Skip to content

Instantly share code, notes, and snippets.

View envp's full-sized avatar

Vaibhav Yenamandra envp

View GitHub Profile
@envp
envp / ruby.rb
Last active January 26, 2016 04:03
lib/distribution/binomial/ruby.rb
# Returns the inverse-CDF or the quantile given the probability `prob`,
# the total number of trials `n` and the number of successes `k`
# Note: This is a binary search under the hood and is a candidate for
# updates once more stable techniques are found.
# This still needs to be optimized and benchmarked against
# the vanilla quantile
#
# @paran qn [Float] the cumulative function value to be inverted
# @param n [Fixnum, Bignum] total number of trials
# @param prob [Float] probabilty of success in a single independant trial
@envp
envp / BtrdAlgorithm.rb
Last active January 26, 2016 18:18
Implementation of BTRD binomial random varirate generation algo from http://epub.wu.ac.at/1242/1/document.pdf . THIS IS EXPLOSIVE CODE IN PUBLIC DOMAIN. USE WITH CAUTION.
# When the mean is still small, but the probability of success
# is not miniscule. Covers n > 20
# Taken from "The Generation of Binomial Random Variates"
# Wolfgang Hormann (http://epub.wu.ac.at/1242/1/document.pdf)
# This is algorithm BTRD from the text
# This is a precalculated table for correction terms in
# stirling's approximation to log(k!) each index corresponds
# to a seperate value of k
fc_table = [0.08106146679532726, 0.04134069595540929,
@envp
envp / ruby.rb
Last active January 29, 2016 12:14
lib/distribution/binomial/ruby.rb
module Distribution
module Binomial
module Ruby_
class << self
# Returns a `Proc`object that yields a random integer `k` <= `n`
# which is binomially distributed with mean np and variance np(1-p)
# This method uses Luc Devroye's "Rejection Method" from page 533
# of his text: "Non-Uniform Random Variate Generation."
#
# @param n [Fixnum] the total number of trials
@envp
envp / goto_evil.rb
Last active February 1, 2016 18:20
state = 1
counter = 0
# Customary: "Here be evil"
# For a live version, see: https://repl.it/BiiG/1
loop do
puts [state, counter].inspect
case state
when 1
@envp
envp / meta.rb
Last active February 18, 2016 09:19
# require all the rngs defined in lib/statistical/rng
require 'statistical/rng/uniform'
module Statistical
module Rng
# :nodoc:
# Dynamically add constant RNG_TYPES when called
def self.const_missing(cname)
if cname == 'RNG_TYPES'.to_sym
@envp
envp / spec_template.rb
Last active February 18, 2016 13:29
Generic template for distribution test cases
describe Statistical::Distribution::DistNameGoesHere do
describe '.new' do
context 'when called with no arguments'
context 'when upper and lower bounds are specified'
end
describe '#pdf' do
context 'when called with x < lower'
context 'when called with x > upper'
context 'when called with x in [lower, upper]'
@envp
envp / issue_description_c9
Created March 10, 2016 16:37
Because c9.io doesnt like if you have 2+ links in a post.
1. When I load c9.io for the first time, no styles are loaded from cdn.c9.io and I get a screen [like this](http://puu.sh/nBEwg/b9cf73fe0e.png).
2. After going to status.c9.io, which needs me to fill out a [captcha](http://puu.sh/nBEGI/92762b043c.jpg). I am able to see my dashboard with proper styling, but is still missing some resources all of which are from cdn.c9.io.
3. [See screenshot of above](http://puu.sh/nBEN9/3b9a868896.png) Note the missing glyphicons in this picture. [And a dropbox link to the console logs](https://www.dropbox.com/s/stn8rl62ndz50v1/c9.io-1457627113298.log?dl=0)
4. Now when I click on "Open" to open my workspace. It gets [stuck loading](http://puu.sh/nBF5n/427dde3458.png). Here's the [dropbox log for that](https://www.dropbox.com/s/jcujwnsvb4uvc9a/ide.c9.io-1457627242366_stuck_Loading.log?dl=0)
@envp
envp / run.log
Created March 19, 2016 14:17
It gets slower after running a few times and starts with comparable perf to Random.new_seed
dimsum:~/workspace/benchmarks $ ruby new_seed_bench.rb
Random.new_seed
128612292610189266596556422956211714817
6.2686e-05
PCGRandom.new_seed
12346887968840078306103323986432
6.4614e-05
dimsum:~/workspace/benchmarks $ ruby new_seed_bench.rb
Random.new_seed
218468435883139448544708591128323365688
require 'benchmark'
require 'pcg_random'
def m
Random.new_seed
end
def n
PCGRandom.new_seed
end
@envp
envp / WhatsAppText2Emoji.js
Last active July 31, 2016 21:50
A Simple script that converts text smileys to emojis
// ==UserScript==
// @name WhatsApp Text2Emoji
// @namespace http://tampermonkey.net/
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version 0.2
// @description Simple script that converts text smileys to emojis
// @author Vaibhav Yenamandra
// @match https://web.whatsapp.com/
// @grant none