Skip to content

Instantly share code, notes, and snippets.

#Declaring a new Hash instance
creditcard = {
"name" => "Billy Bob",
"number" => "4444333322221111",
"code" => "555",
"expiry" => "07/2016"
}
#Using Symbols as keys
customer = {
name: "Billy Bob",
tel: "(415)555-5555",
}
defaults = {font: 'Arial', font_size: '12px'}
customer_prefs = {font: 'Helvetica'}
style = defaults.merge customer_prefs
@stujo
stujo / gist:8789596
Created February 3, 2014 18:35
Hash with symbols as keys
hsh = { name: "Wallace", favourite: "Vegan Captain Kirk" }
@stujo
stujo / Instructions for Installing Git Tab Completion and Prompt
Last active August 29, 2015 13:57
Mac OSX Terminal Tab with Git Completion
#Git Shell Setup FOR BASH ONLY
Add Tab completion for GIT and the current branch to your terminal prompt
This Process Installs these awesome scripts on a Mac OSX:
https://github.com/git/git/tree/master/contrib/completion
##Installation:
@stujo
stujo / parallel_assignment.rb
Last active August 29, 2015 13:59
Ruby : Parallel Assignment
def parallel_assigns
# Parallel Assignment
puts "Parallel assign a and b"
a, b = 1, 2
puts "a is #{a}"
puts "b is #{b}"
puts "Initializing c and d"
@stujo
stujo / app_controllers_search_controller.rb
Last active August 29, 2015 14:01
Ruby on Rails 4.1 : Adding a Search Form using a Form Object
class SearchController < ApplicationController
skip_before_filter :verify_authenticity_token
def results
@search_form = SearchForm.new(params.require(:search_form).permit(:q))
if (@search_form.valid?)
# This sample assumes a model called Contacts with a column field called name
@results = @search_form.search_within (Contacts.all, :name)
end
@stujo
stujo / expose_via_closure.js
Created May 21, 2014 16:23
expose_via_closure.js
var exposed = function (){
function my_secret()
{
return 'I like unicorns'
}
this.tell_secret = function()
{
return 'Hello! Shhh, but ' + my_secret() + "!";
}
@stujo
stujo / enummer.rb
Last active August 29, 2015 14:06
Enumerator Playground
require 'fiber'
#https://practicingruby.com/articles/building-enumerable-and-enumerator
module FakeEnumerable
def select
result = []
each do |value|
result << value if yield(value)
end
@stujo
stujo / falsey_truthy.rb
Last active August 29, 2015 14:06
falsey_truthy - Truthyness and Falseyness in Ruby
def falsey_truthy string_test
begin
value = eval string_test
puts "#{string_test} -> '#{value}' is #{value ? 'truthy' : 'falsey'}"
rescue NameError => e
puts e
end
end
tests = [