Skip to content

Instantly share code, notes, and snippets.

@dschneider
dschneider / Gemfile.lock
Created November 29, 2012 07:56
My Gemfile.lock
GIT
remote: git://github.com/softa/activerecord-postgres-hstore.git
revision: a211841295882aa3e2c267750037b8bc58da5546
ref: a211841295882aa3e2c267750037b8bc58da5546
specs:
activerecord-postgres-hstore (0.4.0)
pg
rails
rake
@dschneider
dschneider / BCryptOptimisation.rb
Created November 25, 2012 18:04
BCrypt optimisation for use in testing.
require 'bcrypt'
silence_warnings do
BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST
end
@dschneider
dschneider / DeferredGarbageCollection.rb
Created November 25, 2012 17:55
Deferred Garbage Collection for speeding up unit and integration tests
# Public: This class contains methods for deferred garbage collection which
# improves the time consumption of integration and unit tests.
class DeferredGarbageCollection
# Public: The time threshold used by the deferred garbage collection. It's
# either set as an environment variable or defaults to 5 seconds.
GC_THRESHOLD = (ENV['DEFER_GC'] || 5.0).to_f
# Public: The last time the GC has run.
@@last_gc_run = Time.now
@dschneider
dschneider / jelly_time_nokogiri.rb
Created September 15, 2012 13:10
Tells me the latest JellyTime rom version that has been released. Just to play around with Nokogiri a little.
# !/usr/bin/ruby
require 'uri'
require 'net/http'
require 'nokogiri'
URL = "http://forum.xda-developers.com/showthread.php?t=1778202"
text = Net::HTTP.get(URI.parse(URL))
doc = Nokogiri::HTML(text)
@dschneider
dschneider / gist:2941990
Created June 16, 2012 17:16
RSpec - Request with remote IP
xhr :post, PATH, DATA, "REMOTE_ADDR" => "192.168.0.1"
@dschneider
dschneider / gist:2941985
Created June 16, 2012 17:15
RSpec - Stub Remote IP Request
ActionDispatch::Request.any_instance.stub(:remote_ip).and_return("192.168.0.1")
@dschneider
dschneider / gist:2941980
Created June 16, 2012 17:13
Mandelbrot Fractal
_ = (
255,
lambda
V ,B,c
:c and Y(V*V+B,B, c
-1)if(abs(V)<6)else
( 2+c-4*abs(V)**-0.4)/i
) ;v, x=1500,1000;C=range(v*x
);import struct;P=struct.pack;M,\
j ='<QIIHHHH',open('M.bmp','wb').write
module Fruits
@fruits = ["Banana", "Apple", "Melon"]
def self::[](index)
return @fruits[index]
end
def self.list_fruits
@fruits.each { |name| print name; puts "\n" }
puts "Those fruits are inside!"
@dschneider
dschneider / gist:2941811
Created June 16, 2012 16:15
Ruby - Conditions in Strings #3 (The right way!)
"Hello #{'Dr. ' if doctor}#{name}"
@dschneider
dschneider / gist:2941809
Created June 16, 2012 16:14
Ruby - Conditions in Strings #2
string = "Hello " doctor ? string += "Dr. " : "" string += name