Skip to content

Instantly share code, notes, and snippets.

View Fonsan's full-sized avatar

Erik Fonselius Fonsan

View GitHub Profile
class ConcurrentHashMap < Hash; end
ConcurrentHashMap.send(:include,(Module.new do
def []=(key,value)
warn 'This method is slow'
super(key,value)
end
end))
h = ConcurrentHashMap.new
{
"7fb0d9"=>6028200,
"366d16"=>6035040,
"57d44a"=>6020760,
"d32228"=>6019140,
"027d29"=>6043620,
"cbc570"=>6000600,
"5f0756"=>6029820,
"798c69"=>6043860,
"803566"=>6024780,
url = "http#{schemes.sample}://#{
#subdomains
tlds.sample(1 + rand(3)).join('.')
}.#{
#host
host
}.#{
#tlds
tlds.sample
}#{
@Fonsan
Fonsan / Gemfile
Created June 10, 2011 13:22
Failing 2.0pre
source 'http://rubygems.org'
gem 'sinatra'
gem 'erubis'
gem 'shotgun'
@Fonsan
Fonsan / test.patch
Created May 29, 2011 15:53
default_scope select 3.1 aggregation
Form.count
(0.4ms) SELECT forms.id, forms.name, forms.created, forms.user_id, forms.category_id, forms.active_status, forms.read_only, forms.example_interview_id, COUNT(*) FROM `forms`
=> 1
> Form.unscoped.count
(0.2ms) SELECT COUNT(*) FROM `forms`
=> 4
> Form.unscoped.select("name").count
(0.3ms) SELECT COUNT(`forms`.`name`) FROM `forms`
=> 4
@samples = 10.times.map do rand(10) end
result = @samples.inject( Hash.new(0) ) do |hash,element|
hash[element] += 1
hash
end.to_a # => [[6, 3], [3, 1], [1, 1], [9, 2], [4, 2], [8, 1]]
module MetaSearch
module Helpers
module UrlHelper
def order_indicator_for(order)
if order == 'asc'
'&#9650;' # replace this with a string or nil
elsif order == 'desc'
'&#9660;' # replace this with a string or nil
else
@Fonsan
Fonsan / Debugger.rb
Created May 13, 2011 08:57
Has many through 3.1 beta
(rdb:1) pp o
#<Arel::Nodes::SelectCore:0x000001056b0638
@groups=[],
@having=nil,
@projections=
[#<struct Arel::Attributes::Attribute
relation=
#<Arel::Table:0x000001056aea68
@aliases=[],
@columns=nil,
@Fonsan
Fonsan / router.rb
Created March 13, 2011 17:09
Ugly non threadsafe way of routing a subdomain to a controller
class SupportSubdomain
def self.subdomain
@@request.subdomain.to_sym rescue :not_found
end
def self.matches?(request)
@@request = request
request.path_parameters[:controller] = request.subdomain
Rails.logger.info request.path_parameters[:controller]
#include <CoreServices/CoreServices.h>
static void callback(ConstFSEventStreamRef streamRef,
void *clientCallBackInfo,
size_t numEvents,
void *eventPaths,
const FSEventStreamEventFlags eventFlags[],
const FSEventStreamEventId eventIds[]) {
exit(0);
}