Skip to content

Instantly share code, notes, and snippets.

View sunny's full-sized avatar
☀️

Sunny Ripert sunny

☀️
View GitHub Profile
# Usage is made of oranges and lemonade and lines starting with "##"
def usage
open(__FILE__).read.grep(/^## ?/).join.gsub(/^## ?/, '')
end
var colors = ['aliceblue', 'antiquewhite', 'aqua', 'aquamarine', 'azure', 'beige', 'bisque', 'black', 'blanchedalmond', 'blue', 'blueviolet', 'brown', 'burlywood', 'cadetblue', 'chartreuse', 'chocolate', 'coral', 'cornflowerblue', 'cornsilk', 'crimson', 'cyan', 'darkblue', 'darkcyan', 'darkgoldenrod', 'darkgray', 'darkgreen', 'darkkhaki', 'darkmagenta', 'darkolivegreen', 'darkorange', 'darkorchid', 'darkred', 'darksalmon', 'darkseagreen', 'darkslateblue', 'darkslategray', 'darkturquoise', 'darkviolet', 'deeppink', 'deepskyblue', 'dimgray', 'dodgerblue', 'firebrick', 'floralwhite', 'forestgreen', 'fuchsia', 'gainsboro', 'ghostwhite', 'gold', 'goldenrod', 'gray', 'green', 'greenyellow', 'honeydew', 'hotpink', 'indianred', 'indigo', 'ivory', 'khaki', 'lavender', 'lavenderblush', 'lawngreen', 'lemonchiffon', 'lightblue', 'lightcoral', 'lightcyan', 'lightgoldenrodyellow', 'lightgreen', 'lightgrey', 'lightpink', 'lightsalmon', 'lightseagreen', 'lightskyblue', 'lightslategray', 'lightsteelblue', 'lightyellow', 'lime
# Fake `svnlook` for testing prupose.
# ./fake_svnlook.rb changed /home/pouet/blah/svn/kikoo -r 3483
# ^-- will just read /tmp/fakeSvn.3483 :)
abort 'only the `changed` keyword is allowed on fake_svnlook' if ARGV[0] != 'changed'
abort 'only the `-r` option is supported on fake_svnlook' if ARGV[2] != '-r'
abort "svnlook: No such revision #{ARGV[3]}" unless File.exists?(fake_svn = "/tmp/fakeSvn.#{ARGV[3]}")
puts File.read(fake_svn)
#!/usr/bin/ruby
# AudreyRandom
# Randomly returns elements out of an enumerable, without picking previous elements.
#
# Author: Sunny Ripert - http://sunfox.org
# Licence: WTFPL
#
# You see, my ex-girlfriend used to blame her music player's random algorythm
# because it sometimes gave her a song which played just a few minutes ago.
# This is for you, Audrey ;).
/*
* hash_change_listener(hash_check_interval)
*
* Prototype method for launching a "hash:change" custom event when the
* page's #anchor changes.
*
* Examples: adding a class to the current page anchor.
*
* document.observe('hash:change', function(event) {
* var div = $(window.location.hash.replace(/^#/, ''))
@sunny
sunny / args_remove.rb
Created August 16, 2008 15:28
Simple way of taking out single arguments from ARGV if they match a given regexp
# args_remove
# Simple way of taking out single arguments from ARGV if they match
# a given regexp.
#
# by Sunny Ripert under the WTFPL
#
# Example:
#
# if args_remove '--usage'
# puts "Usage: app [--progress] [--verbose] [-r|--recursive] [--days=N] [--tag=X --tag=Y...] files"
@sunny
sunny / args_remove.rb
Created August 16, 2008 15:28
Simple way of taking out single arguments from ARGV if they match a given regexp
# args_remove
# Simple way of taking out single arguments from ARGV if they match
# a given regexp.
#
# by Sunny Ripert under the WTFPL
#
# Example:
#
# if args_remove '--usage'
# puts "Usage: app [--progress] [--verbose] [-r|--recursive] [--days=N] [--tag=X --tag=Y...] files"
@sunny
sunny / array_to_h.rb
Created August 17, 2008 22:20
Array#to_h Hash#to_h which can take blocks
class Array
def to_h(&block)
ary = block_given? ? self.collect(&block) : self
Hash[*ary.flatten]
end
end
class Hash
def to_h(&block)
return self if !block_given?
@sunny
sunny / dirstat.rb
Created August 18, 2008 19:06
File usage stats in ruby
#!/usr/bin/ruby
# Dirstat by Sunny Ripert <sripert@insia.org>
# Provides useful file-usage statistics on a given directory.
#
# Example:
#
# $ ruby dirstat.rb .
# directory %use files %use(graph) size
# --------------------------------------------------------------------------------
# ./Futurama 56.11 % ( 27 files) |########### | 4.58GB
class String
# ANSI-colored version of the string
def colorize(color)
n = case color
when :black: 30
when :red: 31
when :green: 32
when :yellow: 33
when :blue: 34
when :magenta: 35