Skip to content

Instantly share code, notes, and snippets.

View davetron5000's full-sized avatar

David Copeland davetron5000

View GitHub Profile
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// This uses $scope to expose stuff to the view. This was just what I learned
// reading Angular's docs. So it's somewhat "official", but
// the downside is that I have to explain wtf $scope is.
app.config([
"$routeProvider",
function($routeProvider) {
$routeProvider.when("/", {
controller: "CustomerSearchController",
templateUrl: "customer_search.html"
});
+-----------+
| customers |---------------------------------+
+-----------+ |
| |
| |
v v
+-----------------------------+ +------------------------------+
| customers_billing_addresses | | customers_shipping_addresses |
+-----------------------------+ | ---- |
| | primary: boolean |
service = MyService.new
service.doit("foo").on_done do |result|
# this is the happy path--doit did whatever it was supposed to
end.on_still_in_progress do
# this could be an alternate path, e.g. the request is still in progress
end.on_error do |exception|
# This could be the error path, where you get an exception passed
end

Suppose I have a bunch of CoffeeScript files:

> ls src
foo.coffee    bar.coffee    baz.coffee

I want to produce the following for deploying:

  • a concatenated, gzip'ed, hashed file suitable for serving up in production

Rails routes:

root 'home#index'

app/views/home/index.html.erb:

@davetron5000
davetron5000 / custom.rb
Created September 7, 2014 21:39
Custom Control Structure
# instead of designing a class to return a result object that we
# must interrogate, we could design our class to have a custom
# control structure to make it easy to see the alternatives
# that must be handled
PaymentProcessor.new.charge_money(credit_card,amount).on_success do |transaction_id|
# happy path
end.on_expired_card do
# special message to get them to update their card
end.on_decline do |decline_message|
# general decline
$ curl -H "Access-Control-Request-Method: GET" -H "Access-Control-Request-Headers: X-Requested-With" -X OPTIONS -H "Origin: https://theboomcase.goodsie.com" --verbose https://d1bn1ndebsjcoa.cloudfront.net/8a6779f/styles/css/combined-store-goodsie.css
* Adding handle: conn: 0x7fae2a004000
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fae2a004000) send_pipe: 1, recv_pipe: 0
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* About to connect() to d1bn1ndebsjcoa.cloudfront.net port 443 (#0)
* Trying 54.239.152.56...
describe Person do
subject(:person) { Person.new(age: age) }
describe "minor?" do
context "over 18" do
let(:age) { 20 }
it { person.minor?.should == false }
end
context "under 18" do
let(:age) { 16 }
it { person.minor?.should == true }
#!/usr/bin/env ruby
require 'methadone'
include Methadone::Main
include Methadone::CLILogging
main do |gem_name|
# ..