Skip to content

Instantly share code, notes, and snippets.

View mdobson's full-sized avatar
😺
Petting a cat

Matthew Dobson mdobson

😺
Petting a cat
View GitHub Profile
@mdobson
mdobson / gist:2047460
Created March 15, 2012 22:50
.profile edits to enable scala, mongodb, and postgresql from the command line.
export PATH="/usr/local/bin/psql:$PATH"
export PATH="/Users/dobsonm2/mongodb/bin:$PATH"
export PATH="/Users/dobsonm2/scala/bin:$PATH"
@mdobson
mdobson / gist:2266658
Created March 31, 2012 16:45
Simply crawling a page and pushing to redis
import requests
from bs4 import BeautifulSoup
import redis
#parse front page of hacker news
url = 'http://news.ycombinator.com/'
r = requests.get(url)
soup = BeautifulSoup(r.text)
@mdobson
mdobson / read-from-redis.py
Created March 31, 2012 16:58
Read web page
import redis
import requests
from bs4 import BeautifulSoup
#create redis connection
redis_server = redis.Redis("localhost")
#read a link from the redis index
requrl = redis_server.lindex("index",2)
@mdobson
mdobson / post_delegate.rb
Created April 7, 2012 02:32
use of delegates
class ExampleSubject < ActiveRecord::Base
belongs_to :study
belongs_to :user
delegate :email, :to => :user
scope :retrieve_by_study_and_identifier, lambda{|study_id, subj_id|
where("study_id = ? and id = ?", study_id, subj_id)}
end
@mdobson
mdobson / no_delegate.rb
Created April 7, 2012 02:32
No use of delegates
class ExampleSubject < ActiveRecord::Base
belongs_to :study
belongs_to :user
scope :retrieve_by_study_and_identifier, lambda{|study_id, subj_id|
where("study_id = ? and id = ?", study_id, subj_id)}
end
<% @subjects.each do |subject| %>
<tr>
<th><%= subject.id %></th>
<th><%= subject.identifier %></th>
<th><%= subject.email %></th>
<th><%= link_to "Edit Subject", edit_study_example_subject_path(@study,subject) %></th>
<th>
<%= form_for [@study, subject] , :html => {:method => :delete} do |f| %>
<%= f.submit "Delete", :class => "btn btn-info" %>
<% end %>
@mdobson
mdobson / before.html.erb
Created April 7, 2012 02:35
Before delegates
<% @subjs.each do |subj| %>
<tr>
<th><%= subj.id %></th>
<th><%= subj.identifier %></th>
<th><%= subj.user.email %></th>
<th><%= link_to "Edit Subject", edit_study_example_subject_path(@study,subj) %></th>
<th>
<%= form_for [@study, subj] , :html => {:method => :delete} do |f| %>
<%= f.submit "Delete", :class => "btn btn-info" %>
<% end %>
@mdobson
mdobson / gist:2631525
Created May 7, 2012 23:57
Coffeescript snippet of data binding
model.bind("change:datapoint", ()=>
$(@el).find(".datapoint").val(@model.model.get("datapoint")))
@mdobson
mdobson / gist:3071299
Created July 8, 2012 15:00
Defining a dynamic singleton method in ruby
class Doc
def initialize(doc)
doc.each do |key, value|
define_singleton_method key, lambda { value }
end
end
end
@mdobson
mdobson / CSVtoJSON.rb
Created July 8, 2012 15:51
Convert CSV to JSON with simple command line script
#!/usr/bin/env ruby
require 'json'
file = File.new(ARGV[0], "r")
#get format
puts "Getting format"
format = file.gets