Skip to content

Instantly share code, notes, and snippets.

@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) {
// 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');
#custom initializer, that automagically loads all processors
# initializer is required to load additional preprocessors for carrierwave - Rails will not load them for you.
dir = Rails.root.join('lib', 'carrierwave_processing')
$LOAD_PATH.unshift(dir)
Dir[File.join(dir, "*.rb")].each {|file| require File.basename(file) }
#And that's it - from this moment on your app will be able to convert uploaded video files to "displayable" format.
##I hope that above solution will save you some time.
1.upto(100) do |i|
puts ''.tap {|output|
output << 'Fizz' if i.modulo(3).zero?
output << 'Buzz' if i.modulo(5).zero?
output << i.to_s if output.empty?
}
end
DS.Model.reopenClass({
scope: function(name, fn) {
Ember.defineProperty(this, '_'+name+'Filter', Ember.computed(function() {
return this.filter(fn);
}));
Ember.defineProperty(this, name, Ember.computed('_'+name+'Filter.@each.id', function() {
return this.get('_'+name+'Filter')
}));