Skip to content

Instantly share code, notes, and snippets.

Caio Chassot kch

Block or report user

Report or block kch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kch
kch / filetrim.rb
Created Jan 1, 2010
removes trailing spaces on every line, leading and trailing empty lines; ensures files end with a line feed
View filetrim.rb
#!/usr/bin/env ruby -pi
#
# Copyright © 2010 Caio Chassot
# Licensed under the WTFPL <http://sam.zoy.org/wtfpl/COPYING>
#
# File Trim. (Vertical and Right trim.)
# Command receives file paths as arguments. Modifies them in-place.
# - removes trailing spaces on every line;
# - removes leading and trailing empty lines;
# - ensures files end with a line feed.
@kch
kch / remove_entities.sh
Created Jan 2, 2010
decode all html entities in a project's files, in-place
View remove_entities.sh
$ ack --no-sql --ignore-dir=vendor -l '&\S+?;' | xargs \
ruby1.9 -rhtmlentities -pi -e '$_ = HTMLEntities.new.decode($_)'
@kch
kch / functions.sh
Created Jan 3, 2010
Awesome bash functions for the mac-minded
View functions.sh
# Allows gnu du to accept bsd's du -d option by wrapping
# gdu and translating -d to --max-depth before calling it.
# Useful on linux and solaris
du --help 2>&1 | grep -q -- '-d depth' || du () {
args=`echo "$@" | perl -pe 's/(-\w*)d(\d+)\b/$1 --max-depth=$2/'`
gnu_du=`which gdu du 2>/dev/null | head -1`
"$gnu_du" $args
}
egem () { $EDITOR $(dirname `gem which $@`)/..; } # opens a gem directory in $EDITOR
@kch
kch / ssh-put-key.sh
Created Jan 4, 2010
puts your ssh public key(s) on a remote server in a single command without fuss
View ssh-put-key.sh
#!/usr/bin/env bash
if [ $# -lt 1 ]; then
echo "Usage: `basename $0` <destination_ssh_connection_arguments>"
echo "Adds your public keys to a remote server."
exit
fi
ssh $@ "
mkdir -p ~/.ssh
@kch
kch / output
Created Jan 19, 2010
how I can't shut up on the @lettersapp mailing lists
View output
# #### email-init
# Caio Chassot....: 18.4%  ==================
# Jonas Wisser....:  6.8%  =======
# Paul Ward.......:  4.7%  =====
# Gavin Eadie.....:  4.0%  ====
# Jesper..........:  3.7%  ====
# Michael Ströck..:  3.6%  ====
# Faisal N Jawdat.:  3.4%  ===
# Mo McRoberts....:  3.3%  ===
# Brent Simmons...:  3.1%  ===
@kch
kch / quiz.rb
Created Jan 26, 2010
yet another annoying ruby quiz. now solved.
View quiz.rb
#!/usr/bin/env ruby1.9
# encoding: UTF-8
###############################################################################
#### The quiz: turn this hash… ################################################
###############################################################################
def initial_hash
{ 'child.name' => "a",
'child.surname' => "b",
@kch
kch / fizz-fucking-buzz.rb
Created Feb 2, 2010
Who doesn't love fizzbuzz?
View fizz-fucking-buzz.rb
i, f = 1, 100
i.upto(f) { |n| puts \
[[3, "Fizz"], [5, "Buzz"]].map { |d, s|
s if n % d == 0 }.join.sub(/^$/, n.to_s) }
@kch
kch / 1-yconvert.rb
Created Feb 4, 2010
Converts Yojimbo's export format for password and serial number records into CSV.
View 1-yconvert.rb
#!/usr/bin/env ruby1.9
# encoding: UTF-8
# rb-yconvert by Caio Chassot
# because yconvert by Steven Frank is PHP and this cannot stand.
# http://stevenf.com/downloads/yconvert.php.txt
#
# Converts Yojimbo's export format for password and serial number
# records into CSV.
#
@kch
kch / Rewind 30 Seconds.rb
Created May 2, 2010
Rewind currently playing track 30 seconds in iTunes
View Rewind 30 Seconds.rb
#!/usr/bin/env ruby1.9
# encoding: UTF-8
require 'appscript'
include Appscript
itunes = app("iTunes")
pos = itunes.player_position.get
pos = pos > 30 ? pos - 30 : pos / 2
itunes.player_position.set pos
@kch
kch / rb_main.rb
Created May 2, 2010
A more idiomatic rb_main for MacRuby applications
View rb_main.rb
# Loading the Cocoa framework. If you need to load more frameworks, you can do that here too.
framework 'Cocoa'
# Loading all the Ruby project files.
[__FILE__].concat(Dir[File.join(NSBundle.mainBundle.resourcePath.fileSystemRepresentation, '*.{rb,rbo}')])
.map { |path| File.basename(path, File.extname(path)) }.uniq[1..-1]
.each { |name| require(name) }
# Starting the Cocoa main loop.
NSApplicationMain(0, nil)
You can’t perform that action at this time.