Skip to content

Instantly share code, notes, and snippets.

@thebigbad
thebigbad / song.js
Created March 21, 2011 01:56
looping background music in all major browsers with only moderate pain
/*
works in:
* chrome
* firefox 3.5+
* safari (with quicktime installed)
* ie 6+
I ended up only needing an ogg and mp3 version
of the file I wanted to play. Any browser that
has m4a support also worked with mp3.
var foo = function (bar, baz) {};
var getBaz = function (callback) {
var baz = 3;
callback(baz);
};
var bar = 2;
getBaz(function (baz) { foo(bar, baz); });
@thebigbad
thebigbad / gist:768585
Created January 6, 2011 21:10
make 20 char pass in js
var genPass = function () {
var pass = '';
var len = 20;
while (len--) {
pass += String.fromCharCode(Math.floor(Math.random() * 95) + 32);
}
return pass;
};
var chars = [
"$", "-", "_", ".", "+",
"<", ">", "#", "%", '"', "{", "}", "|", "\\", "^", "~", "[", "]", "`", "!",
"*", "'", "(", ")", ",", ";", "/", "?", ":", "@", "&", "="
];
console.log(
chars.map(function (c) { return escape(c); }).
map(function (c) { return escape(unescape(c)); })
);
<a id="last" href="#">last</a>
<img id="mug" count="4" src="mug4.png" />
<a id="next" href="#">next</a>
...
$('#last').click(function () {
var mug = $('#mug');
var count = mug.attr('count');
count = (count - 1) % 48;
@thebigbad
thebigbad / gist:749412
Created December 21, 2010 02:48
testing node-irc
var Client = require('irc').Client;
var client = new Client('example.com', 'joe', { port: 6601, secure: true });
client.on('motd', function () {
client.join('#test', function () {
client.say('#test', 'holy shit that was easy');
});
});
@thebigbad
thebigbad / router.js
Created December 14, 2010 01:54
simplest router worth the name
var http = require('http');
var url_parse = require('url').parse;
var routes = {};
var methods = ['get', 'put', 'post', 'delete'];
methods.forEach(function (method) { routes[method] = []; });
var addRoute = function (method, pattern, callback) {
var Script = process.binding('evals').Script;
try { Script.runInNewContext('var a = 2; a.boats();', window); } catch (e) {}
@thebigbad
thebigbad / snake-eyes.js
Created December 6, 2010 20:19
irc bot for ci
var jerk = require('jerk');
var http = require('http');
var options = {
server: 'eng.borderstylo.int',
nick: 'SnakeEyes',
channels: ['#rd', '#clients']
};
var irc = jerk(function (j) {}).connect(options);
@thebigbad
thebigbad / tidypubscraper.pl
Created November 30, 2010 21:43
generate a list of all tidypub urls in use. would take an estimated 12 years to complete a run on a single machine.
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use Math::BaseArith;
my $browser = LWP::UserAgent->new;
sub get {