IPTables rule generator 2012-01-16 10:43am
I just wrote a quick tool to generate iptables rules so I won't have to read the man page every time.
I just wrote a quick tool to generate iptables rules so I won't have to read the man page every time.
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.
Here is how you iterate over the list of command line arguments (ARGV) in bash
for var in "$@"
do
echo "$var"
done
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).
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.
Here is an example of doing date addition/subtraction in a MySQL query.
SELECT * FROM Table WHERE DateField > (now() - INTERVAL 1 year)
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;
}
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"
3+(16/113) is a close approximation of Pi. It can also be written as 355/113.
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.
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
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.
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;
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.