Skip to content

Instantly share code, notes, and snippets.

🐢
I may be slow to respond.

MICE Portal stereosupersonic

🐢
I may be slow to respond.
Block or report user

Report or block stereosupersonic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View show_constants.rb
Module.constants.select do |constant_name|
constant = eval constant_name
if not constant.nil?
puts "#{constant_name} : #{constant}"
end
end
View gist:119540
def self.timeout_guard(sec)
main = Thread.current
timer = Thread.new { sleep sec; main.raise "Timeout after #{sec} seconds" }
begin
yield
ensure
timer.kill
end
end
# use timeout_guard(10) {do_somthing }
View logger.rb
def logger
@logger ||= Logger.new(STDOUT, Logger::WARN)
end
#siehe http://blog.hasmanythrough.com/2009/12/15/no-returns
def logger
RAILS_DEFAULT_LOGGER
end
View my_template.rb
#template
#Constants
app_name = `pwd`.split('/').last.strip
rails_version = '2.3.2'
jquery_version = '1.3.2'
##### remove files #################
run "rm README"
run "rm -rf test"
View time_logging_block.rb
def self.in_time_log(name="",logger=nil)
(logger || RAILS_DEFAULT_LOGGER).info("#{name} start")
start_time = Time.now
yield
duration = Time.now-start_time
(logger || RAILS_DEFAULT_LOGGER).info("#{name} duration: #{ ([duration/3600, duration/60 % 60, duration % 60].map{|t| "%02d" % t.to_i.to_s}).join(':')}")
end
View checksum.rb
require 'digest/md5'
Digest::MD5.hexdigest('http://foo-bar.com/yay/?foo=bar&a=22')
# "43facc5eb5ce09fd41a6b55dba3fe2fe"
#http://stackoverflow.com/questions/67890/whats-the-best-way-to-hash-a-url-in-ruby
View progress.rb
require "rubygems"
require "progressbar"
pbar = ProgressBar.new("Update Offer",big_array.size)
big_array.each do | e |
do_something
pbar.inc
end
###################### oder mit progress-monitor http://github.com/mikisvaz/progress-monitor
View install gemcutter
sudo gem update --system
sudo gem install gemcutter --source http://gemcutter.org
sudo gem tumble
View validation_errors_to_log.rb
RAILS_DEFAULT_LOGGER.error {my_object.errors.full_messages.to_s}
View env.rb
Rails.env.staging?
Rails.env => "development"
You can’t perform that action at this time.