Skip to content

Instantly share code, notes, and snippets.

View neilk's full-sized avatar

Neil Kandalgaonkar neilk

View GitHub Profile
@neilk
neilk / video2podcast.sh
Created October 8, 2012 05:49
Video to podcast VLC sample invocation
# A VLC invocation that converts a movie file into an audio file that iTunes will sync to your iPhone
/Applications/VLC.app/Contents/MacOS/vlc -I dummy --no-sout-video --sout-audio --no-sout-rtp-sap --no-sout-standard-sap --ttl=1 --sout-keep --sout "#transcode{acodec=s16l,channels=2}:std{access=file,mux=wav,dst=podcast.wav}" movie.mp4
@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 / 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;
// 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 / 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 / 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 / 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 / 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 / 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 / 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
*