Skip to content

Instantly share code, notes, and snippets.

View diegodurs's full-sized avatar
💭
Developing the best connected urban e-bike

Diego d'Ursel diegodurs

💭
Developing the best connected urban e-bike
View GitHub Profile
@diegodurs
diegodurs / google_key_val.rb
Created January 9, 2018 12:02
KeyVal on Google Datastore
require 'google/cloud/datastore'
module Ruba
# This use the Google Datastore as a key value storage.
# One could argue that Memcache would be more appropriate.
# usage:
#
## class DoSomething
## include GoogleKeyVal
##
@diegodurs
diegodurs / db_events.md
Created December 5, 2015 16:26
What the heck is EventSourcing & CQRS ? Event table
event id event name payload
1234 artist_was_created artist_id: 1111, name: 'Beatles'
1235 artist_name_was_corrected artist_id: 1111, new_name: 'The Beatles'
1236 performance_was_claimed_on_recording performance_claim_id: 7171, user_id: 2222, recording_id: 3131, performance: 'singer'
@diegodurs
diegodurs / db_artists.md
Last active December 5, 2015 16:25
What the heck is EventSourcing & CQRS ? SQL tables
id name
1111 The Beatles
@diegodurs
diegodurs / benchmark_hash.rb
Created June 16, 2015 12:50
Benchmark with_indifferent_access & symbolize_keys Hash
require 'active_support/core_ext/hash'
require 'benchmark'
Benchmark.bm do |x|
x.report("string") do
1_000.times do
data_str = {
"id" => "06e99a1b-4020-4380-ab27-1a3e0c5e557c",
"type" => "Person",
"score" => "100",
# Ruby API server install
# ------------------------
# instal dev tool: git for clone, gcc & make to compile ruby, libssl-dev to compile ssl for ruby
# g++ is for gem dependencies
sudo apt-get install gcc git make libssl-dev g++
@diegodurs
diegodurs / delayed_job_scopes.rb
Created November 27, 2014 10:56
Delayed::Job Scopes
module DelayedJobScopes
extend ActiveSupport::Concern
included do
scope :error, -> (error) { failed.where('last_error ILIKE (?)', "%#{error.strip}%") }
scope :failed, -> { where('last_error IS NOT NULL') }
scope :queues, -> (queues) { where(queue: queues) }
end
def id_in_args
@diegodurs
diegodurs / .bash_prompt
Created October 29, 2014 13:13
Bash Prompt
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
# Screenshot: http://i.imgur.com/s0Blh.png
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
# after cloning the repo of rbenv
cd ~/.rbenv
git pull
cd plugins/ruby-build
git pull
rbenv install -l
rbenv install 2.1.2
@diegodurs
diegodurs / conventions.md
Last active June 21, 2016 06:25
Rights'Up little guidelines

RightsUp Code Guidelines

Github

use dashes (-) for branches, it's easier to write than underscore (_)

Pull Requests

  • pull latest changes in the master branch git checkout master git pull origin master
  • checkout on-your-feature
@diegodurs
diegodurs / mock_active_record.rb
Last active August 29, 2015 13:59
Attempt to mock basic features of ActiveRecord.I'm willing to include ActiveModel::Dirty, but I do not want to specify my model attributes for every models.
require 'ostruct'
require 'forwardable'
class MockActiveRecord < OpenStruct
def save(opts); end
alias_method :save!, :save
def attributes
to_h.symbolize_keys