Skip to content

Instantly share code, notes, and snippets.

View jhbabon's full-sized avatar
🦊

Juan Hernández jhbabon

🦊
View GitHub Profile
@jhbabon
jhbabon / izanami-app-log
Created August 28, 2013 09:34
Run Izanami app showing the configuration variables
#!/usr/bin/env ruby
require 'izanami/app'
$stdout.puts '>>> Izanami configuration'
ENV.each do |var, value|
if var.to_s.match(/\AIZANAMI_/)
$stdout.puts ">>> #{var}=#{value}"
end
end
@jhbabon
jhbabon / Gemfile
Last active December 19, 2015 04:08 — forked from rhoml/clear_hipchat.rb
# A sample Gemfile
source "https://rubygems.org"
gem 'mechanize'
gem 'chronic'
@jhbabon
jhbabon / cleanup.rb
Created February 14, 2013 16:33
Clean all INSERT command from a mysql dump with grep and ruby
#!/usr/bin/env ruby
# @see http://stackoverflow.com/a/11522507
if ARGV.empty?
$stdout.puts "Usage: cleanup.rb dump.sql table_a [table_b ...]"
else
args = ARGV.reverse
file = args.pop
@jhbabon
jhbabon / test.rb
Last active December 4, 2015 10:48
Visitor pattern (double dispatch) on Ruby
require_relative 'visitor'
require_relative 'visitable'
class Object
include Visitable
end
class Log < Visitor
def visit_Array(array)
puts 'Logging array:'
#! /usr/bin/perl
# @link: http://unix.stackexchange.com/questions/4527/program-that-passes-stdin-to-stdout-with-color-codes-stripped
use strict;
use warnings;
while (<>) {
s/\e\[?.*?[\@-~]//g; # Strip ANSI escape codes
print;
@jhbabon
jhbabon / README.md
Created November 25, 2012 20:02
Playing with DCI in Ruby: Chaining Contexts

DCI: Chain of contexts example

Run each chain:

$ ruby full_chain.rb
$ ruby half_chain.rb
$ ruby no_chain.rb
@jhbabon
jhbabon / Gemfile
Created November 23, 2012 11:34
Ruby development stack presentation
# encoding: utf-8
# Gemfile
source 'https://rubygems.org/'
gem 'rake' # up to date version
gem 'rack', '~> 1.4.1' # pessimistic version
gem 'thin', '= 1.5' # exact version
group :test do
gem 'rspec'
@jhbabon
jhbabon / config.ru
Created September 2, 2012 16:26
Rack configuration for static sites
# encoding: utf-8
use Rack::Static,
:urls => ['/css', '/img', '/js', '/less'],
:root => 'public'
run lambda { |env|
[
200,
{
@jhbabon
jhbabon / proc_callback.rb
Created August 7, 2012 09:44
Block callbacks
# encoding: utf-8
#
# Extract from:
# @link: http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks
# @link: http://techscursion.com/2011/11/turning-callbacks-inside-out
class ProcCallback
def initialize(callable, *args)
@callable = callable.to_s
@arguments = args.dup
@jhbabon
jhbabon / application.html.haml
Created August 2, 2012 16:55
Load javascript functions based on the current controller and action
-# Code...
%body{ :"data-controller" => controller_name, :"data-action" => action_name }
-# Code...