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
@moiristo
moiristo / net_http_debug.rb
Last active November 29, 2023 16:27 — forked from brainlid/net_http_debug.rb
Enable debug for all Ruby HTTP requests
require 'net/http'
module Net
class HTTP
def self.enable_debug!
class << self
alias_method :__new__, :new
def new(*args, &blk)
instance = __new__(*args, &blk)
instance.set_debug_output($stderr)
instance
@moiristo
moiristo / big_query_client.rb
Last active August 31, 2021 10:13
Simple BigQuery Ruby client using OAuth2
# frozen_string_literal: true
module BigQuery
class Client < Oauth2TokenStoreClient
ENDPOINT = 'https://bigquery.googleapis.com/bigquery/v2'
UPLOAD_ENDPOINT = 'https://bigquery.googleapis.com/upload/bigquery/v2'
MULTIPART_BOUNDARY = 'bex835900724346'
REQUIRED_SCOPE = 'https://www.googleapis.com/auth/bigquery'
def initialize
## 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!

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
@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)
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 / 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
@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
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 / 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