GET /trucks HTTP/1.1
Host: api.example.com
Authorization: Basic username:password
Accept: application/hal+json
These examples are type 3 RESTful API requests and responses. The JSON-HAL specification is used to implement HATEOAS.
Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.
- JSON-HAL specification: http://stateless.co/hal_specification.html#media_type_identifiers
- JSON linking with HAL: http://blog.stateless.co/post/13296666138/json-linking-with-hal
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
# MOTIVATION: As rails apps are growing, people are noticing the drawbacks | |
# of the ActiveRecord pattern. Several apps I have seen, and several | |
# developers I have spoken to are looking towards other patterns for object | |
# persistence. The major drawback with ActiveRecord is that the notion | |
# of the domain object is conflated with what it means to store/retrieve | |
# it in any given format (like sql, json, key/value, etc). | |
# | |
# This is an attempt to codify the Repository pattern in a way that would | |
# feel comfortable to beginner and seasoned Ruby developers alike. | |
# |
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 Cirle < Form | |
attr_reader :rayon | |
def initializer(rayon) | |
@rayon = rayon | |
end | |
#Circle.area(20) => 200 | |
def self.area(rayon) | |
Math.Pi * rayon**2 |
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
#!/bin/bash | |
# Checks the files to be committed for the presence of binding.pry | |
# The array below can be extended for further checks | |
checks[1]="binding.pry" | |
element_count=${#checks[@]} | |
let "element_count = $element_count + 1" | |
ROOT_DIR="$(pwd)/" |
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
autocmd FocusGained * call s:CmdTFlush() | |
autocmd BufWritePost * call s:CmdTFlush() | |
function s:CmdTFlush(...) | |
if exists(":CommandTFlush") == 2 | |
CommandTFlus | |
endif | |
endfunction | |
set incsearch |
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
module Extensions | |
module ActiveRecord | |
module BuildForHasOne | |
module InstanceMethods | |
def self.included(base) | |
base.send :alias_method_chain, :method_missing, :build | |
end | |
private | |
def method_missing_with_build(method, *args, &block) | |
relation_name = method.to_s.scan(/(\w+)_or_build$/).flatten.first |
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
module Holidays | |
module DateComputation | |
def holiday?(iso='fr') | |
require_or_load "holidays/#{iso}/computation" | |
holidays = Holidays::const_get(iso.camelize)::Settings.holidays[iso].merge(Holidays::Config::Settings.holidays) | |
holidays.each do |name, settings| | |
holiday_period = Date.from_settings(name, holidays, iso) | |
today_is_holiday = holiday_period.is_a?(Range) ? holiday_period.include?(self) : holiday_period == self | |
return true if today_is_holiday | |
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
# Author: Diego d'Ursel | |
# --------------------- | |
# | |
# This simple lib help you to add state to a model without implementing boring functions for each state | |
# just add macro like "add_state 1, 'mystate'" to the definition of your ActiveRecord model | |
# this lib require a "state" field in the model | |
# | |
# some example of usage: | |
# --------------------- | |
# add_state 0, 'inactive' |
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
Axlsx::Worksheet.class_eval do | |
def add_row_with_position(values = [], options = {}) | |
if options.try(:[], :start_at).present? | |
val = [] | |
options[:start_at].times { val.push nil} | |
options.delete(:start_at) | |
values = val + values | |
end | |
add_row_without_position(values, options) | |
end |