Skip to content

Instantly share code, notes, and snippets.

View hoffmanc's full-sized avatar

Chris Hoffman hoffmanc

View GitHub Profile
@hoffmanc
hoffmanc / asdf.r
Created December 23, 2011 16:53
asdf.r
for(i in unique(mcg$runid)) {
png(paste("plots/greater_than_5_meters/",sprintf("%02d",i),".png",sep=""), width=1024, height=768)
df2 <- mcg[mcg$runid == i & mcg$distance > 5,] # remove the second condition for the "all" plots
plot(df2$lon.y, df2$lat.y, cex=0.1)
lines(c(df2$lon.x,df2$lon.y),c(df2$lat.x,df2$lat.y),col=1 + df2$runid %% 31)
title(main=paste("RUN", i), col.main=1+i%%31, font.main=3)
dev.off()
}
@hoffmanc
hoffmanc / output.irb
Created August 3, 2011 14:48
Problems with awesome_nested_set
chris@ubuntu:~/hud-pinellas$ rails console
Loading development environment (Rails 3.0.9)
irb(main):001:0> task = TimesheetTask.where('parent_id is not null').first
=> #<TimesheetTask id: 11261534, name: "Community Meetings", description: "attendance at meetings with local service providers...", task_type: "Voucher", parent_id: 1065399318, created_at: "2011-07-08 15:48:17", updated_at: "2011-07-08 15:48:17", lft: nil, rgt: nil>
irb(main):002:0> task.ancestors
=> []
irb(main):003:0> task.parent
=> #<TimesheetTask id: 1065399318, name: "Customer Service", description: nil, task_type: "Voucher", parent_id: 600959503, created_at: "2011-07-08 15:48:17", updated_at: "2011-07-08 15:48:17", lft: nil, rgt: nil>
irb(main):004:0> TimesheetTask.rebuild!
=> [#<TimesheetTask id: 36577376, name: "Special Programs (FSS, H, Other)", description: nil, task_type: "Voucher", parent_id: nil, created_at: "2011-07-08 15:48:17", updated_at: "2011-08-03 14:59:37", lft: 1, rgt: 34>, #<TimesheetTask id: 56366788, name: "Staff Meetings",
@hoffmanc
hoffmanc / exportData.py
Created July 12, 2011 13:23
Exporting Data from Access with Python
import pyodbc
import sys
import csv
conn = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\the\path\to\the.accdb;')
cursor = conn.cursor()
def output_col(col):
if col:
if isinstance(col, unicode):
# Chris Hoffman
# 2011-6-17
# Description: takes a
import pyodbc
import sys
import csv
import argparse
import glob
import os
@hoffmanc
hoffmanc / Rhino.Security.schema.sql
Created May 27, 2011 15:07
Rhino.Security on S# 1.9.6
/*
* Sets up the schema for support of Rhino.Security.
* This script assumes that you already have a Users table containing an int primary key of 'Id'
*/
USE Northwind
GO
/****** Object: ForeignKey FKBBE4029387CC6C80 Script Date: 03/12/2009 15:45:24 ******/
IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'FKBBE4029387CC6C80') AND parent_object_id = OBJECT_ID(N'security_EntityReferences'))
library(foreign)
setwd("\\\\wrjfiler\\wgx\\07183 - UVM TRC\\Signature #2\\data\\rundata\\CarDataREADONLY")
geo_files <- list.files(pattern=".*GEO.csv", recursive=T)
geo_tables <- c()
for(idx in 1:length(geo_files)){
runid <- sub(".*RUN_(\\d+).*", "\\1", geo_files[idx], perl=T)
mode(runid) <- "integer"
@hoffmanc
hoffmanc / outlin2json.py
Created April 8, 2011 11:29
outline2array.py
import re
import json
def get_lvl(line):
return len(re.findall("\t",line))
def get_tree(f):
global i
outline = []
primes = (1..10000).to_a.delete_if {|n| ('1' * n) =~ /^1?$|^(11+?)\1+$/}
bases = Hash.new
(2..20).each do |i|
ary = []
primes.each do |j|
str = j.to_s(i)
mid = str.length / 2
p1 = str[0..mid-1]
mid = str.length % 2 > 0 ? mid + 1 : mid
D <- function(n) sum((1:(n-1))[n%%1:(n-1)==0])==n
(2:9000)[sapply(2:9000,D)]
map{$s=0;for$i(1..$_-1){$s+=$_% $i eq 0?$i:0}print"$_\n"if$s==$_}1..10e3