Skip to content

Instantly share code, notes, and snippets.

//
// STAppDelegate.m
// SpotifyTest
//
// Created by Aanand Prasad on 21/05/2012.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "STAppDelegate.h"
#import "STViewController.h"
;(function($) {
$.fn.sitDownMan = function() {
this.click(function(e) {
e.preventDefault()
window.location = this.href
})
}
})(jQuery);
@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({
@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 / 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: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 / 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:6795151
Last active December 24, 2015 11:59
Discrepancy in behaviour of docker run-with-immediate-attach vs run-and-then-attach
# Normal run, without -d.
# Container prompt appears immediately; after exiting, system prompt appears on new line.
$ docker run -i -t ubuntu bash
root@0b3fa3041e3f:/# exit
exit
$
# Now run with -d and *then* attach.
# Container prompt doesn't appear until I hit Enter; after exiting, system prompt appears on same line.
@aanand
aanand / about.md
Last active December 24, 2015 13:59
Docker attach timing bug

When starting and attaching to a container with a pseudo-tty, the initial bash prompt will only appear if the 'attach' request comes very quickly after the 'start' request (<0.1 seconds, in my tests).

Note how in the first run (attach immediately after starting), a chunk is received containing the prompt, but in the second run (start, then sleep 1s, then attach), it hangs after receiving the response headers.

This is an issue when trying to run a bash container from a Docker client that is geographically distant from the Docker server - the prompt doesn't appear, and you have to hit Enter to get one. From a UX standpoint, it appears as if Docker is simply hanging, which is pretty frustrating!

@aanand
aanand / gist:7677102
Created November 27, 2013 15:00
[BP][AEIOU](DM|MD)(AS|SA)
BADMAS
PADMAS
BEDMAS
PEDMAS
BIDMAS
PIDMAS
BODMAS
PODMAS
BUDMAS
PUDMAS