Skip to content

Instantly share code, notes, and snippets.

import json
import urllib
import urllib2
import time
""" Nike plus activity log
https://developer.nike.com
Output:
-- May --
@timcowlishaw
timcowlishaw / monads.rb
Created April 26, 2013 16:19
A Ruby approximation of the Continuation Monad from Haskell, inspired by Dan Piponi's FPComplete tutorial, "The Mother of All Monads": https://www.fpcomplete.com/user/dpiponi/the-mother-of-all-monads
# Inspired by https://www.fpcomplete.com/user/dpiponi/the-mother-of-all-monads, A ruby port of Haskell's continuation monad, using fibers for lazily-evaluated giggles:
#
# For reference, The continuation monad instance definition from haskell:
# instance Monad (Cont r) where
# return a = Cont ($ a)
# m >>= k = Cont $ \c -> runCont m $ \a -> runCont (k a) c
#HI THERE, I AM THE CONTINUATION MONAD
class Cont
def self.unit(x)
@mjbommar
mjbommar / getVixTermStructure.R
Created November 5, 2012 12:12
Retrieving the VIX term structure from CBOE in R
#@author Bommarito Consulting, LLC; http://bommaritollc.com/
#@date 20121105
# Imports
library(RCurl)
library(XML)
# Set RCurl options
options(RCurlOptions = list(timeout = 10, useragent = "Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1"))
@Simbul
Simbul / pre-commit
Created February 9, 2012 18:06
Git hook to prevent commits on a staging/production branch
#!/usr/bin/env ruby
# This pre-commit hook will prevent any commit to forbidden branches
# (by default, "staging" and "production").
# Put this file in your local repo, in the .git/hooks folder
# and make sure it is executable.
# The name of the file *must* be "pre-commit" for Git to pick it up.
FORBIDDEN_BRANCHES = ["staging", "production"]
@agnellvj
agnellvj / 01_README.md
Created January 28, 2012 00:18 — forked from ddemaree/01_README.md
How Sunspot implements its wonderful search/index DSL

This code is extracted/adapted from Mat Brown's Sunspot gem. One of Sunspot's nicest features is an expressive DSL for defining search indexes and performing queries. It works by instance_eval-ing a block you pass into it in the context of its own search builder object. In this code, the pig thing1 statement is roughly equivalent to zoo = Zoo.new; zoo.pig(thing1).

Sunspot's DSL has to resort to trickery: the instance_eval_with_context method uses eval to get the block to give up the object it considers to be self, then sets up an elaborate system of delegates and method_missing calls so any methods not handled by the DSL are forwarded to the surrounding object. But as a result, this syntax is minimal and beautiful, and it works the way you expect whether or not you prefer blocks to yield an object.

Without this trick the block would be restricted to either the original, "calling" context (as a closure) or the DSL's "receiving" context (using instance_eval), but not both.

Using `ins

@dx7
dx7 / gist:1333785
Created November 2, 2011 14:33
Installing ruby-debug with ruby-1.9.3-p0
### UPDATE: ruby-debuy19 is no longer maintained, use https://github.com/cldwalker/debugger
# Install with:
# bash < <(curl -L https://raw.github.com/gist/1333785)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p0 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem