IPTables rule generator  

I just wrote a quick tool to generate iptables rules so I won't have to read the man page every time.

Leave A Reply

How floating point numbers are stored  

A float in C++ is either 4 or 8 bits. A 4 bit float can hold a number up to 38 digits! I wasn't sure how a computer stores a number that large in such a small amount of ram so I did some research. I found that it's stored using a method called IEEE 754-1985 which Wikipedia has a very explanatory article on.

Leave A Reply

Iterate over arguments in bash  

Here is how you iterate over the list of command line arguments (ARGV) in bash

for var in "$@"
do
    echo "$var"
done
Leave A Reply

Books of 2012  

Also see the list of 2011. The date indicated denotes the date I started reading the book.

2012-01-03 - Attack of the Deranged Mutant Killer Monster Snow Goons - 127 pages
2012-01-04 - Calvin and Hobbes - 95 pages
2012-01-06 - Batman: Terror - 128 pages
2011-01-09 - Just After Sunset - 539 pages
2011-01-19 - Coraline - 194 pages

2012-??-?? - Alphabetter juice - 283 pages
2012-??-?? - The Last Werewolf - 293 pages
Leave A Reply

Control Linux sound volume via the command line  

I want to set the volume at the command line to 40% before I run a game. I found that amixer does a pretty good job of this:

amixer --card 0 sset 'Master' 26

The volume number is on a scale of 0 to 64 (which seems weird).

Leave A Reply

sshfs input/output error  

If you're getting an error like this from sshfs 2.3:

ls: cannot access sshfs_dir: Input/output error

It's most likely because you forgot to mount the remote directory with a trailing slash. After I added the trailing slash my sshfs mount work again.

Leave A Reply

MySQL date addition  

Here is an example of doing date addition/subtraction in a MySQL query.

SELECT * FROM Table WHERE DateField > (now() - INTERVAL 1 year)
Leave A Reply

PHP Function: linkify  

I needed a function to take a chunk of text and turn all the URLs inside of it to hyperlinks. Here is the solution I came up with:

function linkify($str) {
    $new_str = preg_replace("@[http|https|ftp]+://[^<>[:space:]]+[[:alnum:]/]@","<a href=\"\\0\">\\0</a>", $str);
    return $new_str;
}
Leave A Reply

Start time of a Linux process  

I needed to find the start time of a Linux process. Luckily the kernel tracks all that for you in /proc. Look at the ctime of the directory for the pid you want,

stat -c %Z /proc/15237

You can also use ps to get the same information, but then you have to parse/scrape the ps output.

ps -p 12345 -o "%t"
Leave A Reply

Close approximation of Pi  

3+(16/113) is a close approximation of Pi. It can also be written as 355/113.

Leave A Reply

StartSSL Free SSL Certificates  

I can't speak highly enough of StartSSL. They give away free personal SSL certificates. This site is available via SSL thanks to them. Their website is fantastic, everything is automated and works well. For personal SSL stuff there is no reason to look anywhere else.

Leave A Reply

MySQL: Rpms needed for mysqlcc  

I still run mysqlcc as a fast and simple MySQL client. It's kind of a pain to get working on modern Linux. These are the RPMs needed to run mysqlcc on Fedora 16 box.

yum install glibc.i686 mesa-libGL.i686 libXmu.i686 libXrender.i686 libXrandr.i686 libXcursor.i686 libXft.i686
Leave A Reply

Reading Watchmen again  

I'm re-reading Watchmen again and listening to the footnotes ComicGeekSpeek podcast of each issue. I forgot how amazing this story is, and the additional backstory supplied by the ComicGeekSpeak podcast really serves to flush out the story all the more.

Leave A Reply

MySQL: Include arbitrary count in SELECT  

Recently I had some data that I needed to add an arbitrary count column to. MySQL lets you use user defined variables in your queries to augment your output. Here is an example that I ended up using to add a sequence number to a CSV I was generating.

set @num := 10;
SELECT First, Last, @num := @num+1 AS SequencNumber FROM CustInfo c;
Leave A Reply

Javascript array/object shortcuts  

I always forget the syntax to make a new object or array in Javascript.

var my_array = new Array();
my_array.push(1);
my_array.push(2);
my_array.push(3);

Or you can simplify the whole process:

var my_array = [1,2,3];

This is the syntax to make a new Object (hash) in Javascript:

var my_obj = new Object();
my_obj['foo'] = 'bar';
my_obj['apple'] = 'red';

But can be shortened this way:

var my_obj = { 'foo':'bar' , 'apple':'red' }

Just remember that arrays are initialized with [] and objects are initialized with {}. This is the same syntax as Perl's array and hash references.

Leave A Reply