Skip to content

Instantly share code, notes, and snippets.

View neilk's full-sized avatar

Neil Kandalgaonkar neilk

View GitHub Profile
#!/usr/bin/env python
import os
import sys
import getopt
from sys import stderr
import boto.ec2
import boto.rds
@neilk
neilk / focus
Created January 28, 2014 07:34
#!/usr/bin/env perl -w
#
# This program is meant to help me focus, by blocking timewasting sites in /etc/hosts.
#
# If the program is invoked with 'focus on', a section will be added to the /etc/hosts file
# routing requests for the domains in __DATA__ to localhost.
#
# If the program is invoked with 'focus off', that section is removed.
#
@neilk
neilk / promiseForEach.js
Last active January 3, 2016 13:09
implementations of looping with Bluebird promises
// promisey foreach loop
'use strict';
var Promise = require('bluebird'),
promiseWhile = require('./promiseWhile');
/**
* Promisey foreach
*
@neilk
neilk / node upserter
Created January 14, 2014 17:43
python versus node for stateful upserting
/**
* postgres does not have replace into, so...
*
* @param {Object} tile specification {tx: ty: zoom:}
* @param {Object} quad properties of that tile
* @param {Knex.transaction} t database transaction
* @return {Promise}
*/
function insertOrUpdateTile(tile, quad, t) {
@neilk
neilk / mockify.css
Created December 15, 2013 00:46
CSS to turn an existing website into something resembling a mock. Requires the font "Redacted Script" (https://github.com/christiannaths/Redacted-Font). One way to use it: get Live CSS Editor (http://www.livecsseditor.com/), pop open the window, and paste the contents of mockify.css.
* {
-webkit-filter: grayscale(100%) !important;
background-color: white !important;
border-color: black !important;
color: black !important;
font-family: "redacted script" !important;
}
@neilk
neilk / promiseWhilePromise.js
Last active January 23, 2017 09:39
Using Q.js, a while loop where the condition is itself a promise
'use strict';
var Q = require('q');
// `condition` is a function that returns a boolean
// `body` is a function that returns a promise
// returns a promise for the completion of the loop
function promiseWhile(condition, body) {
var done = Q.defer();
@neilk
neilk / iteratePromiseTest.js
Created August 23, 2013 21:56
Recursive iterating with promises; done "manually", and with when/unfold
'use strict';
var when = require('when'),
delay = require('when/delay'),
unfold = require('when/unfold');
function getNumber() {
var deferred = when.defer();
deferred.resolve(Math.floor(Math.random() * 10));
return deferred.promise;
@neilk
neilk / vagrant-ssh-node
Created August 22, 2013 18:42
SSH into a Vagrant VM, such that Node.js can be debugged from a debugger or IDE in the host operating system. For some reason, port forwarding in the Vagrant file does not work. See https://groups.google.com/forum/#!topic/vagrant-up/RzPooJ0dp6Q
#!/bin/bash
# SSH into a Vagrant VM, forwarding ports in a way that allows node within Vagrant to be debugged by a debugger
# or IDE in the host operating system. Don't know why, but Vagrantfile port forwarding does not work.
# (https://groups.google.com/forum/#!topic/vagrant-up/RzPooJ0dp6Q)
/usr/bin/vagrant ssh-config > $TMPDIR/vagrant-ssh-config
ssh -F $TMPDIR/vagrant-ssh-config -L 5858:127.0.0.1:5858 default
rm $TMPDIR/vagrant-ssh-config
// sign up
account.signUp('joe@example.com', 'secret');
// sign in
account.signIn('joe@example.com', 'secret');
// sign in via oauth
account.signInWith('twitter');
// sign out
@neilk
neilk / testRoute.js
Last active December 16, 2015 06:19
Attempt to use node-webworker threads
var Worker = require('webworker-threads').Worker;
var worker = new Worker('bin/testWorker.js');
var workerSend;
(function() {
var idCounter = 0;
var callbacks = {};
worker.onmessage = function(oEvent) {
var message = oEvent.data;