Skip to content

Instantly share code, notes, and snippets.

View campeterson's full-sized avatar

Cam Peterson campeterson

View GitHub Profile
@campeterson
campeterson / fixlion.sh
Created August 13, 2012 16:24 — forked from jetpks/fixlion.sh
Tweaks for OS X Lion.
#!/bin/bash
# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)
defaults write NSGlobalDomain AppleKeyboardUIMode -int 3
# Enable the 2D Dock
#defaults write com.apple.dock no-glass -bool true
# Disable menu bar transparency
#defaults write -g AppleEnableMenuBarTransparency -bool false
@campeterson
campeterson / notes.rb
Created October 24, 2012 04:17 — forked from coderberry/notes.rb
urug notes 10/23/2012
[1, 2, 3] * ',' # => "1,2,3"
[1, 2, 3] + [3, 4, 5] # => [1, 2, 3, 3, 4, 5]
[1, 2, 3] << "a" << "b" #=> [1, 2, 3, "a", "b"]
[ "a", "a", "c" ] <=> [ "a", "b", "c" ]
a = Array.new
a[4] = "hello" => [nil, nil, nil, nil, "hello"]
@campeterson
campeterson / Gemfile
Created November 1, 2012 18:28
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@campeterson
campeterson / screenshot.js
Created November 5, 2012 17:18 — forked from javan/screenshot.js
Create a screenshot of any URL using phantomjs (headless webkit)
//
// Example usage: phantomjs screenshot.js http://yahoo.com /tmp/yahoo.png
//
var system = require('system');
var url = system.args[1];
var filename = system.args[2];
var page = new WebPage();
page.open(url, function (status) {
@campeterson
campeterson / nucleotides.rb
Created November 6, 2012 04:33
codeupper1
#!/usr/bin/env ruby
contents = File.read('1.dataset')
A = contents.gsub(/[CcGgTt]/,'')
C = contents.gsub(/[AaGgTt]/,'')
G = contents.gsub(/[AaCcTt]/,'')
T = contents.gsub(/[AaCcGg]/,'')
puts "#{A.length} #{C.length} #{G.length} #{T.length}"
@campeterson
campeterson / nucleotides.rb
Created November 6, 2012 04:35
codeupper2
#!/usr/bin/env ruby
input = ARGV[0]
a = input.count('A');
c = input.count('C');
g = input.count('G');
u = input.count('U')
p "#{a} #{c} #{g} #{u}"
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))
@campeterson
campeterson / data-sets.md
Last active November 13, 2024 12:01
Data sets
from __future__ import division
import numpy
import shlex
from uuid import uuid1
class d3object:
def __init__(self,
height=100,
width=100,
topHtml='',
bottomHtml='',
response = $.getJSON("/pcr.json");
data = JSON.parse(response.responseText);
newData = {"Printer":{}, "Cutter": {}, "Router": []}
$(data).each( function() {
obj = this;
if (obj.type == "Router") {
newData[obj.type].push(obj.make);
} else {
if (!newData[obj.type][obj.make]) {