Skip to content

Instantly share code, notes, and snippets.

View rthbound's full-sized avatar

Ryan T. Hosford rthbound

View GitHub Profile
@rthbound
rthbound / README.md
Created December 27, 2016 21:36 — forked from thbar/README.md
A quick benchmark for ice_cube

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)

@rthbound
rthbound / 9_to_5.rb
Created December 27, 2016 21:36 — forked from seejohnrun/9_to_5.rb
ice_cube 9-5
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
@rthbound
rthbound / html_flip_flop.rb
Created September 3, 2015 21:18 — forked from baweaver/html_flip_flop.rb
Abusing flip flops for HTML parsing after watching a ruby tapa ala Avdi.
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
#
@rthbound
rthbound / dynamic_stylesheet.rb
Last active August 29, 2015 09:03 — forked from mattsmith/dynamic_stylesheet.rb
Renders a scss stylesheet with erb using Tilt templates.
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]
@rthbound
rthbound / skip.rb
Last active August 29, 2015 14:24 — forked from adampats/skip.rb
@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