Skip to content

Instantly share code, notes, and snippets.

View dbalatero's full-sized avatar

David Balatero dbalatero

View GitHub Profile
# detect `$rvm_path`
if [ -z "${rvm_path:-}" ] && [ -x "${HOME:-}/.rvm/bin/rvm" ]
then rvm_path="${HOME:-}/.rvm"
fi
if [ -z "${rvm_path:-}" ] && [ -x "/usr/local/rvm/bin/rvm" ]
then rvm_path="/usr/local/rvm"
fi
# load environment of current project ruby
if
module Wisper::EnlightenedPublisher
extend ActiveSupport::Concern
included do
include Wisper::Publisher
prepend PrependedMethods
end
def subscribe_to_listeners
self.class.wisper_listeners.each do |listener|
@dbalatero
dbalatero / 00_README.md
Last active March 23, 2022 17:04
This is an example of how I combine interaction/service classes with Wisper event broadcasting inside Rails.

This is an example of how I combine interaction/service classes with Wisper event broadcasting in Rails.

In this example, I show a UsersController#create API, a corresponding service object, and all the test code/listeners to make it all happen.

The outcome is:

  • Concepts in your system ("Signing up a user", "Creating an order") have a single entry point in your codebase, vs. making raw ActiveRecord calls to object.save in dozens of places.
  • Since your concept has one entry point (the service class), you can easily grep for usage of it.
  • Stupid easy to attach listeners to the service class
  • All event listeners are very small and easily unit tested
unsetopt auto_name_dirs
ZSH_THEME_GIT_PROMPT_PREFIX="("
ZSH_THEME_GIT_PROMPT_SUFFIX=")"
ZSH_THEME_GIT_PROMPT_DIRTY=" ✗"
ZSH_THEME_GIT_PROMPT_CLEAN=" ✔"
VIMODE='[i]'
function zle-keymap-select {
VIMODE="${${KEYMAP/vicmd/[n]}/(main|viins)/[i]}"
NETCAT(1) General Commands Manual NETCAT(1)
NAME
netcat - a free improvising computer music band
SYNOPSIS
netcat - Cycles Per Instruction [April 18th 2014]
DESCRIPTION
As netcat, Brandon Lucia (drums, Chango, computers), David Balatero (cello,
@dbalatero
dbalatero / practice
Last active February 16, 2025 17:00
Records how long you practice something (guitar, language, etc) each day, and displays it.
#!/usr/bin/env ruby
class Practice
def initialize
@data = {}
try_to_load_data
end
def record_today(minutes)
@data[key_for(Time.now)] = minutes
class Order < ActiveRecord::Base
has_many :line_items
before_validation :initialize_subtotal # good
before_save :recalculate_subtotal # bad
private
def recalculate_subtotal
self.subtotal = self.line_items.map(&:subtotal).sum
G 9 8h9 4h6
D 9h11 6h9 4h6
A 6 4 2h4h2 4
E 0 X 0
T H T P P H T H T H T P H T H T T H H T
G 0h2 9h12h9
D 2 0h10 10h9
A 0 3 0 3 5h7h5h7
E 5 5/15
module WarnMultipleBeforeForks
def self.extended(base)
base.class_eval do
alias_method_chain :before_fork, :multiple_warning
alias_method_chain :after_fork, :multiple_warning
end
end
def before_fork_with_multiple_warning(*args, &block)
if block_given?
describe Haha do
context '#hoho' do
use_vcr_cassette 'haha/hoho/successful_post', :match_requests_on => [:uri_without_params]
it 'should laugh' do
described_class.hoho('hahahahahha')
end
end
end