Skip to content

Instantly share code, notes, and snippets.

View moiristo's full-sized avatar
💭
Monkey see monkey do

Reinier de Lange moiristo

💭
Monkey see monkey do
View GitHub Profile
def gregorian_date?(date)
return false if date.nil?
(date.month == 2 and date.day == 29) ? Date.gregorian_leap?(date.year) : true
end
@moiristo
moiristo / assert_differences
Created November 11, 2010 13:07
Test helper method to perform multiple assert_difference calls easily.
# Example
assert_differences 'Initiative.count' => 1, 'Role.count' => -1, 'Phase.count' => 0 do
@initiative.to_template!
end
def assert_differences(collection = {}, &block)
yield and return if collection.empty?
collection.shift.tap do |diff|
assert_differences(collection){ assert_difference(diff.first, diff.last, &block) }
@moiristo
moiristo / gist:1245170
Created September 27, 2011 14:27
Rails3 way to redirect non-www domain to www domain
# Rails3 way to redirect non-www domain to www domain
# Single domain redirect
'example.com'.tap do |host|
constraints(:host => host) do
match '/(*path)', :to => redirect { |params, request| Addressable::URI.escape request.url.sub(host, "www.#{host}") }
end
end
Tracking and contributing to the trunk of a Subversion-managed project:
# Clone a repo (like git clone):
git svn clone http://svn.example.com/project/trunk
# Enter the newly cloned directory:
cd trunk
# You should be on master branch, double-check with 'git branch'
git branch
# Do some work and commit locally to git:
git commit ...
@moiristo
moiristo / dj_client.rb
Created May 9, 2014 09:23
A simple ruby script to push jobs from the crontab to Delayed Job (Rails Postgres version)
#!/usr/bin/env ruby
require 'yaml'
require 'pg'
# Usage
if ARGV.size == 0
puts "Usage: script/dj_client WorkerName arg1 arg2"
exit(0)
end
@moiristo
moiristo / bounded_event_buffer.coffee
Last active October 9, 2015 09:08
BoundedEventBuffer CS class: buffers event calls until a given condition is met
class @BoundedEventBuffer
constructor: ( options = {} ) ->
@buffer = []
@processConditionMet = false
@processing = false
{ @name, @bufferSize, @processWhen, @interval } = options
@name = options.name ? 'AnonymousEventBuffer'
@bufferSize = options.bufferSize ? 100
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}["
ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN=""
#Customized git status, oh-my-zsh currently does not allow render dirty status before branch
git_custom_status() {
local cb=$(current_branch)
if [ -n "$cb" ]; then
echo "$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_PREFIX$(current_branch)$ZSH_THEME_GIT_PROMPT_SUFFIX"
@moiristo
moiristo / bookingexperts_client.rb
Last active March 9, 2021 16:08
BookingExperts client - ruby example
# frozen_string_literal: true
module BookingExperts
class Client
class Error < StandardError; end
class InvalidSignature < Error; end
attr_accessor :token_store
def initialize(token_store = nil)

BookingExperts App API - Changelog

All notable changes to this API will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[Unreleased]

Deprecated

  • Renamed tag to amenity where applicable. Expected date of removal: 2021-06-30
    • GET /v3/tags
## CREATE EXAMPLE ##
# folder: app/actions/posts
class Actions::Posts::CreatePost
include Actions::Posts::PostAction # In this scenario there is overlap between create & update, so introduce a concern
def perform!(post, author_scope:)
validate_action!(post, author_scope: author_scope)
post.assign_attributes(attributes)
post.save!