Skip to content

Instantly share code, notes, and snippets.

{
"_links": {
"self": { "href": "/orders" },
"next": { "href": "/orders?page=2" },
"find": { "href": "/orders{?id}", "templated": true }
},
"_embedded": {
"orders": [{
"_links": {
"self": { "href": "/orders/123" },
class TaskCompletion
include ActiveModel::Model
attr_accessor :task, :complete
validates :complete, inclusion: { in: [true, false] }
def self.for_task(task, params={})
new(params).tap do |completion|
completion.task = task
end
# ------------------------------------------------------------------
# Desigining "trending topics in 24 hours sliding window" with Redis
# ------------------------------------------------------------------
redis-cli del tophashes:2010-12-07-08-00
redis-cli del tophashes:2010-12-07-09-00
redis-cli del tophashes:current
echo '=== 8:00 AM ==='
@harlow
harlow / booking_payments_controller.rb
Last active December 15, 2015 17:09 — forked from jordelver/booking_payment_controller.rb
Use ActiveModel::Model for validations on non-AR objects
class BookingPaymentsController < ApplicationController
def create
booking_payment = BookingPayment.new(booking_payment_params)
booking_payment.pay
respond_with payment, location: balance_trip_path
end
private
@harlow
harlow / chat.rb
Created March 16, 2013 20:17 — forked from rkh/chat.rb
# coding: utf-8
require 'sinatra'
set server: 'thin', connections: []
get '/' do
halt erb(:login) unless params[:user]
erb :chat, locals: { user: params[:user].gsub(/\W/, '') }
end
get '/stream', provides: 'text/event-stream' do
@harlow
harlow / rules.md
Created January 28, 2013 19:43 — forked from henrik/rules.md
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done.

You can break these rules if you can talk your pair into agreeing with you.