Skip to content

Instantly share code, notes, and snippets.

View rondale-sc's full-sized avatar

Jonathan rondale-sc

  • Providence, Rhode Island
View GitHub Profile
# include this in your ~/.zshrc or ~/.bashrc
pconsole () {
if [[ $1 == production ]];
then RAILS_ENV=production bundle exec pry -r ./config/environment.rb -r rails/console/app -r rails/console/helpers;
elif [[ $1 == test ]];
then RAILS_ENV=test pry -r ./config/environment.rb -r rails/console/app -r rails/console/helpers;
else bundle exec pry -r ./config/environment.rb -r rails/console/app -r rails/console/helpers;
fi }
@rondale-sc
rondale-sc / dndstats.rb
Created November 8, 2011 02:48
Down and Dirty Stats
require 'bigdecimal'
require 'csv'
require 'pp'
class Stats
include Enumerable
def initialize(array)
standardize_array(array)
end
@rondale-sc
rondale-sc / create_hash_from_csv.rb
Created November 30, 2011 15:40
Create hash from CSV using first field as key for a field hash based on header row
# encoding: utf-8
require 'csv'
require 'pp'
class CodeSearch
def initialize(csv)
@file_path = csv
parse
end
@rondale-sc
rondale-sc / gist:1761399
Created February 7, 2012 19:31
Tip for @peterc's ruby trickshot
# Two tips:
# Initialize a Hash with a default value of Array.
hash = Hash.new {|hash,key| hash[key] = []}
hash["some-key"] << "some-string value"
pp hash
# => {"some-key"=>["some-string value"]}
----------------------------------------------------------
@rondale-sc
rondale-sc / game_of_life.rb
Created February 21, 2012 03:01
Conway's Game of Life
require 'pry'
require 'pp'
# --------------------------------------------------------------
# CONWAY'S GAME OF LIFE!
#
# Any live cell with fewer than two live neighbours dies, as if caused by under-population.
# Any live cell with two or three live neighbours lives on to the next generation.
# Any live cell with more than three live neighbours dies, as if by overcrowding.
# Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
@rondale-sc
rondale-sc / percona_generate_sample.rb
Created March 21, 2012 14:12
Generate sample file
require 'rubygems'
require 'mysql2'
require 'faker'
require 'pry'
class SampleData
attr_reader :connection
def initialize(size)
@rondale-sc
rondale-sc / gist-1.rb
Created March 22, 2012 04:25
ruby-loves-sass-gists
module Sass::Script::Functions
def insert_grid(columns, width_string)
assert_type columns, :Number
assert_type width_string, :String
width = width_string.match(/\A(\d+)(\w+)\z/)[1]
type = width_string.match(/\A(\d+)(\w+)\z/)[2]
raise StandardError, "You must set width_string with unit ie '960px'. " unless ["px","em", "pt", "%"].include?(type)
grid, grid_segment_width = "", 0
@rondale-sc
rondale-sc / gist-1.js
Created March 22, 2012 04:39
encapsulation-in-javascript.js
function Mammal(species, defining_characteristic) {
this.species = species;
this.defining_characteristic = defining_characteristic;
}
Mammal.prototype.print = function(){
return "Hello I'm a " + this.species + ". " +
"I have " + this.defining_characteristic + "."
}
@rondale-sc
rondale-sc / gist-1.rb
Created March 22, 2012 05:00
hippo-your-friend-in-5010
require 'hippo'
ts = Hippo::TransactionSets::HIPAA_835::Base.new
ts.ST do |st|
st.TransactionSetControlNumber = '0021'
st.ImplementationConventionReference = '1234random1241'
end
puts ts.to_s
@rondale-sc
rondale-sc / gist-1.rb
Created March 22, 2012 05:05
ruby-hough-hack
# Authors: Robert Jackson, Jonathan Jackson
# the formatting of this file has been altered in
# order to fit on this website. Check out
# https://gist.github.com/1233581 if you care
require 'chunky_png' #or 'oily_png'
class Hough
def initialize(image_path, options={})
@image = ChunkyPNG::Image.from_file(image_path)
@image_path = image_path