This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FreemiumPlan | |
include Billing::Plan | |
def cost | |
0 | |
end | |
def number_of_users | |
5 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
class TaxCodeBase | |
class AbstractMethod < StandardError | |
end | |
attr_accessor :user_id | |
def initialize(user_id=nil) | |
self.user_id = user_id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.AccountEditRoute = Ember.Route.extend({ | |
setupController: function(controller) { | |
controller.set('content', this.get('currentUser')); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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+'[email protected]', function() { | |
return this.get('_'+name+'Filter') | |
})); |