Skip to content

Instantly share code, notes, and snippets.

@citrus
citrus / permalink_fix.rb
Created August 31, 2017 17:18
Jekyll permalink fix for pages without trailing slash
@citrus
citrus / proxy_test.rb
Created August 30, 2016 23:37
Ruby proxy pattern
class ProxyTest
attr_accessor :scope
class ScopeProxy
def initialize(obj, scope)
@obj = obj
@scope = scope
end
TO_TSVECTOR(ARRAY_TO_STRING(holder_names)) ||
SELECT *,
TO_TSVECTOR(holder_names) ||
TO_TSVECTOR(first_name) ||
TO_TSVECTOR(last_name) ||
TO_TSVECTOR(email) ||
TO_TSVECTOR(COALESCE(order_token, '')) AS attendee
FROM (
SELECT
users.id,
users.first_name,
@citrus
citrus / circle.yml
Created March 8, 2016 03:22
circle.yml for building ember app with Circle CI
machine:
node:
version: 0.12.0
dependencies:
pre:
- export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH
- npm config set spin false
- npm install -g npm@^2
- npm install -g bower
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define('progressbar', [], function() {
return factory();
});
} else {
// Browser globals
root.ProgressBar = factory();
}
@citrus
citrus / twilio_helper.rb
Created September 9, 2014 22:13
RSpec helper for testing Twilio sms deliveries
module TwilioHelper
module TwilioMocker
def deliveries
@deliveries ||= []
end
def create(options)
deliveries << options
@citrus
citrus / blog.rb
Created June 17, 2014 04:51
Ruby wordpress API connector - For use with WP-API
require 'uri'
require 'net/http'
class Blog
class Connection
def request(url, &block)
req = Net::HTTP::Get.new(url)
req.basic_auth(ENV['blog_user'], ENV['blog_password']) if ENV['blog_user']
@citrus
citrus / ui_color.rb
Created August 7, 2013 17:19
A utility to convert a hex color to a UIColor in RubyMotion
#!/usr/bin/env ruby
require "bigdecimal"
def to_percent(c)
(c / BigDecimal.new("255.0")).round(3).to_f
end
color = ARGV.shift.to_s.strip.sub("#", "")
@citrus
citrus / gist:4759619
Created February 12, 2013 02:18
Time Hacks
module TimeHacks
class << Time
def now
Time.new + offset
end
def offset
@offset ||= 0