Skip to content

Instantly share code, notes, and snippets.

Job hunting

Tamara Temple tamouse

Job hunting
View GitHub Profile
tamouse /
Last active Aug 29, 2015
The unix command cron(1) runs in a different environment than your login environment. Here is how to get it back.

Getting some jobs to run under cron(1) can be confusing and difficult since cron executes tasks in the crontab(5) file with a different underlying environment than a user normally runs in. What works from you login shell command line often won't from a cron job. Here is how to get it back.

What determines cron's environment?

By default, cron runs with the barest environment. You can discover this by running the following in your crontab:

* * * * * (/usr/bin/date ; /usr/bin/env | /usr/bin/sort) >> /tmp/my_cron_env 2>&1

This will run the task every minute, with stdout and stderr sent to the file. You should make sure to remove or comment out this line after a minute or so or you'll build up quite a long file.

tamouse / bin_to_dec.rb
Last active Aug 29, 2015
simple repl that shows binary string to decimal string conversion -- doing conversion by hand.
View bin_to_dec.rb
#!/usr/bin/env ruby
OUTPUT_FORMAT = "%s in decimal is %s"
ERROR_FORMAT = "Argument %s must be a binary string (0 and 1 only)."
def convert(binary_string="")
binary_string = binary_string.to_s
unless binary_string[/\A[01]+\z/]
View Property.rb
class Property < ActiveRecord::Base
belongs_to :detail
View ruby.v.python.out
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-darwin13.0.0]
Python 2.7.5
javac 1.6.0_65
Configured with: --prefix=/Applications/ --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
tamouse / SubscriptionForm.rb
Created Feb 21, 2014
Problem with reform from_hash method missing for a nested model.
View SubscriptionForm.rb
class SubscriptionForm < Reform::Form
property :extra_user_information do
property :first_name, :on => :extra_user_information
property :last_name, :on => :extra_user_information
property :email, :on => :extra_user_information
property :phone, :on => :extra_user_information
property :fax, :on => :extra_user_information
property :website, :on => :extra_user_information
property :company, :on => :extra_user_information
tamouse / pyramid.out
Last active Aug 29, 2015
Pyramid scheme
View pyramid.out
[6] pry(main)> load 'pyramid.rb'
=> true
[7] pry(main)> pyr1 =
=> #<Pyramid:0x007fb08e74a9a0
@pyramid=[[1], [2, 1], [3, 2, 1], [4, 3, 2, 1], [5, 4, 3, 2, 1]],
[8] pry(main)> print pyr1
2 1
3 2 1
View log
Processing by RecipesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"NPBI20K5lMJHxZGw8Y2FtDLy7KvRr4We2bFHYc3JWlE=", "recipe"=>{"name"=>"omelette", "ingredients_attributes"=>{"0"=>{"quantity"=>"2", "measure"=>"", "name"=>"eggs", "_destroy"=>"false"}, "1"=>{"quantity"=>"1", "measure"=>"oz", "name"=>"shredded cheese", "_destroy"=>"false"}, "2"=>{"quantity"=>"", "measure"=>"", "name"=>"salt & pepper to taste", "_destroy"=>"false"}, "1393170715291"=>{"quantity"=>"1", "measure"=>"tblsp", "name"=>"butter", "_destroy"=>"false"}}, "directions_attributes"=>{"0"=>{"step"=>"warm up pan with butter", "_destroy"=>"false"}, "1"=>{"step"=>"crack egg into bowl, whisk thoroughly", "_destroy"=>"false"}, "2"=>{"step"=>"when pan is hot, pour in egg", "_destroy"=>"false"}, "1393170756671"=>{"step"=>"let egg cook until bottom is settled. sprinkle in cheese. fold and remove from heat", "_destroy"=>"false"}, "1393170794649"=>{"step"=>"let omelette set for 1 minute", "_destroy"=>"false"}}, "notes"=>""}, "c
tamouse /
Created Feb 25, 2014
demo assignment methods

WARNING Setter methods don’t return what you might think. When you use the syntactic sugar that lets you make calls to = methods look like assignments, Ruby takes the assignment semantics seriously. Assignments (like x=1) evaluate to whatever’s on their right-hand side. Methods usually return the value of the last expression evaluated during execution. But = method calls behave like assignments: the value of the expression ticket.price = 63.00 is 63.00, even if the ticket= method returns the string “Ha ha!” The idea is to keep the semantics consistent. Under the hood, it’s a method call; but it looks like an assignment and behaves like an assignment with respect to its value as an expression.

tamouse / hash_walk.rb
Created Mar 2, 2014
walking a complex data structure (deep hash)
View hash_walk.rb
# An attempt to build a method that will deep walk a hash in order to
# convert it to something else, possibly an ostruct
class Hash
def walk(&b)
each do |k,v|
case v
when Hash
tamouse / Guardfile
Last active Aug 29, 2015
Using thor to generate a new ruby project.
View Guardfile
guard :bundler do
# Uncomment next line if your Gemfile contains the `gemspec' command.
# watch(/^.+\.gemspec/)
guard :rspec, :cmd => "bundle exec rspec" do
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }