Skip to content

Instantly share code, notes, and snippets.

View gregory's full-sized avatar
🎯
Focusing

Grégory Horion gregory

🎯
Focusing
View GitHub Profile
= f.inputs :name => :code_promo, :class => 'inputs foldable' do
= f.input :validity_start, :as => :datetime, :include_blank => false
= f.input :validity_end,:as => :datetime, :include_blank => false
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
@gregory
gregory / stateable.rb
Created June 26, 2012 16:14 — forked from diegodurs/stateable.rb
Ruby stateable lib for ActiveRecord class
# 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'
@gregory
gregory / date_computation.rb
Created July 5, 2012 13:15
Date computation for holidays
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
@gregory
gregory / build_for_has_one
Created November 17, 2012 00:30
fields_for :profile_or_build
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
@gregory
gregory / .vimrc.after
Created November 29, 2012 03:26
vimrc.after across all computers
autocmd FocusGained * call s:CmdTFlush()
autocmd BufWritePost * call s:CmdTFlush()
function s:CmdTFlush(...)
if exists(":CommandTFlush") == 2
CommandTFlus
endif
endfunction
set incsearch
@gregory
gregory / pre-commit
Created December 17, 2012 18:50
this is the hack from @Saicheg to remove all the dirty binding.pry before committing.
#!/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)/"
@gregory
gregory / circle.rb
Last active December 16, 2015 06:28
jsut simpel example for POO
class Cirle < Form
attr_reader :rayon
def initializer(rayon)
@rayon = rayon
end
#Circle.area(20) => 200
def self.area(rayon)
Math.Pi * rayon**2
# 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.
#

Examples of RESTful API calls for E-commerce platforms

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.

Relevant links