Skip to content

Instantly share code, notes, and snippets.

@mcansky
mcansky / gist:3098899
Created July 12, 2012 15:35
ruby eq strings
require 'benchmark'
N = 10000
STRING = "cat"
DAT = "cat"
puts "#{STRING} vs #{DAT}"
Benchmark.bmbm do |x|
@mcansky
mcansky / speaker.md
Created June 18, 2012 16:28 — forked from matiaskorhonen/speaker.md
Frozen Rails Talk Proposal Template (http://2012.frozenrails.eu/)
require 'benchmark'
ARRAY = (0..1000).to_a
N = 100000
Benchmark.bmbm do |x|
x.report('each') { N.times {
array = [ ]
array = [ ]
[1,2,3,4].each { |c| array << c }
@mcansky
mcansky / gist:2658018
Created May 11, 2012 06:56
FaP (Fork and Play)
## solve this
#
# max 3 lignes, benche avec Benchmark (http://ruby-doc.org/stdlib-1.9.3/libdoc/benchmark/rdoc/Benchmark.html)
#
# "34,6".to_f -> 34 ; comment faire pour obtenir 34.6 comme un Float/Decimal ?
#
@mcansky
mcansky / rake task to queue.rake
Created March 9, 2012 16:09
using iron.io workers
namespace :iron do
desc "queue clockwork job at Iron worker"
task :queue_clockwork => :environment do
require "iron_worker_ng"
client = IronWorkerNG::Client.new(Settings.iron_worker.token, Settings.iron_worker.project_id)
# ...and upload it to iron.io cloud
# :host, :port, :ssl, :payload, :url, :token, :username
options = {:start_at => 30.seconds.since, :run_every => 300}
options[:run_times] = ENV['COUNT'].to_i if ENV["COUNT"]
$ gem list
*** LOCAL GEMS ***
bundler (1.0.22)
iron_worker_ng (0.1.5)
json (1.6.5)
mime-types (1.17.2)
rake (0.9.2)
rest (0.2.0)
require "iron_worker_ng"
code = IronWorkerNG::Code::Ruby.new
code.merge_worker "#{Rails.root}/app/workers/test_iron.rb"
# ...and upload it to iron.io cloud
client = IronWorkerNG::Client.new(Settings.iron_worker.token, Settings.iron_worker.project_id)
client.codes.create(code)
# :host, :port, :ssl, :payload, :url, :token, :username
client.tasks.create('TestIron', 'foo' => 42)
# encoding: UTF-8
class String
def to_iso
Iconv.conv('ISO-8859-1', 'utf-8', self)
end
end
@mcansky
mcansky / gist:1320000
Created October 27, 2011 16:07
post with a file upload
@request.env["CONTENT_TYPE"] = "multipart/form-data;"
image = Rack::Test::UploadedFile.new("#{Rails.root}/tmp/issue.jpg")
post :create, :image => image