Skip to content

Instantly share code, notes, and snippets.

View prakhar1989's full-sized avatar
I may be slow to respond.

Prakhar Srivastav prakhar1989

I may be slow to respond.
View GitHub Profile
@prakhar1989
prakhar1989 / core.cljs
Created May 13, 2016 00:16 — forked from nasser/core.cljs
rough sketch of reactive svg rendering
(ns savage.core
(:require-macros [reagent.ratom :refer [reaction]])
(:require [reagent.core :as reagent :refer [cursor atom track track!]]
[reagent.ratom :refer [make-reaction]]
[clojure.set :as set]
[clojure.string :as string]))
(enable-console-print!)
(defn sqrt [x] (.sqrt js/Math x))

Here's the prime sieve of eratosthenes implemented in 4 different functional languages.

Which one's your favorite?

OCaml
let rec range s e = if s > e then [] else s :: range (s + 1) e;;

let countprimes n =
  let rec aux count = function
@prakhar1989
prakhar1989 / Vagrantfile
Created February 18, 2016 17:50
Vagrantfile for Spark
# -*- mode: ruby -*-
# vi: set ft=ruby :
ipythonPort = 8001 # Ipython port to forward (also set in IPython notebook config)
Vagrant.configure(2) do |config|
config.ssh.insert_key = true
config.vm.define "sparkvm" do |master|
master.vm.box = "sparkmooc/base2"
master.vm.box_download_insecure = true
@prakhar1989
prakhar1989 / docker-cleanup.sh
Last active February 25, 2016 16:56
Cleanup docker images
#!/bin/bash
# source: http://blog.yohanliyanage.com/2015/05/docker-clean-up-after-yourself/
# clean up exited containers
docker rm -v $(docker ps -a -q -f status=exited)
# clean up dangling images
docker rmi $(docker images -f "dangling=true" -q)
# clean up volumes
@prakhar1989
prakhar1989 / k-means.go
Created November 15, 2015 20:23
K means in Go
package main
import (
"image"
"image/color"
"image/png"
"log"
"math"
"math/rand"
"os"
@prakhar1989
prakhar1989 / marauders-map.md
Last active October 21, 2015 02:18
Cloud Project

Marauder's Map

An Android app that allows Columbia students to locate their friends on campus in real-time.

High-level user flow

  • User logs into app via facebook
  • User enters his columbia email and then verifies his/her email address
  • The user is shown a map of columbia with their friends' faces and last-known locations
  • (optional) Show which building (Mudd, Low, etc) that location has come from
@prakhar1989
prakhar1989 / nginx.conf
Last active January 10, 2016 01:53
nginx-with-node
### Nginx configuration for Node
upstream nodejs {
server 127.0.0.1:8081;
keepalive 256;
}
server {
listen 80;
@prakhar1989
prakhar1989 / notes.md
Last active September 17, 2015 23:14
Distributed Systems

Jepsen Summaries

  • First in the series explaining the motivation and the goals of the project
  • Since computers have finite memory and latency bounds, we introduce timeouts, which close the connection when expected messages fail to arrive within a given time frame.
  • Detecting network failures is hard. Since our only knowledge of the other nodes passes through the network, delays are indistinguishible from failure. This is the fundamental problem of the network partition: latency high enough to be considered a failure.
  • The CAP theorem tells us that we can either have consistency (technically, linearizability for a read-write register), or availability (all nodes can continue to handle requests), but not both.
  • In this series, I'm going to demonstrate how some real distributed systems behave when the network fails.
  • To simulate slow networks, or network
@prakhar1989
prakhar1989 / trees.py
Last active July 29, 2016 05:46
Fun with binary trees
#!/usr/bin/python
import unittest
## binary tree problems
### A NODE OBJECT
class Node(object):
def __init__(self, data):
self.data = data
self.left = None
@prakhar1989
prakhar1989 / graphs.py
Last active July 29, 2016 05:46
Simple Graph Algos
from collections import deque
from sys import maxint as MAXINT
# Breadth first search
def bfs(graph, start):
explored, queue = set([start]), deque([start])
while len(queue):
vertex = queue.popleft()
yield vertex
for neighbor in graph[vertex]: