Skip to content

Instantly share code, notes, and snippets.

View rosenfeld's full-sized avatar

Rodrigo Rosenfeld Rosas rosenfeld

View GitHub Profile
@rosenfeld
rosenfeld / output.txt
Last active December 31, 2015 22:59
Isn't MRI 2.0 behaving wrongly here?
MRI 2.0.0p353:
$ ruby test.rb
1
1
102
102
JRuby 1.7.9:
$ ruby test.rb
19
@rosenfeld
rosenfeld / benchmark.rb
Created August 23, 2013 12:34
factories overhead over fixtures
require 'sequel'
require 'benchmark'
# createdb factories_test
DB = Sequel.connect 'postgres://localhost/factories_test'
DB.drop_table? :test
DB.create_table :test do
primary_key :id
@rosenfeld
rosenfeld / LICENSE
Last active December 20, 2015 18:49 — forked from myronmarston/LICENSE
Backup for RSpec Around All gem
(The MIT License)
Copyright (c) 2012-2013 Myron Marston
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
@rosenfeld
rosenfeld / group_helpers.rb
Created August 5, 2013 12:44
RSpec run_all_in_transaction helper for running before(:all) blocks under a transaction with Sequel
# support/group_helpers.rb
module GroupHelpers
def self.start_transaction
# @_conn = DB.pool.send :acquire, Thread.current
@_conn = DB.pool.hold{|conn| conn }
DB.send(:add_transaction, @_conn, {savepoint: true})
DB.send(:begin_transaction, @_conn, savepoint: true)
end
@rosenfeld
rosenfeld / bookmarks
Last active December 20, 2015 06:09
bookmarks
http://rubysource.com/streaming-with-rails-4/
http://www.highcharts.com/
https://bitbucket.org/cleonello/jqplot/wiki/Home
http://www.dreamfactory.com/
http://coding.smashingmagazine.com/2013/08/09/absolute-horizontal-vertical-centering-css/
http://tech.pro/blog/1486/client-side-storage-options
https://www.globalsign.com/ssl/ssl-open-source/
http://nowardev.wordpress.com/2012/05/16/create-debian-package-for-script-and-simple-project-with-cmake-and-cpack/
http://shvets.github.io/blog/2013/09/14/nodejs_and_karma.html
@rosenfeld
rosenfeld / bm.rb
Last active December 12, 2015 06:58
trade-offs between hashes and HashWithIndifferentAccess
require 'benchmark'
require 'active_support/hash_with_indifferent_access'
Benchmark.bmbm do |x|
l1 = []; l2 = []
# writing:
# simulate objects returned by Sequel queries:
x.report('creating array or regular hashes'){10_000.times{ l1 << { id: 1, name: 'column value' } }}
x.report('creating array or proposed hashes'){10_000.times{ l2 << HashWithIndifferentAccess.new({ id: 1, name: 'column value' }) }}
@rosenfeld
rosenfeld / report.txt
Created February 6, 2013 14:56
Performance comparison: strings vs symbols in Ruby
ruby symbols-performance.rb
Rehearsal ------------------------------------
0.540000 0.010000 0.550000 ( 0.543421)
0.680000 0.020000 0.700000 ( 0.705931)
--------------------------- total: 1.250000sec
user system total real
0.240000 0.000000 0.240000 ( 0.244554)
0.380000 0.000000 0.380000 ( 0.391517)
@rosenfeld
rosenfeld / user.rb
Created October 15, 2012 21:16
User class example for Sequel and Devise
class User < Sequel::Model(:jsec_user)
plugin :devise
# other available modules:
# :token_authenticatable, :registerable, :confirmable, :lockable, :timeoutable and :omniauthable
# :recoverable, :rememberable, :trackable, :validatable, :encryptable
devise :database_authenticatable, :timeoutable #, etc
end
@rosenfeld
rosenfeld / pagination.sql
Created September 28, 2012 18:18
Pagination example with PostgreSQL
select username, count(*) over() from user order by username limit 5 offset 0;
@rosenfeld
rosenfeld / parseParams.coffee
Created August 7, 2012 19:06
Parse query params in CoffeeScript
# for simple use case - doesn't take into account multiple occurrences
parseParams = (search = window.location.search)->
d = (str)-> decodeURIComponent str.replace /\+/g, ' '
query = search.substring 1
regex = /(.*?)=([^\&]*)&?/g
params = {}
params[d(m[1])] = d(m[2]) while m = regex.exec query
params