Wednesday, January 28, 2015

Show all active TCP connections

To display all active TCP connections, at your command prompt:
netstat -tnlp
For example, from an AWS instance setup for serving web pages:
[root@t2-micro ssh]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address        Foreign Address       State       PID/Program name
tcp        0      0 0.0.0.0:80           0.0.0.0:*             LISTEN      2201/nginx
tcp        0      0 0.0.0.0:22           0.0.0.0:*             LISTEN      5103/sshd
tcp        0      0 127.0.0.1:9000       0.0.0.0:*             LISTEN      2197/php-fpm
tcp        0      0 0.0.0.0:3306         0.0.0.0:*             LISTEN      2723/mysqld
tcp        0      0 :::22                :::*                  LISTEN      5103/sshd

Friday, January 9, 2015

I've been a fan of Seagate since the venerable 2080. Seagate used to be the "go to" drive, but that no longer appears to be true.

A few years ago I started buying the FreeAgent GoFlex desktop external (USB 3.0) drives for backup purposes. Since it's used for backup, I need it to be reliable and why I went with Seagate (instead of Western Digital).

Both have failed and Seagate has swapped them out per warranty - no problems there. Guess what? One of the replacements has now failed and I no longer trust the other to not fail soon.

Time to start looking for a large SSD to be the replacement...

Wednesday, December 3, 2014

Waiting for AJAX

If you need to transfer execution of your page to somewhere else, but want to make sure you don't have any pending (jquery) ajax calls, use the $.active variable as below:

// 
// wait for pending ajax calls to finish first
// 
var timer = setInterval(function() {
 if ($.active==0) {
  clearInterval(timer);
  window.location.assign("www.google.com");
 }
}, 500);

Tuesday, December 2, 2014

How to delete multiple keys in Redis

At the command prompt:

#redis-cli KEYS "some-prefix*" | xargs redis-cli DEL

where "some-prefix" is the key prefix you want to delete.

Tuesday, July 16, 2013

PID algorithm for Node

This is a PID algorithm I'm working on for beerNode:

Monday, July 15, 2013

I got beerNode connected to my 1Wire controller this weekend. Gauges by Steel Series.

Thursday, July 11, 2013

Don't optimize the code until you've optimized the algorithm

A co-worker pointed out an article regarding performance tuning for the JQuery DataTables this morning. The author goes through a lot of effort to improve the performance of a JQuery DataTable when adding 1000 rows. It's a valiant effort, and some good code is in there, but, there's a better way.

P. J. Plauger once wrote "Don't optimize the code until you've optimized the algorithm".

Truer words have not been spoken. I spent way too much time (a long time ago in a galaxy far far away) "optimizing" interrupt service routines into 8086 ASM code. I was convinced that a C compiler could not produce code that was as good as I could write - and I was correct. However, I was so caught up in being "right" that I was wrong. Sure, I could write better asm code than a C compiler, but, my asm code was doing the job all the "wrong" ways. My algorithm was flawed. I modified the algorithm, converted the asm code to C and the result was better performance (and a lot less bleeding).

This poor fellow above has fallen into that trap - he's trying to find a better way to stuff 1000 rows into the DOM. Don't waste time and effort trying to find a better way to stuff 1000 rows into the DOM - find a better way to NOT send 1000 rows to the browser! What's that better way you ask? Server side pagination, and it's built into DataTables:

Server-side pagination with DataTables

Certainly, there are situations where you need or want all the data at once, but those situations are typically rare. Think long and hard before you go loading 1000 records into your browser. Server side paging is almost always a win-win-win for viewing large datasets: less impact on the server, less bandwidth used (the data gets there faster) and the page load is faster, improving the user experience - especially on mobile devices.