Skip to content

Instantly share code, notes, and snippets.

View neilk's full-sized avatar

Neil Kandalgaonkar neilk

View GitHub Profile
@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.
#
#!/usr/bin/env python
import os
import sys
import getopt
from sys import stderr
import boto.ec2
import boto.rds
var db = Knex({ /* connection properties */ });
function sessionToAccount(session) {
return db('accounts').where('user_ID', session.user_ID).select();
}
function withdraw(account, amount) {
if (account.balance < amount) {
throw new Error("insufficient funds");
}

Keybase proof

I hereby claim:

  • I am neilk on github.
  • I am neilk (https://keybase.io/neilk) on keybase.
  • I have a public key whose fingerprint is B969 3202 D54C BBA2 608F 1778 0CE3 13EC F872 D474

To claim this, I am signing this object:

@neilk
neilk / softStars
Last active August 29, 2015 14:08
softStars for weatherStrip ElectricImp project
// WS2812 "Neopixel" LED Driver
// Copyright (C) 2014 Electric Imp, inc.
//
// Uses SPI to emulate 1-wire
// http://learn.adafruit.com/adafruit-neopixel-uberguide/advanced-coding
// This class requires the use of SPI257, which must be run at 7.5MHz
// to support neopixel timing.
const SPICLK = 7500; // kHz
Verifying that +neilk is my openname (Bitcoin username). https://onename.io/neilk
@neilk
neilk / git-purge.sh
Last active February 16, 2017 17:59
Purge a file from your git repo
#!/bin/bash
git filter-branch --force --index-filter \
"git rm -r --cached --ignore-unmatch $1" \
--prune-empty --tag-name-filter cat -- --all
@neilk
neilk / .sharedhistory.sh
Last active April 11, 2017 03:47
Multiple bash hooks upon changing directories (set env var, switch node version, switch history file)
shopt -s histappend
PROMPT_COMMAND="history -a;history -c;history -r;$PROMPT_COMMAND"
SHARED_HISTORY_DIR="$HOME/.sharedhistory"
mkdir -p $SHARED_HISTORY_DIR
function __sharedhistory_chpwd() {
if [[ -n $PROJECT ]]; then
local pwd_escaped=$(echo $PWD | sed 's/[\/ ]/~/g')
HISTFILE="$SHARED_HISTORY_DIR/$PROJECT"
@neilk
neilk / retry-promise.js
Last active June 9, 2017 23:11
Retry logic for promises
/**
* Retry a promise until success, up to a certain number of times.
* Returns the last error if it reaches maximum attempts.
*
* @param maxTries {Number} positive integer
* @param p {Promise}
* @return {Promise}
*/
function retry (maxTries, p) {
var tries = 0;
@neilk
neilk / sbt-deps-changes
Last active July 11, 2017 21:07
In a Scala/SBT project, figure out what dependencies are added or removed in a branch
#!/bin/bash
# Find dependency changes in a branch in a scala project using sbt.
# You have to have the https://github.com/jrudolph/sbt-dependency-graph plugin installed.
# the standard `sed` on Mac OS X won't work, so make sure to install GNU sed via brew.
branch="$1"