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 / compare.rb
Created March 21, 2014 20:28
Methods a, b, and c return truthy or falsy. Which of these is better approach?
method_a(data) && method_b(data) && method_c(data)
# or
if method_a(data)
if method_b(data)
method_c(data
end
end
@tamouse
tamouse / gist:9822711
Last active August 29, 2015 13:57
**SOLVED** Why does globally installed gem/script fail when run in a directory with a Gemfile?
tamara@pontiki:~/a/b/c/d/e/f:2014-03-27@07:55:24
$ mkdir test_dir
tamara@pontiki:~/a/b/c/d/e/f:2014-03-27@07:55:31
$ pushd test_dir/
~/a/b/c/d/e/f/test_dir ~/a/b/c/d/e/f ~
tamara@pontiki:~/a/b/c/d/e/f/test_dir:2014-03-27@07:55:43
$ gem env
RubyGems Environment:
@tamouse
tamouse / Floating-Labels.markdown
Created April 15, 2014 19:17
A Pen by Rik Schennink.
@tamouse
tamouse / block_formatting.html.erb
Last active August 29, 2015 14:01
passing a block to link_to or button_to, using bootstrappy goodnesses
<%= link_to edit_article_path(article), class: "btn btn-default" do -%>
<i class="glyphicon glyphicon-pencil"></i> Edit
<% end -%>
<%= button_to destroy_article_path(article), class: "btn btn-danger", method: "delete"
data: {confirm: "Are you sure?"}} do -%>
<i class="glyphicon glyphicon-delete"></i> Delete
<% end -%>
@tamouse
tamouse / flash_helper.rb
Created June 15, 2014 02:24
flash_class method for rails application helper
def flash_class(level)
class_level = case level.to_sym
when :success then "success"
when :error then "danger"
when :alert then "warning"
else 'info'
end
"alert alert-#{class_level}"
end
@tamouse
tamouse / check_options_parameters.rb
Created June 15, 2014 17:43
A small sample of checking for extra or missing option hash parameters.
class CheckOptionsParameters
attr_accessor :options, :options_keys, :valid_options
def initialize(options, valid)
self.options = options.nil? ? {} : Hash(options.dup)
self.options_keys = @options.keys
self.valid_options = valid.nil? ? [] : Array(valid.dup)
end
@tamouse
tamouse / README.md
Created June 16, 2014 17:30
Setting up log4r the way I like it for simple ruby apps.

Log4r Setup

One day I was sitting around trying to get some logging and output done on a rakefile, and getting tired of doing log.info("blah blah").tap{|t| puts t}, so I looked into log4r, and decided to use it. So here we are.

Set up log4r the way I like:

  • Info Messages to stdout with no decoration
STOPWORDS=%w[a an and in of the].freeze
def proper_title(t)
t.to_s.split.inject([]) do |m, x|
if m.empty? || ! STOPWORDS.include?(x)
m << x.capitalize
else
m << x
end
end.join(" ")
end
@tamouse
tamouse / JEKYLL-BOOTSTRAP-UPDATE-README.md
Last active August 29, 2015 14:03
Rake task to update Jekyll repo with new TWBS version

Let's say you have a Jekyll site that you are using bootstrap-sass on, and you want to update to a new version.

This rake task will pull in the new version, unpack it, and move things into the appropriate locations, based on your _config.yml file.

touche

@tamouse
tamouse / airline_code.rb
Created July 13, 2014 03:03
doing something like an airline confirmation code with securerandom
[1] pry(main)> require 'securerandom'
=> true
[2] pry(main)> SecureRandom.hex(6).upcase
=> "123B1EEF6F4C"
[3] pry(main)> SecureRandom.hex(3).upcase
=> "917522"
[4] pry(main)> SecureRandom.hex(3).upcase
=> "3EE4B5"
[5] pry(main)> SecureRandom.hex(3).upcase
=> "2188BB"