Skip to content

Instantly share code, notes, and snippets.

module AsyncSupport
def eventually(timeout = 10)
polling_interval = 0.1
time_limit = Time.now + timeout
loop do
begin
yield
rescue Exception => error
end
return if error.nil?
@otzy007
otzy007 / time_dimension_month
Last active March 16, 2017 16:09 — forked from bryhal/gist:4129042
MYSQL: Generate Calendar Table
DROP TABLE IF EXISTS time_dimension;
CREATE TABLE time_dimension (
id INTEGER PRIMARY KEY, -- year*10000+month*100+day
db_date DATE NOT NULL,
year INTEGER NOT NULL,
month INTEGER NOT NULL, -- 1 to 12
day INTEGER NOT NULL, -- 1 to 31
quarter INTEGER NOT NULL, -- 1 to 4
week INTEGER NOT NULL, -- 1 to 52/53
day_name VARCHAR(9) NOT NULL, -- 'Monday', 'Tuesday'...
@otzy007
otzy007 / memory_leaks_check.rb
Created December 23, 2015 11:41
memory leaks check
pid = Process.pid
rss = `ps -eo pid,rss | grep #{pid} | awk '{print $2}'`.to_i
puts "MEMORY[#{pid}]: rss: #{rss}, live objects #{GC.stat[:heap_live_slots]}"
@otzy007
otzy007 / merge_similar_errbit_problems.rb
Last active December 23, 2015 11:42
Merge errbit similar problems
def merge(id, message)
main_p = Problem.find(id)
Problem.where(message: /^#{message}/).each {|p| ProblemMerge.new(main_p, p).merge unless p == main_p}
end
org.jruby.rack.RackInitializationException: undefined method `raw_date_time?' for ActiveRecord::ConnectionAdapters::JdbcConnection:Class
from /usr/share/apache-tomcat-7.0.34/webapps/ROOT/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.3.6/lib/arjdbc/jdbc/adapter.rb:862:in `JdbcAdapter'
from /usr/share/apache-tomcat-7.0.34/webapps/ROOT/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.3.6/lib/arjdbc/jdbc/adapter.rb:35:in `ConnectionAdapters'
from /usr/share/apache-tomcat-7.0.34/webapps/ROOT/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.3.6/lib/arjdbc/jdbc/adapter.rb:17:in `ActiveRecord'
from /usr/share/apache-tomcat-7.0.34/webapps/ROOT/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.3.6/lib/arjdbc/jdbc/adapter.rb:16:in `(root)'
from org/jruby/RubyKernel.java:1027:in `require'
from /usr/share/apache-tomcat-7.0.34/webapps/ROOT/WEB-INF/gems/gems/activerecord-jdbc-adapter-1.3.6/lib/arjdbc/jdbc.rb:1:in `(root)'
from org/jruby/RubyKernel.java:1027:in `require'
from /usr/share/apache-tomcat-7.0.34/webapps/ROOT/WEB-IN
@otzy007
otzy007 / api_steps.rb
Created September 7, 2013 07:07
api_steps
Given /^I send and accept JSON$/ do
header 'Accept', 'application/json'
header 'Content-Type', 'application/json'
end
Given /the following API Keys exist/ do | keys |
keys.hashes.each do | k |
ApiKey.create! k
end
end
@otzy007
otzy007 / gist:2758273
Created May 20, 2012 14:14
link to other git repo
git submodule add git://github.com/defunkt/my-fantastic-plugin.git plugins/my-fantastic-plugin