Skip to content

Instantly share code, notes, and snippets.

View Monte Carlo Simulations.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kamalbanga
kamalbanga / monte_carlo.py
Last active Mar 1, 2020
Monte Carlo simulations of some problems; to estimate probabilities
View monte_carlo.py
from random import choices, sample
from statistics import mean
def common_birthday(k):
'''Generate k independent uniformly random birthdays & check if there are any repeats'''
birthdays = choices(range(1, 366), k=k)
return len(set(birthdays)) != k
>>> mean(common_birthday(23) for _ in range(10000))
0.4979
View MonteCarlo.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kamalbanga
kamalbanga / setup.sh
Last active May 17, 2016
Setup Dataproc
View setup.sh
sudo apt-get install python-pip python-dev build-essential
sudo pip install --upgrade pip
sudo pip install --upgrade gensim
@kamalbanga
kamalbanga / ctmdata.py
Last active May 12, 2016
Generate random data for input to CTM algorithm. Run as "python2.7 ctmdata.py".
View ctmdata.py
from random import randint
from random import uniform, gauss
def gaussian(mu, sigma = 0.1):
prob = gauss(mu, sigma)
if prob < 0:
return 0.0
elif prob > 1:
return 1.0
else:
@kamalbanga
kamalbanga / most_frequent.sh
Created Apr 23, 2015
Doug Mcllroy's solution to "find n most frequent words in a file"
View most_frequent.sh
tr -cs A-Za-z '\n' |
tr A-Z a-z |
sort |
uniq -c |
sort -rn |
sed ${1}q
View latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@kamalbanga
kamalbanga / install.md
Last active Aug 29, 2015
Installation commands by Ajay the Ultimate.
View install.md

SBT

echo "deb http://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list

sudo apt-get update

sudo apt-get install sbt

Java

@kamalbanga
kamalbanga / compress.scala
Last active May 8, 2019
Zlib Compression in Scala
View compress.scala
import scala.io._
import java.util.zip.{Inflater, Deflater}
import java.io.{File, FileOutputStream}
object App {
def compress(inData: Array[Byte]): Array[Byte] = {
var deflater: Deflater = new Deflater()
deflater.setInput(inData)
deflater.finish
@kamalbanga
kamalbanga / max.cpp
Created Dec 3, 2014
Max Difference of Numbers in an Array.
View max.cpp
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;