Skip to content

Instantly share code, notes, and snippets.

View benoittgt's full-sized avatar
🏳️‍🌈

Benoit Tigeot benoittgt

🏳️‍🌈
View GitHub Profile
class Comparison
@@window = 64
@@prelude = 12
def self.window
@@window
end
def self.window=(val)
@@window = val
@lenary
lenary / _README.md
Created January 25, 2011 14:58
assorted RSpec 2 formatters

Two formatters i made, just for fun, both heavily based of the specdoc format.

The dragon_formatter.rb just says "HERE BE DRAGONS" after pending tests, and tells you the count in the summary.

the boss_formatter.rb just adds "LIKE A BOSS!" after passing tests, and when it says how long it took.

@chrisjpowers
chrisjpowers / wacky_undef.rb
Created May 24, 2011 14:16
Ruby undef vs. remove_method
class A
def hello
"hello from A"
end
end
class B
def hello
"hello from B"
end
@wtaysom
wtaysom / where_is.rb
Created September 23, 2011 08:57
A little Ruby module for finding the source location where class and methods are defined.
module Where
class <<self
attr_accessor :editor
def is_proc(proc)
source_location(proc)
end
def is_method(klass, method_name)
source_location(klass.method(method_name))
@l4u
l4u / gist:1551372
Created January 2, 2012 17:01
Flush Heroku Memcache with Dalli
heroku run console
Dalli::Client.new.flush
@hiltmon
hiltmon / development_profiler.rb
Created February 28, 2012 03:55
Simple class to wrap a profile run around some code
class DevelopmentProfiler
def self.prof(file_name)
RubyProf.start
yield
results = RubyProf.stop
# Print a flat profile to text
File.open "#{Rails.root}/tmp/performance/#{file_name}-graph.html", 'w' do |file|
@p-baleine
p-baleine / gist:2958913
Created June 20, 2012 08:58
mongoDB, MapReduce with calendar
## coding: utf-8
# Demo mongoDB mapreduce with callendar
require 'date'
require 'mongo'
require 'securerandom'
require 'pp'
# Create calendar collection with random string name,
@shunchu
shunchu / convert-seconds-into-hh-mm-ss-in-ruby.rb
Created July 25, 2012 07:58
Convert seconds into HH:MM:SS in Ruby
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active June 19, 2024 21:11
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@JoshCheek
JoshCheek / gc_test.rb
Created September 19, 2012 05:20
Ruby gc not collecting array
THE_STRING = 'a random 369-characterish string'
def self.find_array
ObjectSpace.each_object Array do |array|
return array if array.any? && array.all? { |s| s == THE_STRING }
end
nil
end
def self.print_whether_array_exists