Skip to content

Instantly share code, notes, and snippets.

@boy-jer
boy-jer / email.rb
Created May 24, 2012 14:12 — forked from ahawkins/email.rb
class Email
class Email < Message
attr_accessor :to, :cc, :bcc
validates :to, :presence => true, :on => :create
validates :to, :cc, :bcc, :emails => true
normalize_attribute :subject, :message
attr_accessible :to, :cc, :bcc, :subject, :message
@boy-jer
boy-jer / billing_musings.rb
Created May 24, 2012 14:12 — forked from ahawkins/billing_musings.rb
Tiered SaaS plans w/per use individual service billings. These are just musings,
class FreemiumPlan
include Billing::Plan
def cost
0
end
def number_of_users
5
end
@boy-jer
boy-jer / wormhole_backend.js
Created June 5, 2012 12:00 — forked from maffoo/wormhole_backend.js
wormhole - simple cross-domain ajax with a convenient interface
// backend
$(document).ready(function() {
// the server sets parentUrl in the page it serves, based on the http-referer
var windowProxy = new Porthole.WindowProxy(window.parentUrl + "/proxy.html");
function send(data) {
windowProxy.postMessage(JSON.stringify(data));
}
windowProxy.addEventListener(function(event) {
@boy-jer
boy-jer / Gemfile
Created October 11, 2015 19:28 — forked from mchail/Gemfile
Zapier Webhooks in Rails with Resque
gem "resque", :require => 'resque/server'
gem 'resque-history'
@boy-jer
boy-jer / url_regex.rb
Last active October 24, 2015 09:47 — forked from ryana/url_regex.rb
@gruber's improved regex for matching URLs written in Ruby
# From @gruber http://daringfireball.net/2010/07/improved_regex_for_matching_urls
#http://ryanangilly.com/post/8654404046/grubers-improved-regex-for-matching-urls-written
UrlRegex = /\b((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/?)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s\`!()\[\]{};:\'\".,<>?«»“”‘’]))/i
// Correction to this article: http://kresimirbojcic.com/2011/11/19/dependency-injection-in-ruby.html
class TaxCode
GENERATORS = {
:us => lambda { |id| "US-#{id}" },
:br => lambda { |id| "#{id + 9}-BRA" },
}
def self.generate(code, id)
gen = GENERATORS[code] || raise ArgumentError, "No generator for country #{code}"
gen.call(id)
require 'minitest/autorun'
class TaxCodeBase
class AbstractMethod < StandardError
end
attr_accessor :user_id
def initialize(user_id=nil)
self.user_id = user_id
@boy-jer
boy-jer / gist:4555031
Created January 17, 2013 10:08 — forked from bradleypriest/gist:3494093
Using plupload with emberjs
App.Forms.ImageUploader = Ember.View.extend
classNames: ['ember-image-uploader']
controller: null
didInsertElement: ->
controller = @get('controller')
if controller.get('imageUploadUrl')
@initUploader()
else
@get('controller').addObserver 'imageUploadUrl', =>
if @get('controller.imageUploadUrl')
App.AccountEditRoute = Ember.Route.extend({
setupController: function(controller) {
controller.set('content', this.get('currentUser'));
}
});
Adapted from Tchak's code here https://gist.github.com/4511824
//Passing a function instead of route name will setup an anonymous route and assign the function as `redirect` hook.
//Passing object instead of route name can be used to redirect for example.
App.Router.map(function {
this.resource('index', { path: '/'}, function() {
if (this.controllerFor('login').get('isSignedIn')) {
this.transitionTo('search');
} else {
this.transitionTo('signIn');