Skip to content

Instantly share code, notes, and snippets.

View batasrki's full-sized avatar

Srdjan Pejic batasrki

  • S-Squared Design & Development
  • Toronto, ON
View GitHub Profile
some_variable = begin
if some_condition?
some_value
else
another_value
end
end
some_variable = if some_condition?
some_value
else
another_value
end
development: &global_settings
database: textual_development
host: 127.0.0.1
port: 27017
test:
database: textual_test
<<: *global_settings
production:
// DOM Builder plugin for jQuery
// (c) Dan Webb ([email protected])
//
// $.build(function() {
//
// div({ 'class': 'module' },
// h1('A list of stuff'),
// ul(
// li('item 1'),
// li('item 2'),
it "should time how long it takes to find a number in a set of 100" do
# when uniq! is executed the number of items in the array is roughly halved, so I need to double the seed
seed = []
(1..200).each { |num| seed << rand(num)}
seed.uniq!.sort!
index_found = search(81, seed)
x.report("elight's:") { bchop(81, seed).should == index_found}
end
#linear search function to compare against
def transform_hash(original, options={}, &block)
original.inject({}){|result, (key,value)|
value = if (options[:deep] && Hash === value)
transform_hash(value, options, &block)
else
value
end
block.call(result,key,value)
result
}
class BinarySearch
attr_accessor :index_tracker, :times_split
def initialize
@index_tracker= @times_split = 0
end
def search(search_for, list)
return -1 if list.size == 0 || (list.size == 1 && search_for != list[0])
#location_of_number = list.index(search_for)
#if location_of_number != nil
class Array
def map_e(elz, &block)
results = []
if length > 0
each do |o|
block.call(o)
end
else
elz.call
end
@batasrki
batasrki / url_dsl.rb
Created December 14, 2009 19:47 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
@batasrki
batasrki / url_dsl.rb
Created December 14, 2009 19:47 — forked from defunkt/url_dsl.rb
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json