Skip to content

Instantly share code, notes, and snippets.

View neilk's full-sized avatar

Neil Kandalgaonkar neilk

View GitHub Profile
@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
@neilk
neilk / nonBlockingForEach.js
Last active November 25, 2021 11:06
Works a little bit like `Array.prototype.forEach()`, but uses `process.nextTick` to allow other processes to execute. NOTE. This isn't meant to be practical; if you use this in production code you're probably doing it wrong.
/**
* Allow other processes to execute while iterating over
* an array. Useful for large arrays, or long-running processing
*
* @param {Function} fn iterator fed each element of the array.
* @param {Function} next executed when done
*/
Array.prototype.nonBlockingForEach = function(fn, next) {
var arr = this;
var i = 0;
@neilk
neilk / galaxy.applesoft.txt
Created May 1, 2019 02:04
Galaxy applesoft basic
10 HGR2: HCOLOR=3
11 R0 = 70
12 TAU = 6.282
13 SCREENX = 279: SCREENY = 191
15 CENTERX = INT(SCREENX / 2): CENTERY = INT(SCREENY / 2)
16 LINEDOTS = 3
17 R = R0
18 CIRCUM = TAU*R0: S = 1
19 J = 0:
20 REM J-LOOP
@neilk
neilk / PageRank in Python from Wikipedia example.ipynb
Created January 21, 2019 18:38 — forked from sebastien-bratieres/PageRank in Python from Wikipedia example.ipynb
IPython notebook to illustrate an algorithm to compute PageRanks.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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"
@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 / .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 / 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 / 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 / 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.
#