Skip to content

Instantly share code, notes, and snippets.

@aanand
aanand / gist:5859532
Last active December 18, 2015 23:09

My Travails with Python Command-Line Parsing

What I Want

Top-level and nested subcommands.

$ welp login --username aanand -p s3cr3t

$ welp things

@aanand
aanand / gist:5206145
Last active December 15, 2015 04:59
Combining two streams in Bacon.js, but only updating when one stream updates

Say I have two properties, a and b. If I want a stream that combines their values, I can use a.combine(b, <fn>). Abstractly, this gets me the following:

a:      0    1              2
b:      0         1    2         3
a,b:    0,0  1,0  1,1  1,2  2,2  2,3

But what I need is a stream that only updates when a updates, but uses the most up-to-date value of b. That is:

a:      0    1              2

b: 0 1 2 3

@aanand
aanand / sieve.hs
Last active December 14, 2015 04:59
Un-genuine Sieve of Eratosthenes in Haskell
$ ghci sieve.hs
*Main> take 10 primes
[2,3,5,7,11,13,17,19,23,29]
@aanand
aanand / gist:4968356
Last active December 13, 2015 20:09
Alternate throttle function for Bacon.js
// var throttled = source.steady(2)
// source: asdf------qwerzxcv---------
// throttled: --a-s-d-f---q-w-e-r-z-x-c-v
Bacon.EventStream.prototype.steady = function(delay) {
var bus = new Bacon.Bus();
var queue = [];
var timeout = null;
var emit = function() {
@aanand
aanand / gist:4698693
Created February 2, 2013 18:24
Replace all links to audio files with <audio> tags
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
$(function() {
var a = document.createElement('audio');
if (!(a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''))) return;
$("a").each(function() {
if (!this.href.match(/\.(mp3|mp4|m4a)$/)) return;
var audio = $('<audio/>').attr({
;(function($) {
$.fn.sitDownMan = function() {
this.click(function(e) {
e.preventDefault()
window.location = this.href
})
}
})(jQuery);
//
// STAppDelegate.m
// SpotifyTest
//
// Created by Aanand Prasad on 21/05/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "STAppDelegate.h"
#import "STViewController.h"
loading GPX...99 files loaded (total size 7809.02k)
Checking correctness
--------------------
checking json...ok
checking msgpack...ok
checking protobuf...ok
preparing serialized data...ok
@aanand
aanand / gif
Created November 23, 2011 11:39
Command-line gif creator
#!/usr/bin/env ruby
require "optparse"
default_file_pattern = "png/*.png"
default_output_filename = "out.gif"
start = nil
finish = nil
skip = 1
if RUBY_VERSION < '1.9'
require 'redgreen'
else
require 'colored'
# A poor person's redgreen.
class ActiveSupport::TestCase
def run(*args, &block)
result = super(*args, &block)