Skip to content

Instantly share code, notes, and snippets.

View Leechael's full-sized avatar
🐹
Working from home

Leechael Leechael

🐹
Working from home
View GitHub Profile
@Leechael
Leechael / WeiboController.php
Created January 25, 2011 05:23
The weibo oauth processing controller with li3_oauth.
<?php
namespace app\controllers;
use lithium\net\http\Router;
use lithium\storage\Session;
use li3_oauth\models\Consumer;
class WeiboController extends \lithium\action\Controller {
@Leechael
Leechael / wget_slides.sh
Created February 13, 2011 07:25
Download all pdf/ppt/pptx/zip/doc/odp files in page
# --------------------------------------------------------------------------------------
# Download all pdf/ppt/pptx/zip/doc/odp files in page.
#
# Usage:
# xxx@xxx:~$ wget_slides http://velocityconf.com/velocity2010/public/schedule/proceedings
# Download all velocity 2010 slides.
# --------------------------------------------------------------------------------------
function wget_slides () {
curl -sX GET "$1" | grep -or 'http:\/\/[^\"]\+\.\(pdf\|pptx\?\|zip\|doc\|odp\)' | awk '{print "\""$0"\""}' | xargs wget
for f in `curl -s http://www.qconbeijing.com/schedule.html | grep -oe '\"[^\"]\+\.\(pdf\|rar\|zip\|ppt\|pptx\|odt\|doc\|docs\)' | cut -d\" -f2`; do wget http://www.qconbeijing.com/$f; done
@Leechael
Leechael / Entity.php
Created March 11, 2012 12:39 — forked from clexmond/Entity.php
Implementing custom getters and setters in Lithium
<?php
namespace path\to\lib;
use BadMethodCallException;
use lithium\core\Libraries;
use lithium\util\Inflector;
/**
* This class can extend either \lithium\data\entity\Record or \lithium\data\entity\Document
@Leechael
Leechael / build-ruby.sh
Created August 26, 2012 12:32
Build Ruby 1.9.3-p194 deb package
#!/usr/bin/env bash
# ----------------------------------------------------------------------------
#
# Test under 64-bit Debian Squeeze
#
# Thanks follow up posts:
#
# - Ruby 1.8.2 and Checkinstall 1.6.0:
# http://checkinstall.izto.org/cklist/msg00770.html
@Leechael
Leechael / setup-fluentd-initscript.sh
Created September 8, 2012 04:35
Fluentd init script setup for Debian
#!/usr/bin/env bash
#if [ `whoami` != 'root' ]; then
#echo "Please run as root."
#exit 1
#fi
cat << 'EOF' > /etc/init.d/fluentd
#! /bin/sh
@Leechael
Leechael / virtualbox_4_1.rb.patch
Created September 8, 2012 17:45
Added `:both` support for forward_port protocol configuration
--- virtualbox_4_1.rb.orig 2012-09-09 01:24:56.000000000 +0800
+++ virtualbox_4_1.rb 2012-09-09 01:39:32.000000000 +0800
@@ -135,15 +135,22 @@
def forward_ports(ports)
args = []
ports.each do |options|
- pf_builder = [options[:name],
- options[:protocol] || "tcp",
- "",
- options[:hostport],
@Leechael
Leechael / pjson.py
Created November 10, 2012 07:21
Pretty print for JSON, in Python
#!/usr/bin/env python
# -*- coding: utf8 -*-
from simplejson import loads
from simplejson.decoder import JSONDecodeError
from betterprint import pprint
from os import path
if __name__ == '__main__':
@Leechael
Leechael / gist:4074485
Created November 14, 2012 20:17
vmlive and vmstart: my handy commands for VirtualBox Instance Management
alias vmlive="VBoxManage list runningvms"
function vmstart () {
if [ -e $1 ]; then
echo 'No VirualMachine specified. All available machines:'
VBoxManage list vms | cut -d'"' -f2 | sed -E 's/(.*)/> \1/'
return
fi
local _EXISTS=`VBoxManage list vms | grep $1 | wc -l | awk '{print $1}'`
if [ ! $_EXISTS -eq 1 ]; then