Skip to content

Instantly share code, notes, and snippets.

@fakechris
fakechris / export_delicious.py
Created October 3, 2011 07:03
Export delicious export html format from delicious API
from StringIO import StringIO
from lxml import etree
import time
XML_BEGIN = """
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<!-- This is an automatically generated file.
It will be read and overwritten.
Do Not Edit! -->
@fakechris
fakechris / sync_pinboard_delicious.py
Created October 3, 2011 10:45
Synchronize recent pinboard bookmarks to delicious.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from lxml import etree
from StringIO import StringIO
import time
import os
import urllib
PINBOARD_USER = "username"
@fakechris
fakechris / mysql_tunnel.rb
Created November 16, 2011 08:23
Connect mysql via ssh tunnel, create active record obj automatically and processing
require 'rubygems'
require 'URI'
require 'cgi'
require 'net/ssh/gateway'
require "mysql"
require 'active_record'
def connect_to(database, connection_opts)
args = {:adapter=>"mysql", :database=>database}.merge(connection_opts)
ActiveRecord::Base.establish_connection(args)
@fakechris
fakechris / ljoin.sh
Created December 7, 2011 03:24
one line join script
#!/bin/sh
ruby -e 'puts ARGF.read().split("\n").join(" ")' $@
# or use see instead
# sed -e :a -e '/$/N; s/\n/ /; ta'
@fakechris
fakechris / watch_fd.sh
Created December 7, 2011 03:26
watch fd by trace
#!/bin/sh
sudo dtrace -n 'syscall::open*:entry { printf("%s %s",execname,copyinstr(arg0)); }'
@fakechris
fakechris / mac_set_dns.sh
Created December 7, 2011 03:28
Set dns on mac
#!/bin/sh
networksetup -setdnsservers Wi-Fi Empty # 8.8.8.8
sudo killall -9 mDNSResponder
@fakechris
fakechris / hadoop_du.sh
Created December 7, 2011 03:30
user friendly hadoop du
#!/bin/sh
hadoop fs -du $1 | awk '{print $1/1000.0/1000.0/1000.0, $2, $3}'
@fakechris
fakechris / airplay.js
Created December 27, 2011 14:07
ipad airplay bookmarklet
javascript:%5B%5D.forEach.call(document.querySelectorAll('embed,video'),function(e)%7Be.setAttribute('x-webkit-airplay','allow');e.setAttribute('airplay','allow')%7D);
@fakechris
fakechris / g2b.js
Created March 31, 2012 07:44
Javascript bookmartlet that swith between google&baidu
javascript:window.location.href=window.location.href.match(/google/)?'http://www.baidu.com/s?ie=utf-8&wd='+window.location.href.split('&q=')[1].split('&')[0]:'http://www.google.com/search?ie=UTF-8&q='+window.location.href.split('&wd=')[1].split('&')[0];
#!/bin/sh
SRC_PATH=$0
DST_PATH=$1
for d in `ls $SRC_PATH`; do
echo "copying $SRC_PATH/$d -> $DST_PATH/$d"
rsync -aplx --link-dest=$SRC_PATH/$d $SRC_PATH/$d $DST_PATH/$d
echo "removing $SRC_PATH/$d"
rm -rf $SRC_PATH/$d
done