Skip to content

Instantly share code, notes, and snippets.

View kpumuk's full-sized avatar

Dmytro Shteflyuk kpumuk

View GitHub Profile
@kpumuk
kpumuk / rails22.patch
Created June 14, 2011 16:59
Profile Rails 2.2 startup
diff --git a/vendor/rails/railties/lib/initializer.rb b/vendor/rails/railties/lib/initializer.rb
index 16abe62..cb7a811 100644
--- a/vendor/rails/railties/lib/initializer.rb
+++ b/vendor/rails/railties/lib/initializer.rb
@@ -10,11 +10,13 @@ require 'rails/plugin/loader'
require 'rails/gem_dependency'
require 'rails/rack'
+require 'rails_startup_timer'
@kpumuk
kpumuk / mysql_adapter_extensions.rb
Created April 15, 2011 17:24
Trace SQL queries in Rails 2
module OpsApi
# Helper methods for `ActiveRecord::ConnectionAdapters::MysqlAdapter` to enable SQL queries
# tracing functionality. There are two goals:
#
# * Add source line into the query itself so it would be possible to understand where
# the query was issues from:
#
# SELECT * FROM `admins` WHERE
# ((`admins`.`user_id` = 1)) LIMIT 1
# /*OOPS:app/models/user.rb:72:in `admin?'*/
diff --git a/src/ngx_http_lua_hook.c b/src/ngx_http_lua_hook.c
index b36d751..2d8a017 100644
--- a/src/ngx_http_lua_hook.c
+++ b/src/ngx_http_lua_hook.c
@@ -1671,6 +1671,37 @@ ngx_http_lua_ngx_time(lua_State *L)
int
+ngx_http_lua_ngx_response_time(lua_State *L)
+{
@kpumuk
kpumuk / date_time_marshal.rb
Created February 11, 2011 05:56
Marshal.dump and different date/time classes in Ruby
Marshal.dump Date.today
# "\004\bu:\tDate=\004\b[\bo:\rRational\a:\021@denominatori\a:\017@numeratori\003g?Jii\003\031\025#"
Marshal.dump Time.now
# "\004\bIu:\tTime\re?200\247?U?:\037@marshal_with_utc_coercionF"
Marshal.dump DateTime.now
# "\004\bu:\rDateTimeT\004\b[\bo:\rRational\a:\021@denominatorl+\b\000 \235\264\006\000:\017@numeratorl+\t\227՗A\272@?o;\a;\006i\035;\ai?i\025#"
@kpumuk
kpumuk / zlib.patch
Created February 7, 2011 21:33
Patch for Ruby to fix "tar_input.rb:49:in `initialize': not in gzip format (Zlib::GzipFile::Error)" exception
diff -crB a/source/ext/zlib/zlib.c b/source/ext/zlib/zlib.c
*** a/source/ext/zlib/zlib.c 2010-06-03 09:01:09.000000000 +0000
--- b/source/ext/zlib/zlib.c 2011-02-07 21:21:05.000000000 +0000
***************
*** 610,615 ****
--- 610,616 ----
}
#define zstream_append_input2(z,v)\
+ RB_GC_GUARD(v),\
@kpumuk
kpumuk / super_logger.rb
Created February 3, 2011 23:55
Awesome Ruby feature. Do not use it in real projects!
require 'logger'
class SuperLogger
include Logger::Severity
attr_accessor :level
def initialize(level = INFO)
@level = level || INFO
end
@kpumuk
kpumuk / plurk.css
Created January 25, 2011 17:47
Plurk custom CSS
a.front {position:absolute;top:-1000px}
div.plurk_cnt div.manager span {position:absolute;top:-1000px}
img.emoticon[alt="(fuu)"],
img.emoticon[alt="(troll)"],
img.emoticon[alt="(yay)"],
img.emoticon[alt="(gfuu)"],
img.emoticon[alt="(bah)"],
img.emoticon[alt="(gtroll)"],
img.emoticon[alt="(gyea)"],
#!/bin/bash
PASTEL='{
"Ansi 0 Color" = {
"Blue Component" = 0.3097887;
"Green Component" = 0.3097887;
"Red Component" = 0.3097887;
};
"Ansi 1 Color" = {
"Blue Component" = 0.3764706;
(n=(c=IRB.conf)[:PROMPT][:NULL]).map{|k,v|n[k]=v.to_s};c[:MAIN_CONTEXT].prompt_mode=c[:AUTO_INDENT]=:NULL;class IRB::InputMethod;def prompt=(p);@prompt=p.gsub(/^(\s*)/){'8=='+'='*$1.size}+'D ';end;end
begin
require 'capistrano/recipes/deploy/strategy/fast_remote_cache'
rescue LoadError
require 'capistrano/recipes/deploy/strategy/remote_cache'
end
module Capistrano
module Deploy
module Strategy
RsyncRemoteCache = Class.new(defined?(FastRemoteCache) ? FastRemoteCache : RemoteCache)