Skip to content

Instantly share code, notes, and snippets.

@puneetlakhina
puneetlakhina / Median.java
Created July 30, 2012 23:01
Get median from a list
public double getMedian(List<? extends Number> values) {
if(values.size() % 2 != 0) {
return values.get(values.size()/2).doubleValue();
} else {
return (values.get((values.size()/2) - 1).doubleValue() + values.get(values.size()/2).doubleValue())/2;
}
}
@puneetlakhina
puneetlakhina / csshorizontalstatus.css
Created June 29, 2012 23:24
CSS for Horizontal Success/Fail/Warn with bootstrap
.status-ul {
list-style: none;
padding:0;
margin:0;
font-size: 8px;
}
.status-item {
display:inline;
border-style: solid;
@puneetlakhina
puneetlakhina / p4cl
Created June 6, 2012 18:03
Create an empty perforce changelist
#!/bin/bash
p4 change -o | grep '^\(Change\|Client\|User\|Description\)' | sed "s/Description:/Description:$1/" | p4 change -i | cut -d ' ' -f 2
@puneetlakhina
puneetlakhina / centospy26.sh
Created May 30, 2012 18:25
CentOS python 2.6 installation
sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
sudo yum install gcc python26-devel
sudo yum install python26-setuptools
sudo easy_install-2.6 pip
sudo easy_install-2.6 -U distribute
def ts_weeks_ago(n):
"""
Gets the unix timestamp n weeks ago
"""
return time.time() - (n*7*24*60*60*1000)
public void open() {
new Thread() {
public void run() {
loadData((Schema)null, _file);
}
}.start();
}
@Override
protected boolean processRecord(GenericRecord data) {
@puneetlakhina
puneetlakhina / lpr.py
Created April 10, 2012 06:44
Multiply probabilities by doing log sum
import math
def lpm(*args):
return sum([math.log(x) for x in args])
lpm(0.1,0.2)
Test Gist
@puneetlakhina
puneetlakhina / git_set_upstream.sh
Created December 6, 2011 02:42
set upstream git branch
git branch --set-upstream branch_name upstream/branch_name
@puneetlakhina
puneetlakhina / CollectionUtils.java
Created December 2, 2011 20:01
A utility of collection functions. 1. Denormalize a java Map<K,List<T>> into a list of entries 2. firstOrNull in a list
private <K,T> List<Map.Entry<K, T>> denormalizeMap(Map<K,List<T>> nestedListMap) {
List<Map.Entry<K, T>> denormalizedEntryList = new ArrayList<Map.Entry<K,T>>();
for(Map.Entry<K, List<T>> entry:nestedListMap.entrySet()) {
for(T t:entry.getValue()) {
denormalizedEntryList.add(new AbstractMap.SimpleEntry<K,T>(entry.getKey(), t));
}
}
return denormalizedEntryList;
}