Skip to content

Instantly share code, notes, and snippets.

View dgrtwo's full-sized avatar

David Robinson dgrtwo

View GitHub Profile
@dgrtwo
dgrtwo / drupal_password_hasher.py
Created April 9, 2012 15:44
Django password hasher for migration from Drupal
"""
DrupalPasswordHasher
To use, put this in any app and add to your settings.py, something like this:
PASSWORD_HASHERS = (
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'myproject.myapp.drupal_hasher.DrupalPasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
@dgrtwo
dgrtwo / minimal_Python.py
Created August 11, 2012 13:14
This simple script translates a Python program into another, equivalent, Python program using a minimal set of characters.
"""
Usage: python minimal_Python.py infile outfile
Programs output by this translator will run the same way as the original and
use only the characters:
()+1cehrx
The code is for entertainment only. Converting your code base to minimal Python
is not recommended.
@dgrtwo
dgrtwo / barcode_splitter.py
Created September 15, 2012 00:21
Barcode splitter for fastq sequencing files that splits using Levenshtein distance.
"""
barcode_splitter.py
Barcode splitter for fastq sequencing files, that matches using Levenshtein
distance.
USAGE:
python barcode_splitter.py reads.fastq index_reads.fastq barcodes.txt
@dgrtwo
dgrtwo / server.R
Created October 16, 2013 03:27
K-means clustering interactive tutorial
library(ggplot2)
library(shiny)
shinyServer(function(input, output) {
output$main_plot <- renderPlot({
set.seed(205)
means = t(replicate(input$clusters, c(runif(1), runif(1))))
means = cbind(1:input$clusters, means)
means = apply(means, 2, function(col) rep(col, input$points))
means = data.frame(means)
@dgrtwo
dgrtwo / gist:db83a968e880d8c325b2
Created August 1, 2014 17:41
Analysis of StackOverflow activity trends
library(dplyr)
library(ggplot2)
library(reshape2)
# used the query here:
# http://data.stackexchange.com/stackoverflow/query/213011/metrics-of-question-activity-over-time
dat = read.csv("permonth_data.csv")
dat = dat %>% mutate(Date=as.Date(paste(Year, Month, "15", sep="-")))
@dgrtwo
dgrtwo / mer_tidiers.R
Created January 5, 2015 20:15
Tidy, augment and glance (a la [broom](https://github.com/dgrtwo/broom) package) for lme4.0's "mer" class.
## "mer" methods for lme4.0, which couldn't be included in CRAN version
## of broom because it suggested lme4.0. See ?broom::lme4_tidiers for
## documentation.
tidy.mer <- function(x, effects = "random", ...) {
# pass directly on to lme4 method
effects <- match.arg(effects, c("random", "fixed"))
if (effects == "fixed") {
# return tidied fixed effects rather than random
@dgrtwo
dgrtwo / DataSet1.tds
Created March 12, 2015 18:43
Tidying gene expression data from Brauer et al 2008: [Coordination of growth rate, cell cycle, stress response, and metabolic activity in yeast](http://www.molbiolcell.org/cgi/pmidlookup?view=long&pmid=17959824).
This file has been truncated, but you can view the full file.
GID YORF NAME GWEIGHT G0.05 G0.1 G0.15 G0.2 G0.25 G0.3 N0.05 N0.1 N0.15 N0.2 N0.25 N0.3 P0.05 P0.1 P0.15 P0.2 P0.25 P0.3 S0.05 S0.1 S0.15 S0.2 S0.25 S0.3 L0.05 L0.1 L0.15 L0.2 L0.25 L0.3 U0.05 U0.1 U0.15 U0.2 U0.25 U0.3
GENE1331X A_06_P5820 SFB2 || ER to Golgi transport || molecular function unknown || YNL049C || 1082129 1 -0.24 -0.13 -0.21 -0.15 -0.05 -0.05 0.2 0.24 -0.2 -0.42 -0.14 0.09 -0.26 -0.2 -0.22 -0.31 0.04 0.34 -0.51 -0.12 0.09 0.09 0.2 0.08 0.18 0.18 0.13 0.2 0.17 0.11 -0.06 -0.26 -0.05 -0.28 -0.19 0.09
GENE4924X A_06_P5866 || biological process unknown || molecular function unknown || YNL095C || 1086222 1 0.28 0.13 -0.4 -0.48 -0.11 0.17 0.31 0 -0.63 -0.44 -0.26 0.21 -0.09 -0.04 -0.1 0.15 0.2 0.63 0.53 0.15 -0.01 0.12 -0.15 0.32 0.16 0.09 0.02 0.04 0.03 0.01 -1.02 -0.91 -0.59 -0.61 -0.17 0.18
@dgrtwo
dgrtwo / example.snippets
Last active August 29, 2015 14:19
Example snippets
snippet S3
${1:funcname} <- function(${2:args}, ...) UseMethod("${1:funcname}")
@dgrtwo
dgrtwo / saveRDS.Rmd
Last active September 3, 2018 19:08
saveRDS speed and size
---
title: "Effect of compression type and file complexity on saveRDS size and speed"
author: "David Robinson"
date: "April 20, 2015"
output: html_document
---
```{r echo = FALSE}
knitr::opts_chunk$set(cache = TRUE, message = FALSE)
```
@dgrtwo
dgrtwo / tidy_pipes.R
Created June 29, 2015 15:01
Script for turning "pipes" data from predpipe into a tidy data frame
library(plyr)
library(dplyr)
library(tidyr)
library(reshape2)
library(predpipe)
pipes_tidy <- pipes %>%
ldply(melt, .id = "path") %>%
rename(func = value, chain = L1) %>%