Skip to content

Instantly share code, notes, and snippets.

View eik3's full-sized avatar

Eike Herzbach eik3

View GitHub Profile
############
############ this doesn't work with anthing above rails 2.0.4
############
cd `mktemp -d`
rails ext_js_test
wget extjs.com/deploy/ext-2.2.zip
unzip ext-2.2.zip
mv ext-2.2 ext_js_test/public/ext
cd ext_js_test
script/plugin install http://rug-b.rubyforge.org/svn/ext_scaffold/
@eik3
eik3 / Varnish VCL to randomize an URL
Created August 11, 2009 17:28
Varnish VCL to randomize an URL
# C includes must happen outside a VCL function
# see http://varnish-cache.org/wiki/VCLExampleSyslog
C{
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
}C
sub vcl_recv {
if (req.url ~ "^/random$" ) {
@eik3
eik3 / sqlite_basics.rb
Created September 1, 2009 17:09
Ruby <-> SQLite3
fn="test.sqlite"
exit(1) if File.exist?(fn)
require 'rubygems'
require 'sqlite3'
db=SQLite3::Database.new(fn)
db.execute("CREATE TABLE testable (t1 INTEGER PRIMARY KEY, data TEXT, num DOUBLE, time DATE)")
db.execute(%^INSERT INTO testable (data,num,time) VALUES ('This is sample data',#{rand},"#{Time.now}")^)
puts db.execute("SELECT * FROM testable")
@eik3
eik3 / commands.txt
Last active September 4, 2015 07:15
fix whitespace problems in source tree
# this find command lists all text files excluding files (e.g. binary files) that shouldn't be touched.
# you might want to add more file name extensions for your project if [1] outputs extensions of files
# that you don't want to have processed
#
# the commands below were tested on Ubuntu, your milage may vary on Mac OS (please leave a comment if so)
find . -regextype posix-extended -type f -size +0 ! -iregex '.*/\.(svn|git)/.*' ! -iregex '.*\.(gif|png|jpe?g|ico|psd|ai|jar|db|odt|pdf|swf|rtf|zip|eps|sqlite3?|mo|air|mp3|wav|otf|eot|ttf|woff)$'
# append this to add missing newline at EOF
-print0 | xargs -0 printf "e %s\nw\n" | ed -s;
@eik3
eik3 / sessiondecode.rb
Created August 19, 2010 15:50
A script to decode the Rails _session cookie
#!/usr/bin/env ruby
# This interactive script decodes the _session cookie contents of the Rails
# Session Store. It can be useful when debugging session-related problems.
# Be aware that Firefox doesn't update the cookie contents on every request when
# you keep the according dialog open. If you have to debug HTTP regularly, I can
# recommend the Charles Web Debugging Proxy (http://www.charlesproxy.com/)
puts("Loading...")
Signal.trap("INT") { puts "\n" ; exit }
@eik3
eik3 / clone gem list
Created September 2, 2010 12:59
clone gem list
# from: vestal_versions (1.0.2, 0.8.3)
# to: gem install --no-ri --no-rdoc vestal_versions -v=1.0.2
gem list | sed -r 's/([a-zA-Z0-9_-]+) \(([0-9\.]+)[,\)](.*)/gem install --no-ri --no-rdoc \1 -v=\2/'
@eik3
eik3 / unicodes.txt
Created November 25, 2010 10:14
cheat sheet for some useful or funny unicode characters
∞ 221e
∕ 2215 (useful for slashes in filenames)
★ 2605
☆ 2606
☹ 2639
☺ 263a
☻ 263b
⌣ 2323
ツ 30c4
@eik3
eik3 / block facebook.sh
Created December 20, 2010 16:39
how to prevent your computer from talking to facebook
# use the 127.0.0.2 address of the loopback interface so that it doesn't interfere with other servers on localhost
echo '127.0.0.2 blog.facebook.com static.ak.connect.facebook.com www.facebook.com facebook.com static.ak.fbcdn.net connect.facebook.net creative.ak.facebook.com ads.ak.facebook.com ads.ak.facebook.com.edgesuite.net' | sudo tee -a /etc/hosts
# run a tiny ruby/rack app with unicorn to reply with an empty HTTP 200 response on all requests
sudo unicorn -D -l 127.0.0.2:80 -e 'lambda { |env| [ 200, {"Content-Type" => "text/plain"}, "" ] }'
$ cat Gemfile
source :rubygems
gem "sinatra"
$ cat config.ru
require 'rubygems'
require 'bundler'
Bundler.require
@eik3
eik3 / gist:936362
Created April 22, 2011 09:46
Process Grep Bash Function
function prg {
WIDE=""
if [ "$1" == "-w" ]
then
WIDE="www"
shift
fi
processes=$(pgrep -- "$1")
if [ ! -z "${processes}" ]