Skip to content

Instantly share code, notes, and snippets.

View funny-falcon's full-sized avatar

Sokolov Yura funny-falcon

View GitHub Profile
class ActiveRecord::Associations::AssociationCollection
def has_finder_sql_with_select?
@finder_sql =~ /^\s*select\s/i
end
def find(*args)
options = args.extract_options!
# If using a custom finder_sql, scan the entire collection.
if has_finder_sql_with_select?
@funny-falcon
funny-falcon / dump.sh
Created October 20, 2010 13:27
dumps remote database
DB_NAME=local_database
FILE_NAME=dump.sql
REMOTE_DB_NAME=remote_database
REMOTE_HOST=user@host.com
REMOTE_DBUSER=postgres
cat <<EOF > $FILE_NAME
\c postgres
DROP DATABASE $DB_NAME ;
CREATE DATABASE $DB_NAME ;
@funny-falcon
funny-falcon / rbx-1.2.1dev.run-1.webrick.log
Created December 22, 2010 21:19
simple testing sinatra application
BENCH http://localhost:9294/h
** SIEGE 2.69
** Preparing 15 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 1945 hits
Availability: 100.00 %
Elapsed time: 19.99 secs
Data transferred: 0.01 MB
@funny-falcon
funny-falcon / config.ru
Created March 2, 2011 18:51
testing sinatra application with results for REE 2010.2 and 1.9.2
require File.dirname(__FILE__) + '/sin.rb'
run Sinatra::Application
@funny-falcon
funny-falcon / patch-1.9.2-gc.patch
Created March 5, 2011 11:11
GC tunning simple patch ruby 1.9.2 p180
diff --git a/gc.c b/gc.c
--- a/gc.c
+++ b/gc.c
@@ -77,6 +77,41 @@ void *alloca ();
#ifndef GC_MALLOC_LIMIT
#define GC_MALLOC_LIMIT 8000000
#endif
+#define HEAP_MIN_SLOTS 10000
+#define FREE_MIN 4096
+
@funny-falcon
funny-falcon / gist:870609
Created March 15, 2011 11:24
Monkey patch for speedup date/time parsing
class Date
module Format
class Bag
A_FIELDS = %w{year mon mday hour min sec sec_fraction offset zone wday}
for fld in A_FIELDS + %w{_comp}
attr_accessor fld.to_sym
end
to_hash = A_FIELDS.map{|fld| "res[:#{fld}] = @#{fld} unless @#{fld}.nil?"}.join("\n")
class_eval <<-"END"
@funny-falcon
funny-falcon / sequel_time_parse.rb
Created March 15, 2011 22:19
speedup sequel datetime parse
~/tmp/ruby-sequel$ ruby test_sequel_times.rb
user system total real
base 6.870000 0.200000 7.070000 ( 7.534538)
~/tmp/ruby-sequel$ ruby test_sequel_times.rb home_run
user system total real
home_run 5.350000 0.160000 5.510000 ( 5.856684)
~/tmp/ruby-sequel$ ruby test_sequel_times.rb fix
user system total real
fix 2.490000 0.150000 2.640000 ( 2.807951)
@funny-falcon
funny-falcon / fast_time_parse.rb
Created March 17, 2011 08:25
Fast parsing of db timestamp (useful for postgresql and sqlite3 adapters with sequel )
class Time
class << self
def relaxed_rfc3339(date)
if /\A\s*
(-?\d+)-(\d\d)-(\d\d)
[T ]
(\d\d):(\d\d):(\d\d)
(?:\.(\d+))?
(Z|[+-]\d\d(?::?\d\d)?)?
\s*\z/ix =~ date
@funny-falcon
funny-falcon / load.c.patch
Created October 8, 2011 22:30
Patch against ruby-1.9.3-p0 to futher improve load.c
diff --git a/load.c b/load.c
index 0ff4b60..019ccb9 100644
--- a/load.c
+++ b/load.c
@@ -18,6 +18,7 @@ VALUE ruby_dln_librefs;
#define IS_DLEXT(e) (strcmp((e), DLEXT) == 0)
#endif
+static int sorted_loaded_features = 1;
@funny-falcon
funny-falcon / mandelbrot.rb
Created October 18, 2011 11:39
mandelbrot rubinius
# The Computer Language Benchmarks Game
# http://shootout.alioth.debian.org/
#
# contributed by Karl von Laudermann
# modified by Jeremy Echols
# modified by Detlef Reichl
# modified by Joseph LaFata
# modified by Peter Zotov
# modified by Brian Ford
# modified by Yura Sokolov