Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wvanbergen
wvanbergen / gist:5017
Created August 12, 2008 07:44 — forked from dbussink/gist:4461
Add the current git branch in pink to your bash prompt.
# colors for ls, etc.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
if [[ ${EUID} == 0 ]] ; then
PS1='\[\033[01;31m\]\u@\h \[\033[01;34m\]\w\[\033[01;35m\]$(parse_git_branch)\[\033[01;34m\] \$ \[\033[00m\]'
else
PS1='\[\033[01;37m\]\w\[\033[00;35m\]$(parse_git_branch)\[\033[00m\] \$ '
fi
@wvanbergen
wvanbergen / ParseTree.eval_static_tree.rb
Created October 3, 2009 11:50
A method to evaluate static parts of a ParseTree syntax tree.
class ParseTree
# Evaluates a static part of the tree that ParseTree.translate returns.
# You can pas a block that will be used to get a value that is not static.
# A simple example:
#
# >> code = '{ :array => ["str", 123, 4.5], :dynamic => method_call }'
# >> tree = ParseTree.translate(code)
# => [:hash, [:lit, :array], [:array, [:str, "str"], [:lit, 123], [:lit, 4.5]],
# [:lit, :dynamic], [:vcall, :method_call]]
@wvanbergen
wvanbergen / gist:204134
Created October 7, 2009 15:30
Audio-enabled, profanity-enabled unit testing
module Swearing
SWEAR_WORDS = ['dammit', 'fuck', 'son of a bitch', 'motherfucker', 'oh no', 'prick']
SWEAR_VOICE = 'Alex'
def self.swear!
`say -v #{SWEAR_VOICE} #{SWEAR_WORDS[rand(SWEAR_WORDS.length)]} &`
end
end
class Test::Unit::Error
@wvanbergen
wvanbergen / 1.8.7 (ruby-1.8.7-p299): ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10.4.0]
Created July 28, 2010 17:07
Benchmark results of ChunkyPNG using different interpreters
---------------------------------------------
ChunkyPNG (0.8.0) decoding benchmark (n=50)
---------------------------------------------
Rehearsal ---------------------------------------------------------
From PNG stream 16.050000 0.110000 16.160000 ( 16.747523)
From RGBA pixelstream 0.090000 0.030000 0.120000 ( 0.122060)
From RGB pixelstream 0.860000 0.030000 0.890000 ( 0.901062)
----------------------------------------------- total: 17.170000sec
@wvanbergen
wvanbergen / bmp_import.rb
Created August 18, 2010 22:59
Create PNG from 24 bit BMP file
require 'rubygems'
require 'chunky_png'
# get the data
data = StringIO.new(File.read('filename.bmp'))
bmp_file_header = data.read(14).unpack('a2VxxV')
bmp_info_header = data.read(40).unpack('V3v2V6')
raise "Not a BMP file" unless bmp_file_header[0] == "BM"
@wvanbergen
wvanbergen / convert_innodb_to_per_table_idb.rb
Created August 22, 2010 11:52
Convert InnoDB tables to use a separate idb files instead of the shared, giant ibdata1.
#!/usr/bin/env ruby
# Converts an InnoDB database that uses a shared InnoDB tablespace file (e.g. ibdata1) to use
# a separate file per table.
#
# - First change your my.cnf file to use separate files by adding "innodb_file_per_table" to
# the [mysqld] section. (This is safe: MySQL will revert to the giant file if it cannot find
# the per table file.)
# - Restart the MySQL server
# - cd to the directory of your database (cd /opt/mysql/data/mydb)
# settings
@bucket_count = 1000 # Must be integer > 0
@min_value = 10 ** -4 # Must be > 0.0
@max_value = 10 ** +2 # Must be > @min_value
# precalculate some stuff
@min_value_log = Math.log(@min_value)
@max_value_log = Math.log(@max_value)
@log_delta = @max_value_log - @min_value_log
@bucket_size = @log_delta / @bucket_count.to_f
~ $ request-log-analyzer production.log # Analyze production.log
--format custom_file_format.rb # Use custom file format
--reject account_type free # Ignore requests from free accounts
--select locale en-US # Only look at en-US locale requests
--output HTML --file report.html # Generate an HTML report as report.html
---------------------------------------------
ChunkyPNG (0.10.0) encoding benchmark (n=10)
---------------------------------------------
Autodetect (indexed) 0.860000 0.000000 0.860000 ( 0.856220)
:no_compression 0.490000 0.000000 0.490000 ( 0.488724)
:fast_rgba 0.140000 0.000000 0.140000 ( 0.143066)
:fast_rgb 0.140000 0.000000 0.140000 ( 0.143170)
:good_compression 0.470000 0.010000 0.480000 ( 0.476883)
:best_compression 1.880000 0.000000 1.880000 ( 1.877189)
@wvanbergen
wvanbergen / Decoding speed
Created October 5, 2010 08:56
Chunky PNG performance: same benchmarks on Ruby 1.8.7, but added 'require "oily_png"' for a speed boost
---------------------------------------------
ChunkyPNG (0.10.2) decoding benchmark (n=20)
---------------------------------------------
ChunkyPNG OilyPNG
PNG - no filtering ( 1.056832) ( 0.078345)
PNG - UP filtering ( 3.327986) ( 0.078387)
PNG - PAETH filtering ( 7.499367) ( 0.089143)
From RGBA pixelstream ( 0.032571) ( 0.035790)