Skip to content

Instantly share code, notes, and snippets.

View phosphene's full-sized avatar

Ed Phillips phosphene

View GitHub Profile
require 'rsruby'
r = RSRuby.instance
# mod of Peter Lane's Ruby for Scientific Research plot example
# construct data to plot, graph of x vs exp(x)
xs = 10.times.collect {|i| i}
ys = xs.collect {|x| r.exp(x)}
r.png("exp_example.png") # tell R we will create png file
@phosphene
phosphene / du_ch_pipe_to_ack.txt
Created January 8, 2011 20:20
disk usage human readable output pipe to ack and show only dirs with Gig multiples
[root@phosphene /]# du -ch | ack "^[\d\.]*?G"
@phosphene
phosphene / disk_usage_culprits_fine_grained
Created January 8, 2011 20:53
du -ch piped to ack find dir outputs with Gig multiples and hundreds of megs
[root@phosphene /]# du -ch | ack "^[\d\.]+?G|^\d{3,4}M"
opening connection to localhost...
opened
opening connection to localhost...
opened
<- "POST /users.json HTTP/1.1\r\nContent-Type: application/json\r\nAccept: */*\r\nUser-Agent: Ruby\r\nConnection: close\r\nHost: localhost:9292\r\nContent-Length: 209\r\n\r\n"
<- "{\"user\":{\"email\":\"ed@cronos.com\",\"encrypted_password\":\"$2a$10$fsLeIBMVmx8nfmKs3mp3R.HbUgTmivddTUuO.0GzQkONMWV.ylaAe\",\"password_salt\":\"$2a$10$fsLeIBMVmx8nfmKs3mp3R.\",\"username\":\"faustrolle\",\"zip_code\":\"97221\"}}"
-> "HTTP/1.1 500 Internal Server Error \r\n"
-> "Content-Length: 321\r\n"
-> "Content-Type: text/html\r\n"
-> "Server: WEBrick/1.3.1 (Ruby/1.8.7/2011-01-18)\r\n"
class User < ActiveResource::Base
#generic user class for test
#include ActiveModel::Validations
self.site = "http://localhost:9292/"
self.format = :json
end
require 'spec_helper'
module UserSpecHelper
def valid_user_attributes
{ 'email' => 'ed@test.com',
'username' => 'faustrolle',
'password' => 'abcdefg',
'zip_code' => '97221' }
end
end
@phosphene
phosphene / add_numbers_in_text.rb
Created February 11, 2012 21:17
find and add numbers at first position of lines only in text file
File.open('test.txt', 'r') do |f|
count = 0
f.each_line do |line|
if line =~ /^(\d+)/
count = count + $1.to_i
end
end
puts count
end
# http://blog.firsthand.ca/2011/12/example-using-rspec-double-mock-and.html
describe Transfer do
context "transfer with amount of 10" do
let(:source_account) { double :source_account, :decrease => nil }
let(:destination_account) { double :destination_account, :increase => nil }
def transfer_amount(amount)
Transfer.new(source_account, destination_account, amount).call
end
@phosphene
phosphene / zumbach.jpeg
Last active February 3, 2021 17:17
Zumbach the Tailor
zumbach.jpeg
@phosphene
phosphene / sandis_rules.txt
Last active December 12, 2015 05:08
Sandi Metz's Rules of Parsimony for Rails
1. Your classes should be no longer than (200) 100 lines of code.
2. Your methods should be no longer than (10) five lines of code.
3. You should pass no more than four parameters into a method.
4. Your controller should only instantiate one object to do whatever it is that needs to be done.
5. Your view can only know about one instance variable.
6. Err on the side of many small objects
7. Thin Models/Thin Controllers
8. Drive design through tests
9. See "Lex Parsimoniae" for advice