Skip to content

Instantly share code, notes, and snippets.

View Jimbly's full-sized avatar

Jimb Esser Jimbly

View GitHub Profile
@Jimbly
Jimbly / gist:11302619
Last active August 29, 2015 14:00
Periodic beacon firing
<html>
<head>
<script>
var beacon = (function() {
function fireBeacon(url, cb) {
//debug('Firing beacon ' + url);
var beacon = new Image();
beacon.onload = function() {
cb();
};
@Jimbly
Jimbly / gist:10771051
Last active August 29, 2015 13:59
Page scraping with login
var request = require('request').defaults({ jar: true });
var config = require('./config.json');
var log = console.log.bind(console);
function wrapcb(orig_url, cb) {
return function(err, res, body) {
if (res && res.statusCode === 302) {
var url = require('url').resolve(orig_url, res.headers.location);
log('Redirect from ' + orig_url + ' to ' + url);
@Jimbly
Jimbly / DefaultKeyBindings.dict
Last active April 2, 2025 20:48
Mac OSX keybindings to more closely match Windows
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more closely
match default behavior on Windows systems.
You must log out and back in to see these changes.
Here is a rough cheatsheet for syntax.
Key Modifiers
^ : Ctrl
$ : Shift
var domain = require('domain');
var assert = require('assert');
var DELAY = 10;
function doerr() {
var fired = false;
setTimeout(function () {
fired = true;
@Jimbly
Jimbly / jimb_util.py
Last active August 29, 2015 13:55
Jimbly's Sublime config snapshot
[
// Rebind mac to be like windows
{ "keys": ["ctrl+n"], "command": "new_file" },
{ "keys": ["ctrl+s"], "command": "save" },
{ "keys": ["ctrl+shift+s"], "command": "prompt_save_as" },
{ "keys": ["ctrl+alt+s"], "command": "save_all" },
{ "keys": ["ctrl+f4"], "command": "close" },
@Jimbly
Jimbly / gist:5408241
Last active December 16, 2015 08:48
Cloud Party: floating beach ball script
function tick() {
//error('test');
var z = getParam('ground_height');
var pos = getPos();
if (pos[2] < z) {
setGravity({ gravity: [0, 0, min(5, z - pos[2])] });
} else {
setGravity({ gravity: [0, 0, -9.8] });
}
}
@Jimbly
Jimbly / gist:5112692
Last active December 14, 2015 16:08
Logging to zlib log stream with periodic flushing.
var assert = require('assert');
var zlib = require('zlib');
var gzip = zlib.createGzip();
var fs = require('fs');
var FILENAME = 'log.txt.gz';
var out = fs.createWriteStream(FILENAME);
gzip.pipe(out);
function debug(msg) {
@Jimbly
Jimbly / gist:3997436
Created November 1, 2012 23:20
Infinite HTTP server
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var count=0;
function doit() {
while (res.writable && res.write('Data!\r\n\r\n')) {
++count;
if (count % 1000 === 0) {
console.log('wrote ' + count + ' chunks');
return process.nextTick(doit);
@Jimbly
Jimbly / gist:3935714
Created October 23, 2012 00:07
Failed attempt at IP filtering.
var dns = require('dns');
var http = require('http');
var https = require('https');
var blocked = ['207.171.163.193'];
var user_supplied_hostname = 'www.cloudpartytime.com';
dns.lookup(user_supplied_hostname, function(err, address) {
console.log('DNS lookup returned ' + address);
@Jimbly
Jimbly / test-http-deadsocket-client.js
Created September 7, 2012 20:57
Test case for getting a dead socket because of node timing issues.
var assert = require('assert');
var http = require('http');
var agent = new http.Agent({maxSockets: 1});
var headers = {'connection': 'keep-alive'};
var PORT = 8080;
var responses = 0;
var errors = 0;