Skip to content

Instantly share code, notes, and snippets.

Baishampayan Ghose ghoseb

Block or report user

Report or block ghoseb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
anthonytxie /
Created Mar 24, 2018
Hodl 20 Rebalancing Algorithm
def calc_allocations(self, date, quantity, cap):
"""Figure out ideal allocations for a given date"""
# {
# coin_name: (percent_allocation, data)
# }
top_market = self.get_top_market(date, quantity)
total_cap = sum([coin.market_cap for coin in top_market])
allocations = [{

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

light44 /
Created Dec 21, 2016
Latent Dirichlet Allocation using gensim
import nltk
import pandas as pd
import re
import pprint
import operator
import csv
import logging
from stop_words import get_stop_words
from collections import defaultdict
from gensim import corpora
yanok / gist:4701552
Created Feb 3, 2013
Tests for HW3 challenge
View gist:4701552
val wc = Wildcard
val x = Variable "x"
val y = Variable "y"
val z = Variable "z"
fun tpl vs = Tuple vs
fun pair (a,b) = Tuple [a,b]
fun tp ps = TupleP ps
fun pp (a,b) = TupleP [a,b]
kachayev / barber.erl
Last active Dec 9, 2017
Solve "Sleeping Barber Problem" with Erlang (more about problem -
View barber.erl
-export([run/2, barber/1, clients/1, simulator/2]).
-define(CUT_DUTAION, 20).
run(RoomSize, Duration) ->
% create barber
BPid = spawn(?MODULE, barber, [?CUT_DUTAION]),
% run simulartor with barber PID
SPid = spawn(?MODULE, simulator, [BPid, RoomSize]),
View topo.clj
(defbolt split-category ["category" "event"]
[tuple collector]
(let [event (.getString tuple 0)
category "testing_category2"]
(emit-bolt! collector [category event] :anchor tuple)
(emit-bolt! collector [category event] :anchor tuple :stream "3")
(ack! collector tuple)))
View kafka_spout.clj
(ns example.storm.clj.spout.kafka-spout
(:import ; [example.storm.spout UnreliableKafkaSpout]
[storm.kafka HostPort KafkaSpout SpoutConfig StringScheme]))
(def ^:dynamic *kafka-hosts* [""
(def ^:dynamic *kafka-ports* [9093
wmorgan / gist:3054620
Created Jul 5, 2012
Mustache templating for Clojure
View gist:3054620
(ns potato.core
(:use [slingshot.slingshot :only [throw+ try+]])
(:use [clojure.string :only [trim split]]))
;; use this provide template values at write time (i.e. not compile time).
;; "name" will be the name of the template variable. "context", when not nil,
;; will be the value previously returned by *template-value* for the enclosing
;; section.
(defn ^:dynamic *template-value* [name context])
jmgimeno / bfc.clj
Created Jun 14, 2012
Brainf*** compiler (Alan Dipert)
View bfc.clj
(defn bfc
(let [allowed #{\+ \- \< \> \[ \] \.}
src (->> program (filter allowed)
(interpose \space) (apply str))
fns (zipmap '(- + < > . ?) (repeatedly gensym))]
(letfn [(bfc* [s]
(if (vector? s)
`(while (not (~(fns '?))) ~@(map bfc* s))
`(~(fns s))))]
You can’t perform that action at this time.