Skip to content

Instantly share code, notes, and snippets.

View kmatt's full-sized avatar
😐

Matt Keranen kmatt

😐
  • SE US
View GitHub Profile
@kmatt
kmatt / gist:2848105
Created June 1, 2012 02:17 — forked from mikeyk/gist:1329319
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import sys
r = redis.Redis(host = 'localhost', port = 6389)
REDIS_SETGET = False
REDIS_HSET = False
@kmatt
kmatt / gist:2848112
Created June 1, 2012 02:18
The Zen of R
# I am a scientist who has been using R for about 2 years. Today I achieved a measure of enlightenment into
# the zen of R, and I want to share it with you.
# I was simulating a set of independent random walks, which are formed by a multiplicative process. Here is
# the code I had built up over a few months of working on it and modifying it on and off as research
# questions changed:
TimeSteps <- 1000
Walks <- 100
ErrorMagnitude <- 0.03
@kmatt
kmatt / gist:3351502
Created August 14, 2012 18:28 — forked from karlseguin/gist:2992426
sample code used by ranking post
# http://openmymind.net/Paging-And-Ranking-With-Large-Offsets-MongoDB-vs-Redis-vs-Postgresql/
lids = ['4fe907f1210b2e9e3080f001', '4fe907f1210b2e9e3080f002', '4fe907f1210b2e9e3080f003', '4fe907f1210b2e9e3080f004', '4fe907f1210b2e9e3080f005']
insert the data
open('data.csv', 'w') do |f|
6000000.times do |i|
f.puts "#{lids.sample},user_#{i},#{(rand() * 10000000).to_i}"
end
end
@kmatt
kmatt / cairographics.R
Created October 13, 2012 07:13 — forked from dsparks/cairographics.R
Using cairographics with ggsave()
# .png with Windows GDI versus .png with cairographics
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("ggplot2", "RColorBrewer", "Cairo")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Generate some data
nn <- 100
myData <- data.frame(X = rnorm(nn),
@kmatt
kmatt / exampleRScript1.r
Created December 9, 2015 17:57 — forked from ericminikel/exampleRScript1.r
An example of how to use Rscript and optparse to run R in batch mode with command line args.
#!/broad/software/free/Linux/redhat_5_x86_64/pkgs/r_3.0.2/bin/Rscript
# Eric Vallabh Minikel
# CureFFI.org
# 2014-01-14
# example of how to use optparse in R scripts
# usage: ./exampleRScript1.r -a thisisa -b hiagain
# ./exampleRScript1.r --avar thisisa --bvar hiagain
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog $zookeeper
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
@kmatt
kmatt / vimdiff.md
Last active April 28, 2016 17:30 — forked from mattratleph/vimdiff.md
vimdiff cheat sheet

vimdiff cheat sheet

##git mergetool

In the middle file (future merged file), you can navigate between conflicts with ]c and [c.

Choose which version you want to keep with :diffget //2 or :diffget //3 (the //2 and //3 are unique identifiers for the target/master copy and the merge/branch copy file names).

:diffupdate (to remove leftover spacing issues)

:only (once you’re done reviewing all conflicts, this shows only the middle/merged file)

@kmatt
kmatt / table2plot.R
Created May 18, 2016 17:21 — forked from even4void/table2plot.R
A fake example for mixing text and graphic
display.cell <- function(x, bgcol="#DAE6F2", ...) {
opar <- par(bg=bgcol, mar=rep(0,4))
plot(c(0,1), c(0,1), type="n", axes=FALSE, xlab="", ylab="")
text(.5, .5, as.character(x), ...)
lines(c(-0.1,1.1), c(0,0))
par(opar)
}
format.digits <- function(x) as.character(paste("$", as.character(x), sep=" "))
@kmatt
kmatt / bigquery_schema.py
Created August 8, 2016 20:22 — forked from danielecook/bigquery_schema.py
Sense / infer / generate a big query schema string for import #bigquery
import mimetypes
import sys
from collections import OrderedDict
filename = sys.argv[1]
def file_type(filename):
type = mimetypes.guess_type(filename)
return type
@kmatt
kmatt / gmail_imap_example.py
Created December 15, 2016 19:55 — forked from robulouski/gmail_imap_example.py
Very basic example of using Python and IMAP to iterate over emails in a gmail folder/label. http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/
#!/usr/bin/env python
#
# Very basic example of using Python and IMAP to iterate over emails in a
# gmail folder/label. This code is released into the public domain.
#
# RKI July 2013
# http://www.voidynullness.net/blog/2013/07/25/gmail-email-with-python-via-imap/
#
import sys
import imaplib