Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'mechanize'
def prompt(label, echo = true)
`stty -echo` unless echo
$stdout.print "#{label}: "
$stdout.flush
$stdin.readline.strip
ensure
unless echo
#!/usr/bin/ruby
# Format columns in the Cucumber style
input = STDIN.read
margin_left = input =~ /\A(\s+)\S/ && $1
rows = input.split("\n").map {|line| line.strip.scan(/\|([^|]+)/).map {|column| column.first.strip } }
column_widths = rows.transpose.map {|column| column.map {|c| c.size }.max }
rows.each do |row|
print margin_left
@ayosec
ayosec / example-config.yml
Created August 9, 2010 12:32
Simple script to auto-reply mails
from: any@example.com
body: "Invalid mail"
include_source: true
" Put this file in ~/.vim/plugin/local_vimrc.vim
" When open a file (buffer) this script will find a .vimrc in the file's directory and in its parents.
function! LoadLocalVimrc()
let paths = split(expand("%:p:h"), "/")
while len(paths) > 0
call add(paths, ".vimrc")
let source_name = "/" . join(paths, "/")
if filereadable(source_name) && $MYVIMRC != source_name
map = [
"âãäåāăąÁÂÃÄÅĀĂĄèééêëēĕėęěĒĔĖĘĚìíîïìĩīĭÌÍÎÏÌĨĪĬóôõöōŏőÒÓÔÕÖŌŎŐùúûüũūŭůÙÚÛÜŨŪŬŮñÑçÇüÜ".mb_chars,
"aaaaaaaaaaaaaaaeeeeeeeeeeeeeeeiiiiiiiiiiiiiiiiooooooooooooooouuuuuuuuuuuuuuuunnccuu"
]
# ActiveSupport::Multibyte::Chars#tr broken?
word = "anything"
adapted_word = "%#{word.mb_chars.split(//).map {|e| (p = map[0].index(e)) ? map[1][p,1] : e.to_s }.join.downcase}%"
Post.where("lower(translate(title, '#{map[0]}', '#{map[1]}')) like #{Post.connection.quote word}")
$ git clone git://gist.github.com/582351.git html_entities
...
$ cd html_entities/
$ wget http://www.w3.org/2003/entities/2007xml/unicode.xml
...
$ ruby html_entities.rb > entities.rb
$ ruby html_entities.rb plain > entities.dat
$ ls -sh entities.*
28K entities.dat 68K entities.rb
#!/usr/bin/ruby
begin
require "readline"
rescue LoadError
STDERR.puts "No readline found"
end
load "Rakefile"
Rake::Task["environment"].invoke
# Author: Ayose Cazorla
# Public Domain
#
# Normalize a lot of videos using ffmpeg and normalize-audio (both available as Debian packages)
#
# HRC on tha house...
AMPLITUDE="-12dBFS"
def say(msg)
# To be used with http://github.com/setepo/asset-pocket
#
# require 'clousure_compressor'
# compressor :clousure, :handler => ClousureCompressor.new
#
# js "public/javascripts/application.js" do
# compress :clousure
# use "app/views/js/*"
# end
@ayosec
ayosec / gist:630829
Created October 17, 2010 12:59
This scripts preloads the Rails environment, so you can run tests using "run 'test/unit/foo_test.rb'"
#!/usr/bin/ruby
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/application', __FILE__)
module Kernel
def run(test_file)
Process.waitpid(fork do
$: << File.dirname(__FILE__)+"/../test/"
load test_file