Skip to content

Instantly share code, notes, and snippets.

View releu's full-sized avatar
🕶️
I may be slow to respond.

Jan Bernacki releu

🕶️
I may be slow to respond.
View GitHub Profile
@releu
releu / replaceable.rb
Created April 8, 2012 17:59
Replaceable review
class Replaceable
BASE_REGEXP = '(^|\W){1}%s(\b|\.|,|:|;|\?|!|\(|\)|$){1}'
attr_accessor :body
alias to_s body
def initialize(body)
self.body = body
end
@releu
releu / alarm.rb
Created April 2, 2012 19:39
Simple alarm
after = ARGV.join
def say(message)
system "say -v Zarvox #{message}"
end
begin
time = after.to_i
puts "You will be notified after #{time} hours"
sleep time * 60 * 60
@releu
releu / gist:2169237
Created March 23, 2012 10:11 — forked from vadv/gist:1725277
munin resque
#!/usr/bin/env ruby
require 'rubygems'
require 'resque'
require 'resque-cleaner'
HOST = ENV['host'] ||= 'db1.kupikupon.ru'
PORT = ENV['port'] ||= '6379'
Resque.redis = [HOST, PORT].join(':')
@releu
releu / Gemfile
Created March 22, 2012 06:17 — forked from krisleech/README.md
State Validator for ActiveModel
source 'http://rubygems.org'
gem 'activemodel', '>= 3.0.0', :require => 'active_model'
gem 'state_machine', '>= 1.0.0'
gem 'rspec', '~> 2.8.0'
@releu
releu / quiet_assets.rb
Created March 20, 2012 11:23
Quiet assets
# http://stackoverflow.com/questions/6312448/how-to-disable-logging-of-asset-pipeline-sprockets-messages-in-rails-3-1
Rails.application.assets.logger = Logger.new('/dev/null')
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
@releu
releu / gist:2132703
Created March 20, 2012 08:13
printing table #3
<table>
<% @hash.keys.each do |key| %>
<th>key</th>
<% end %>
<% @hash.values.max_by(&:size).size.times do |i| %>
<tr>
<% @group.values.map { |a| a[i] }.each do |value| %>
<td><%= value %></td>
<% end %>
</tr>
@releu
releu / gist:2132697
Created March 20, 2012 08:13
printing table #2
<table>
<tr>
<th>foo</th>
<th>bar</th>
<th>baz</th>
</tr>
<tr>
<td>1</td>
<td>3</td>
<td>5</td>
@releu
releu / gist:2132694
Created March 20, 2012 08:12
printing table #1
@hash = {
:foo => [1, 2],
:bar => [3, 4],
:baz => [5, 6]
}
>> a
=> "Something like this\n\n<div class=\"gistable\" data-gist-at=\"1988392\"></div>\n\n#ruby #fiber"
>> a.split(' ')
=> ["Something", "like", "this", "<div", "class=\"gistable\"", "data-gist-at=\"1988392\"></div>", "#ruby", "#fiber"]
>> a.split(/ /)
=> ["Something", "like", "this\n\n<div", "class=\"gistable\"", "data-gist-at=\"1988392\"></div>\n\n#ruby", "#fiber"]
@releu
releu / fiber.rb
Created March 6, 2012 19:19
test fibers
process = Fiber.new do
i = 0
loop do
puts "process_#{i = i.next}"
sleep 0.1
Fiber.yield
end
end
loop do