Skip to content

Instantly share code, notes, and snippets.

View narath's full-sized avatar

Narath Carlile narath

View GitHub Profile
@narath
narath / gist:7694671
Created November 28, 2013 16:35
Easier releases with git and git flow
# Create a file in config/initializers/version.rb, with the following string in it
# APP_VERSION = "0.0.0"
#
# Add this file to lib/tasks
#
# Add the following to ~/.bash_profile
# function release() {
# version=`bundle exec rake version:next`
# git flow release start $version && bundle exec rake version:bump && git commit -a -m "version bump" && git flow release finish $version && git push origin master
# }
@narath
narath / comma_separated_collection_in_simple_form.md
Last active December 14, 2015 12:09
Using simple_form collections to save and load a comma separated values string as checkboxes

Based on https://gist.github.com/jchunky/3444833

add the collection helper methods to your model

class QuizAnswer < ActiveRecord::Base
  ...  
  def user_answer_collection
    return [] if !user_answer
    user_answer.split(",")

end

@narath
narath / step_timer.rb
Last active December 11, 2015 21:48
Step timer that predicts how long something will take to complete based on measurements of how long each step is taking you
#!/usr/bin/env ruby
# provides a basic timer, and predicts how long something will take you based on how long each individual step is taking you.
# Parameters:
# timer [num_steps=100] [at_steps]
def main
total_steps = 100;
@narath
narath / pretty_phone_number.rb
Created September 16, 2012 01:29
Pretty printing a phone number from a string
def pretty_phone_number(str_num)
# I know how to handle 9 digit numbers
# I know how to handle 10 digit numbers
# for above that I only know how to divide into 3s
result = ""
case
when str_num.length==10
result << '('+str_num[0..2]+') '+str_num[3..5]+'-'+str_num[6..9]
when str_num.length == 11 && str_num =~ /^1/
@narath
narath / gist:1129474
Created August 6, 2011 16:14
Ruby Easy Grep Script
#!/usr/bin/ruby
# from http://www.3till7.net/2010/02/23/convenient-file-searching-with-ruby-grep-and-file/
unless ARGV.length >= 2
puts "Usage: #$0 file_extension query"
puts "\tExample: #$0 '*.h' 'struct list_head'"
exit
end
unless ARGV.length == 2