Skip to content

Instantly share code, notes, and snippets.

View jcasimir's full-sized avatar

Jeff Casimir jcasimir

View GitHub Profile
# Implement an algorithm
# to determine if a string has all unique characters
# without using uniq.
# What if you can not use additional data structures?
# ===
sample = "abcdę"
sample.split('').uniq.count == sample.split('').count
sample.split('').uniq.count == sample.length
@jcasimir
jcasimir / atom_notes.markdown
Created March 12, 2014 16:22
Notes about the Atom Editor

Getting Setup

Creating an Alias

In you ~/.bash_profile, add:

alias a="/Applications/Atom.app/Contents/MacOS/Atom $1"
desc "It's says 'Hey'"
task :say_hey do
`say hey`
end
desc "It says 'Hey you'"
task :say_hey_you => [:say_hey] do
`say you`
end
# Go through the numbers 0 through 100 (including both 0 and 100)
# If the number is divisible by 3, print "Fizz"
# If the number is divisible by 5, print "Buzz"
# If the number is divisible by both 3 and 5, print "FizzBuzz"
# Otherwise print the number
# Solution 1
#
# (0..100).each do |i|
# if (i % 3 == 0) && (i % 5 == 0)
@jcasimir
jcasimir / Guardfile
Created July 1, 2014 16:06
generic minitest Guardfile
guard :minitest do
watch(/test\/.+_test\.rb/)
watch(/lib\/(.+)\.rb/) do |data|
"test/#{data[1]}_test.rb"
end
end
class Garden
attr_reader :layout, :row_0, :row_1
def initialize(layout, two=nil)
@row_0, @row_1 = layout.split("\n")
@layout = layout.gsub("\n", "")
end
def alice
@jcasimir
jcasimir / garden_meta.rb
Created July 1, 2014 17:03
Full Garden.rb with Metaprogramming
class Garden
attr_reader :row_0, :row_1, :names
def initialize(layout, names=nil)
@row_0, @row_1 = layout.split("\n")
@names = format_names(names) || default_names
build_name_accessor_methods
end
def format_names(names)
@jcasimir
jcasimir / admin_routes.rb
Created July 31, 2014 17:41
Breaking Out Routes
module Sinatra
module AdminRoutes
def self.registered(app)
app.get "/admin/pages" do
pages = Page.all
erb 'admin/pages'
end
end
@jcasimir
jcasimir / example.rb
Created September 25, 2014 03:17
manual stubbing
class Game
def get_input
gets.chomp
end
def play
unless get_input == "quit"
puts "Still Going"
end
@jcasimir
jcasimir / di_example.rb
Last active August 29, 2015 14:06
Gets.chomp stubbing with Dependency Injection
class InputFetcher
def fetch
gets.chomp
end
end
class Game
attr_reader :fetcher
def initialize(fetcher_type = InputFetcher)