Skip to content

Instantly share code, notes, and snippets.

View jhbabon's full-sized avatar
🦊

Juan Hernández jhbabon

🦊
View GitHub Profile
@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
#! /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...
@jhbabon
jhbabon / vim_installer.rb
Created June 24, 2012 17:37
Thor file for install vim in Mac OS X with Mercurial and rbenv
require 'thor'
class VimInstaller < Thor::Group
include Thor::Actions
def self.source_root
'/tmp'
end
def clean_up
@jhbabon
jhbabon / git_tar.sh
Created June 13, 2012 09:12
archive a git repo
# link: http://linssen.me/entry/archive-your-git-repo-easily/
git archive HEAD | gzip > $PWD\.tar\.gz