Skip to content

Instantly share code, notes, and snippets.

# prevents complicated rewrites from somehow screwing up my RailsBaseURI
<IfModule mod_rewrite.c>
# RewriteEngine on
RewriteCond %{REQUEST_URI} ^/my-uri-prefix* [NC]
RewriteRule ^(.*)$ - [L,QSA]
</IfModule>
<IfModule passenger_module>
RailsBaseURI /my-uri-prefix
</IfModule>
@choonkeat
choonkeat / twitter-member-lists.js
Created October 30, 2009 17:14
bookmarklet to show memberships on twitter profile
/*
bookmark: javascript:void(function(){var%20urls=['http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js','http://gist.github.com/raw/222540/52236ed6fd9f706c7c1f8c654427b53861f21945/twitter-member-lists.js'];for(n%20in%20urls){var%20s=document.createElement('script');s.src=urls[n];document.getElementsByTagName('head')[0].appendChild(s);}}())
*/
jQuery.getJSON(window.location + "/lists/memberships.json?callback=?", function(json) {
var list_names = jQuery.map(json.lists, function(obj) { return obj.name; });
jQuery('h2.thumb').after("<code>" + list_names.join(", ") + "</code>");
});
function on_google_map_ready(callback_fn) {
function call_when_found(name, fn) {
var x = function() {
if (window[name]) {
log("FOUND", name);
fn();
} else {
log("NOT found", name, new Date());
setTimeout(x, 500);
}
# wrt http://stackoverflow.com/questions/1066340/how-to-use-long-id-in-rails-applications
# and http://rubyforge.org/tracker/index.php?func=detail&aid=24387&group_id=4550&atid=17562
bash$ rake db:migrate
(in /Users/choonkeat/test/testbigint)
== CreateMessages: migrating =================================================
-- create_table(:messages)
-> 0.0966s
== CreateMessages: migrated (0.0967s) ========================================
Choonkeat-Home:trynodejs(master) choonkeat$ cat watch.js
sys = require("sys");
process.watchFile("watched_dir", function () {
sys.puts("\n[watched_dir changed]")
});
process.watchFile("watched_dir/watched_file.txt", function () {
sys.puts("\n[watched_file.txt changed]")
});
Choonkeat-Home:trynodejs(master) choonkeat$ node watch.js &
[1] 79417
@choonkeat
choonkeat / ee-localize-mysqldump.rb
Created November 26, 2009 02:05
Because customizing config.php is insufficient (3rd party code get left out, config.php get overwritten on update, ...) http://boblet.tumblr.com/post/68095239/ee-localhost
#!/bin/env ruby
if ARGV.empty?
$stderr.puts <<-EOM
ExpressionEngine (1.x) MYSQL DUMP Localizer
1. Reads MYSQL DUMP of ExpressionEngine website from STDIN
2. Replaces ALL HOSTNAME & PATH data (config) with LOCAL SETTINGS
3. Output corrected MYSQL DYMP file.
/*
Minimum tinymce config for MS-Word sanity
Based on http://tinymce.moxiecode.com/examples/example_05.php
*/
tinyMCE.init({
setup : function(ed) {
ed.onPostProcess.add(function(ed, o) {
if (o.get) {
// cleaning up white spaces, remove unnecessary tags
// p, span, em should have no attributes (unlike img or a)
@choonkeat
choonkeat / jsonify.rb
Created January 9, 2010 09:01
Display xml/json as pretty json
#!/usr/bin/env ruby
#
# Display xml/json as pretty json
#
require 'rubygems'
data = ARGV.first ? IO.read(ARGV.shift) : STDIN.read
while data
begin
require 'json'
x = JSON.load(data)
from=$1
to=$2
find . -iname "$from*" | sed "s/$from/\{$from,$to\}/g" | sed 's/^/mv /g' | bash
# Usage: ssh root@server "`cat rambo.puppet`"
#
# dependencies
which yum 2> /dev/null && yum -y install facter puppet # it is that simple
which apt-get 2> /dev/null && apt-get -y install wget ruby ruby1.8 libruby1.8 && apt-get -y autoremove
which facter && which puppet && exit 0 # proceed if not installed
which ruby || exit 1 # abort if without ruby
#
# let's go
mkdir install-puppet