Skip to content

Instantly share code, notes, and snippets.

View shriphani's full-sized avatar

Shriphani Palakodety shriphani

View GitHub Profile
@shriphani
shriphani / coroutines.rkt
Created January 30, 2012 09:23
Scheme code to teach myself co-routines
#lang racket
;; loops using continuations
(define infinite-loop
(lambda (proc)
(letrec ((loop (lambda ()
(proc)
(loop))))
(loop))))
@shriphani
shriphani / Haskell_Code_Porn.hs
Created February 2, 2012 22:46
One-Liners in Haskell that merit the "Code Porn" label
-- list of numbers of form 2k
twoK = 1:(map (2*) twoK)
@shriphani
shriphani / random-choice.rkt
Created November 12, 2012 18:42
random-choice implementation using user-supplied probabilities for list items
(define (random-choice-probs ns n-probs)
(let ((x (random))
(cum-prob 0.0)
(res (first ns)))
(define (inner)
(for ((item ns)
(item-prob n-probs))
(begin
(set! cum-prob (+ cum-prob item-prob))
(when (< x cum-prob)
#lang lazy
(require racket/promise)
(define (port->lines p)
(let ((r (read-line p)))
(if (eof-object? r)
'()
(cons r (port->lines p)))))
#lang racket
(require net/url)
(require (planet dherman/json:4:0))
; Blekko API implementation
(struct blekko (queries api-key))
@shriphani
shriphani / gist:4715130
Created February 5, 2013 15:26
clj file
#!/bin/sh
# Clojure wrapper script.
# With no arguments runs Clojure's REPL.
# Put the Clojure jar from the cellar and the current folder in the classpath.
CLOJURE=$CLASSPATH:/usr/local/Cellar/clojure/1.4.0/clojure-1.4.0.jar:${PWD}
if [ "$#" -eq 0 ]; then
java -cp "$CLOJURE" clojure.main --repl
else
@shriphani
shriphani / scipy_io_alternatives.py
Created February 9, 2013 21:59
csv, numpy interop
"""
Alternatives to working with scipy
"""
import argparse
import csv
import numpy
import scipy.io as sio
import sys
import boost.mpi as mpi
def test_mpi_init():
if mpi.rank == 0:
req = mpi.world.isend(1, 1, 1)
print '0 is done'
if mpi.rank == 1:
req = mpi.world.irecv(0, 1)
r = None
@shriphani
shriphani / gist:5087017
Created March 5, 2013 00:35
Given a template and a list of files, this generates submit-files for your processes.
We couldn’t find that file to show.
@shriphani
shriphani / condor_distribute_command_files.py
Created March 5, 2013 20:13
Create condor_run strings for running jobs in parallel over a list of files
"""
Given a large list of files and the number of processes,
this script will divide up the work, generate a list of condor_submit files,
submit them to condor and exit
"""
import argparse
import errno
import math
import os