Skip to content

Instantly share code, notes, and snippets.

@joshz
joshz / snippets.R
Last active August 29, 2015 14:26
R Studio snippets
snippet updr
options(repos=c(CRAN='http://cran.revolutionanalytics.com'))
update.packages(ask=F)
snippet package.installer
install.packages('devtools')
library(devtools)
install_github("ririzarr/rafalib")
essential <- c('data.table', 'dplyr', 'reshape2', 'ggplot2', 'foreach', 'tidyr', 'ggvis',
@joshz
joshz / serList
Last active August 29, 2015 14:14 — forked from anonymous/serList
serList <- function(serlist){
## Function to serialize list of R objects and returns a dataframe.
## The argument is a list of R objects.
## The function returns a serialized list with two elements.
## The first element is count of the elements in the input list.
## The second element, called payload, containts the input list.
## If the serialization fails, the first element will have a value of 0,
## and the payload will be NA.
## Messages to use in case an error is encountered.
@joshz
joshz / pascal.py
Last active August 29, 2015 14:11
pascal's trimangle, no recursion, no combinations
def triangle(r):
def row(n, previous=None):
if n == 1:
return n+1, [1]
else:
rown = []
rown.append(1)
for i in xrange(n):
if i + 1 < n-1:
rown.append(previous[i] + previous[i+1])
@joshz
joshz / gist:8345672
Created January 10, 2014 01:52
Kaggle - Titanic
# Plot at https://plot.ly/~jzegan/0
# install.packages("devtools")
# library("devtools")
# install.packages("microbenchmark")
# install.packages("Lahman")
# install.packages('hflights')
# install.packages('RSQLite')
# install.packages('RSQLite.extfuns')
# devtools::install_github("dplyr")
@joshz
joshz / timezonedb.sql
Created November 13, 2013 12:33
timezonedb in sqlite
SELECT DATETIME(1379478541.13277 + tz.gmt_offset, 'unixepoch', 'localtime') AS local_time, z.country_code, z.zone_name, tz.abbreviation
FROM timezone tz JOIN zone z
ON tz.zone_id=z.zone_id
WHERE tz.time_start < 1379478541.13277 AND z.zone_name='Europe/Warsaw'
ORDER BY tz.time_start DESC LIMIT 1;
@joshz
joshz / retries.py
Created September 18, 2013 21:23 — forked from n1ywb/retries.py
#!/usr/bin/env python
#
# Copyright 2012 by Jeff Laughlin Consulting LLC
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@joshz
joshz / UbuntuInstall.sh
Last active December 22, 2015 14:48
Installing QSTK dependencies on virtualenv, may need tweaking
#
# (c) 2011, 2012 Georgia Tech Research Corporation
# This source code is released under the New BSD license.
# Please see http://wiki.quantsoftware.org/index.php?title=QSTK_License
# for license details.
# Created on Sep 08, 2013
# @original author: look QSTK installation directory
@joshz
joshz / gist:6258340
Created August 17, 2013 19:16
mark, put in .bashrc or .zsh
export MARKPATH=$HOME/.marks
function jump {
cd -P $MARKPATH/$1 2>/dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1
}
function unmark {
rm -if $MARKPATH/$1
}
import csv
import json
with open('metrics.json', 'r') as f:
data = json.load(f)
keys = data[0].keys()
writer = csv.DictWriter(open('metrics.csv', 'wb'), keys)
writer.writer.writerow(keys)
writer.writerows(data)