Skip to content

Instantly share code, notes, and snippets.

View wacko's full-sized avatar

Joaquín Vicente wacko

  • Buenos Aires, Argentina
View GitHub Profile
@wacko
wacko / A friendlier rake task.md
Created August 7, 2026 16:45
A better approach when writing/testing a long rake task

The problem

When writing a script that updates a large amount of data (typically a rake task), it's easy to end up with something like this:

A long, procedural script that works like a black box.

The problem is that testing this properly usually means running the script multiple times against different datasets and checking the final state of the database.

The tests tend to become long setup sections, small variations from one test to another (often involving subtle or unclear changes), and finally an assertion against the final database state using a query that doesn't tell us much about why something happened.

@wacko
wacko / rake tasks más amigables.md
Last active February 6, 2025 03:22
Una mejor alternativa a la hora de escribir/testear rake tasks

El problema

Muchas veces a la hora de programar un script que actualiza muchos datos (tipicamente una rake task), se suele obtener un resultado similar:

Un script largo, procedural, que funciona como una caja negra.

Y el problema es que, para testearlo bien, hay que correrlo muchas veces contra distintos conjuntos de datos, evaluando el estado final de la base de datos. Los tests suelen ser líneas y líneas de setup, pequeñas variaciones entre test y test (muchas veces cambios poco claros o evidentes) y finalmente una evaluación del estado final con una query con gusto a poco.

@wacko
wacko / short_date.rb
Last active January 3, 2020 23:18
Class to represent a short date (MM/DD), without the year component
require 'date'
class ShortDate
attr_reader :month, :day
include Comparable
def initialize(string)
date = Date.strptime(string, '%m/%d')
@month, @day = date.month, date.day
rescue StandardError
@wacko
wacko / 01 Intro.md
Created June 7, 2019 19:36
Guia rápida para instalar ruby
@wacko
wacko / radios_nacionales.txt
Last active July 23, 2020 01:45 — forked from pisculichi/radios_nacionales.txt
URLs de radios nacionales de Argentina, para poder escuchar en la terminal con mplayer o vlc
# alias radio='function __radio(){ r=`grep -v "#" radios_nacionales.txt | grep -m 1 -i $1 | cut -d" " -f1`; cvlc $r 2> /dev/null; }; __radio'
# podria utilizarse mplayer en vez de vlc
AMs Nacionales
http://200.68.81.65:8000/am530 Radio Madre 530
http://www.servidorstreaming1.com:9962/; Radio Colonia 550
http://195.154.182.222:25223/live.mp3 Radio Argentina 570
http://18683.live.streamtheworld.com/CONTINENTAL_SC Continental 590
http://38.107.243.197:9639/live Rivadavia 630
@wacko
wacko / gemcount
Last active June 21, 2017 20:53
List all the different gems on your Gemfile.lock
#!/bin/bash
print_gems() {
awk '/([[:alnum:]_]+) \(/{ print $1 }' Gemfile.lock | sort -u
}
count() {
grep -c ^
}
@wacko
wacko / 01_node.sh
Last active August 4, 2019 08:10
Nativefier installer (Node.js + HomeBrew)
brew install 'nvm'
NODE_VERSION="4.4.3"
if ! grep -qs 'source $(brew --prefix nvm)/nvm.sh' ~/.bash_profile; then
printf 'export PATH="$PATH:/usr/local/lib/node_modules"\n' >> ~/.bash_profile
printf 'source $(brew --prefix nvm)/nvm.sh\n' >> ~/.bash_profile
fi
source $(brew --prefix nvm)/nvm.sh
nvm install "$NODE_VERSION"
@wacko
wacko / app.rb
Created May 14, 2015 18:33
Cuba basic test
require 'cuba'
class MyApp < Cuba
define do
on root do
res.write "it works!"
end
end
@wacko
wacko / example.rb
Created April 20, 2015 01:29
Very simple and stupid key-value store using ActiveRecord
# Use KeyValue to store globally unique data
KeyValue.set('api_key', '123') # => true
KeyValue.get('api_key') # => '123'
# You can use the alternate syntax:
KeyValue['api_key'] = '123' # => true
KeyValue['api_key'] # => '123'
@wacko
wacko / pre-commit
Last active September 16, 2020 22:57
Git hook to avoid commit debug lines (binding.pry console.log debugger...)
#!/usr/bin/env ruby
# Validates that you don't commit forbidden keywords to the repo
# You can skip this checking with 'git commit --no-verify'
exit 0 if ARGV.include?('--no-verify')
# Update this list with your own forbidden keywords
KEYWORDS = %w(binding.pry console.log debugger)
def red(text) "\033[31m#{text}\033[0m"; end