Skip to content

Instantly share code, notes, and snippets.

View singpolyma's full-sized avatar

Stephen Paul Weber singpolyma

View GitHub Profile
@singpolyma
singpolyma / version_compare.c
Created February 6, 2009 22:47
Compare two version numbers.
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "version_compare.h"
int compar_version(const void *va,const void *vb) {
const char * const *a = va;
const char * const *b = vb;
return version_compare(*a, *b);
@singpolyma
singpolyma / magic
Created March 3, 2009 04:38
/etc/magic
0 string/b #!\ /bin/sh POSIX shell script commands text executable
0 string/b #!\ /usr/bin/ruby Ruby script text executable
!:mime text/x-ruby
0 string/b #!\ /usr/bin/env\ ruby Ruby script text executable
!:mime text/x-ruby
0 search .each\ do\ | Ruby script text executable
!:mime text/x-ruby
0 search .each\ {\ | Ruby script text executable
!:mime text/x-ruby
@singpolyma
singpolyma / keyid2email.sh
Created March 27, 2009 21:48
Pass a keyid or mnencoded keyid and get back a list of email addresses.
#!/bin/sh
RAW="`echo $* | sed -e's/^0x//'`"
DECODED="`echo $RAW | mndecode | bytes2hex`"
curl -s "http://keys.nayr.net:11371/pks/lookup?search=0x$RAW&op=index&exact=on&options=mr" | grep uid | sed -e's/^.*:.*)\? <\([^>]*\)>.*$/\1/g'
curl -s "http://keys.nayr.net:11371/pks/lookup?search=0x$DECODED&op=index&exact=on&options=mr" | grep uid | sed -e's/^.*:.*)\? <\([^>]*\)>.*$/\1/g'
. . . . 8 . 6 . .
. 6 . 2 . . . 5 .
. . 1 3 4 . . . 8
. 4 9 . . . . . .
2 . 7 . . . 5 . 3
. . . . . . 8 1 .
7 . . . 2 1 9 . .
. 5 . . . 8 . 7 .
. . 4 . 9 . . . .
@singpolyma
singpolyma / str_realloc_cat.c
Created March 28, 2009 20:55
Easy string concatenation in C
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
char *vstr_realloc_cat(int count, char *buf, va_list vl1, va_list vl2) {
int buf_was_null = !buf;
int length = 0;
int i;
if(!buf_was_null) {
length = strlen(buf);
#!/usr/bin/ruby
# Verify the PGP signature on the data on STDIN
# Fetch key from keyserver if not present
block = STDIN.read
gpg = IO.popen('gpg --verify 2>&1', 'r+b')
gpg.write(block)
gpg.close_write
<?php
/* Code from http://tantek.pbworks.com/NewBase60
License: http://creativecommons.org/licenses/by-sa/3.0/
Author: Tantek Çelik <http://tantek.com>
*/
function strcat($a, $b) {
return $a.$b;
}
/* Expanded form of a bookmarklet for extracting rev=canonical OR tinyurling a page */
(function(){
var url=document.location;
var links=document.getElementsByTagName('link');
var found=0;
for(var i = 0, l; l = links[i]; i++) {
if (l.getAttribute('rev') == 'canonical' || (/alternate short/).exec(l.getAttribute('rel'))) {
found=l.getAttribute('href');
break;
}
#!/usr/bin/ruby
require 'open-uri'
require 'hpricot'
unless ARGV[0]
warn 'Plase specify a libre.fm user to get data for.'
exit 1
end
#!/usr/bin/ruby
require 'open-uri'
require 'hpricot'
require 'cgi'
unless ARGV[0]
warn 'Plase specify a libre.fm user to get data for.'
exit 1
end