Skip to content

Instantly share code, notes, and snippets.

View narath's full-sized avatar

Narath Carlile narath

View GitHub Profile
@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
@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 / 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 / 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 / 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 / upgrade_phusion_passenger_to_ruby_2_1_on_ubuntu_precise.md
Created April 26, 2014 16:36
How we upgraded Phusion Passenger for Ruby 2.1 on Ubuntu Precise

After upgrading to Ruby 2.1, the rails app and apache we got the following error in our apache log:

/usr/bin/ruby: warning: RUBY_HEAP_MIN_SLOTS is obsolete. Use RUBY_GC_HEAP_INIT_SLOTS instead.
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- phusion_passenger (LoadError)
	from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/share/phusion-passenger/helper-scripts/passenger-spawn-server:76:in `<main>'
[ pid=56858 thr=140583398008576 file=ext/apache2/Hooks.cpp:884 time=2014-04-25 22:10:55.823 ]: Unexpected error in mod_passenger: Cannot spawn application '/home/web1.kmedcommunications.com/current': Could not read from the spawn server: Connection reset by peer (104)
  Backtrace:
     (empty)
@narath
narath / realm_words
Last active August 29, 2015 14:13 — forked from anonymous/realm_words
Menopause
Antibiotics
Exercise
Jaundice
Rectal
@narath
narath / realm_words
Last active August 29, 2015 14:13 — forked from anonymous/realm_words
Menopause
Antibiotics
Exercise
Jaundice
Rectal
<!DOCTYPE html>
<html>
<head>
<title>Simple Auth App</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<script>
// get the URL parameters received from the authorization server
var state = getUrlParameter("state"); // session key