Quick benchmark to see how ice_cube behaves in the far future. It seems that the cost is linearly increasing.
Results at: http://bit.ly/pjsQH1
(note: second version is without the time parse in the loop)
Quick benchmark to see how ice_cube behaves in the far future. It seems that the cost is linearly increasing.
Results at: http://bit.ly/pjsQH1
(note: second version is without the time parse in the loop)
s = IceCube::Schedule.new(Time.now, :duration => 3600 * 7) | |
s.add_recurrence_rule IceCube::Rule.daily.day(:monday, :tuesday, :wednesday, :thursday, :friday).hour_of_day(9) | |
s.occurring_at?(Time.new(2011, 5, 30, 10, 0, 0)) # true, monday at 10am | |
s.occurring_at?(Time.new(2011, 5, 29, 10, 0, 0)) # false, sunday at 10am | |
s.occurring_at?(Time.new(2011, 5, 30, 8, 0, 0)) # false, monday at 8am |
IO.readlines('test.html') | |
.flat_map(&:split) | |
.select { |word| | |
true if word =~ %r{<strong>} .. word =~ %r{</strong>} | |
} | |
# => ["<strong>multiple</strong>","<strong>strong</strong>"] | |
# test.html | |
# |
class DynamicStylesheet | |
# logical_path = 'app/assets/stylesheets/custom.css.scss.erb' | |
def render(logical_path, data={}) | |
path = Rails.root.join(logical_path) | |
context = env.context_class.new(env, logical_path, Pathname.new(path)) | |
# TODO Change to Tilt.templates_for(file) in Tilt 2.x | |
templates = [Tilt::ERBTemplate, Sass::Rails::ScssTemplate] |
@panels = @servicelist.map do |service| | |
if service[:hidden] == "true" | |
nil | |
else | |
{ | |
title: service[:title], | |
panel_name: __method__.to_s, | |
icon: service[:logo], | |
query_string: {}, | |
id: service[:id] |
def getgst | |
d { 'gets fired' } | |
s = Building.get_gst_for_building(params[:buildinginfo]) | |
d { s.to_s('F') } | |
@var = s.to_s('F') | |
respond_to do |format| | |
format.html { render :text => @var } | |
end | |
end |
# SQLite version 3.x | |
# gem install sqlite3 | |
# | |
# Ensure the SQLite 3 gem is defined in your Gemfile | |
# gem 'mysql2' | |
#gem 'pg' | |
development: | |
adapter: postgresql |
# Extend the Array class with a to_h method | |
class Array | |
def to_h | |
Hash[*self] | |
end | |
end | |
# Extend rexml/document to create a Ruby hash from xml | |
class REXML::Document |
bq --query 'SELECT repository_name, count(repository_name) as pushes, repository_description, repository_url | |
FROM [githubarchive:github.timeline] | |
WHERE type="PushEvent" | |
AND repository_language="Ruby" | |
AND PARSE_UTC_USEC(created_at) >= PARSE_UTC_USEC("2012-04-01 00:00:00") | |
GROUP BY repository_name, repository_description, repository_url | |
ORDER BY pushes DESC | |
LIMIT 100' |
class ApplicationController < ActionController::Base | |
before_action :require_login | |
private | |
def check_user | |
if not request.headers["user_id"].empty? | |
define_method(:get_user) { Users.get(id: request.headers["user_id"]) } | |
else | |
#halt this request |