Skip to content

Instantly share code, notes, and snippets.

class ContainerLabel < ActiveRecord::Base
aasm_column :state
aasm_initial_state :undownloaded
aasm_state :undownloaded
aasm_state :downloaded
aasm_event :download do
transitions :to => :downloaded, :from => :undownloaded
end
def download
@jpowers
jpowers / gist:659818
Created November 2, 2010 15:52
nav helper
def nav_item(title, url)
active_class = current_path?(url) ? ' class=\'active\'' : ''
content = '<li' + active_class + '>'
content << capture do
link_to title, url
end
content << content_tag(:span) << '</li>'
content.html_safe
end
named_scope :patient_first_name_or_last_name_or_mrn_like, lambda{|name|
Patient.first_name_or_last_name_or_mrn_like(name).proxy_options.merge({:joins =>[{:order => :patient}]})
}
@jpowers
jpowers / gist:862798
Created March 9, 2011 19:28
curl POST
curl -i -u foo@email.com:123456 -X POST -H 'Content-Type: application/xml' -d '<user><email>foo@example.com</email><postal-code>12345</postal-code></user>' http://0.0.0.0:3000/users.xml
#git prompt
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
green=$'\e[1;32m'
magenta=$'\e[1;35m'
normal_colours=$'\e[m'
export PS1="$NM$HI\u@$HII\h:$SI\w$NM\[$magenta\]\$git_branch\[$green\] $ $IN"
function find_git_branch {
local dir=. head
#!/bin/bash
sudo apt-get update
sudo apt-get upgrade –y
sudo apt-get install vim build-essential libssl-dev openssl curl libxml2-dev libxslt1-dev git-core mysql-server libmysqlclient-dev \
nginx monit ufw monit lynx unixodbc-dev unixodbc tdsodbc freetds-dev freetds-common libreadline5-dev libncurses5-dev libaio-dev -y
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.profile
@jpowers
jpowers / gist:1420039
Created December 1, 2011 21:34
inverse_of for in memory association access
class Shipment < ActiveRecord::Base
has_many :labels
accepts_nested_attributes_for :labels
end
class Label < ActiveRecord::Base
belongs_to :shipment
end
ruby-1.9.2-p180 :001 > s = Shipment.new(:vendor_service_code =>'asdasd', "labels_attributes"=>{"0"=>{"package_weight"=>"1", "insured_value"=>"50"}})
ruby-1.9.2-p180 :026 > pp bing.news('"global warming" or "climate change" not happening').news.results.first
{"Title"=>"Climate change is happening but it's out of man's control",
"Url"=>
"http://www.sun-sentinel.com/news/opinion/fl-readers-view-global-warming-20120110,0,6201898.story",
"Source"=>"Sun Sentinel",
"Snippet"=>
"does not seem to understand that the science concerning humans being primarily responsible is far from settled. The writer states that global warming/climate change has been happening for 30 to 100 years, which understates the time frame by ...",
"Date"=>"2012-01-10T07:53:54Z",
"BreakingNews"=>0}
class SettingsController < ApplicationController
set_tab :settings
before_filter :authenticate_user!
def edit
@user = current_user
end
def update
@jpowers
jpowers / gist:5731878
Last active August 1, 2017 20:29
Ruby Hash with range key
class RangedHash
def initialize(hash)
@ranges = hash
end
def [](key)
@ranges.each do |range, value|
return value if range.include?(key)
end
end