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 / 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
#!/bin/bash
# http://www.postgresql.org/message-id/4D3B1F75.8040405@2ndquadrant.com
# Output lines suitable for sysctl configuration based
# on total amount of RAM on the system. The output
# will allow up to 50% of physical memory to be allocated
# into shared memory.
# On Linux, you can use it as follows (as root):
@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 / sleeptil
Last active August 3, 2016 21:02
Bash sleep until time function
sleeptil () {
local END_TS END_DATE DUR
# Checking valid of date/time string
if ! END_TS=$(date -d "$*" +%s); then return 1; fi
# Cannot sleep back into the past
if (( END_TS < $(date +%s ))); then
echo "$(date -d "$*") is in the past!" >&2
return 1
@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
BEGIN {
# Array to validate dates from 2010-01-01 through 2019-12-31
t=1262304000; for (i=1; i<=3652; i++) { ymd[strftime("%Y-%m-%d", t)] = i; t+=86400 }
}
{
if ymd[$1] {
print $1 "valid"
} else {
print $1 "invalid"
@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