Skip to content

Instantly share code, notes, and snippets.

View tamouse's full-sized avatar
🏠
Working from home

Tamara Temple tamouse

🏠
Working from home
View GitHub Profile
@tamouse
tamouse / cron_tasks_for_login_environment_commands.md
Last active August 29, 2015 13:55
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
tamouse / bin_to_dec.rb
Last active August 29, 2015 13:55
simple repl that shows binary string to decimal string conversion -- doing conversion by hand.
#!/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/]
@tamouse
tamouse / Property.rb
Last active August 29, 2015 13:55 — forked from anonymous/Property.rb
class Property < ActiveRecord::Base
belongs_to :detail
end
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/Xcode.app/Contents/Developer/usr --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
tamouse / SubscriptionForm.rb
Created February 21, 2014 00:09
Problem with reform from_hash method missing for a nested model.
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
tamouse / log
Created February 23, 2014 15:54
parameters from submitting a recipe to https://github.com/tamouse/test_nested_attributes
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
tamouse / pyramid.out
Last active August 29, 2015 13:56
Pyramid scheme
[6] pry(main)> load 'pyramid.rb'
=> true
[7] pry(main)> pyr1 = Pyramid.new(5)
=> #<Pyramid:0x007fb08e74a9a0
@pyramid=[[1], [2, 1], [3, 2, 1], [4, 3, 2, 1], [5, 4, 3, 2, 1]],
@size=5>
[8] pry(main)> print pyr1
1
2 1
3 2 1
@tamouse
tamouse / README.md
Created February 25, 2014 09:13
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
tamouse / hash_walk.rb
Created March 2, 2014 16:00
walking a complex data structure (deep hash)
# 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
tamouse / Guardfile
Last active August 29, 2015 13:57
Using thor to generate a new ruby project.
guard :bundler do
watch('Gemfile')
# Uncomment next line if your Gemfile contains the `gemspec' command.
# watch(/^.+\.gemspec/)
end
guard :rspec, :cmd => "bundle exec rspec" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }