Skip to content

Instantly share code, notes, and snippets.

CmdUtils.CreateCommand({
name: "dict",
icon: "http://dict.cn/favicon.ico",
homepage: "http://dict.cn/",
author: { name: "Kai Chen", email: "chenk85@gmail.com"},
license: "GPL",
description: "Search word in dict.cn",
help: "dict word_wanted_to_search",
takes: {"input": noun_arb_text},
preview: function( pblock, input ) {
@kaichen
kaichen / gist:24572
Created November 13, 2008 19:21
test db prepare for merb
namespace :db do
namespace :test do
desc "Create the test DB and do migrations automatonlly"
task :prepare do
Merb.start_environment(:environment => 'test', :adapter => 'runner')
config = Merb::Orms::DataMapper.config
puts "Creating database '#{config[:database]}'"
case config[:adapter]
when 'postgres'
`createdb -U #{config[:username]} #{config[:database]}`
#! /usr/bin/ruby -w
# File: ryaourt
#
# A utility script let you can install rubygems as archlinux's aur package manager yaourt.
#
# Usge:
#
# $ ryaourt gem_you_want_to_query
#
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
if ARGV.empty? || ARGV.size != 3
#display the usage
return
end
# base.rb
# rails2p3 app template
# from Kai Chen
# Delete unnecessary files
run "rm README"
run "rm public/index.html"
run "rm public/favicon.ico"
run "rm public/robots.txt"
# From: http://www.javaeye.com/topic/456482?page=1
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <time.h>
#include <stdlib.h>
# Crack bug
# Crack use YAML paser to parse json data, and YAML parser cloud not parse colon symbol well.
# brianmario's fork would be better, http://github.com/brianmario/crack
# Fail
should "should be able to parse a JSON includes colon" do
data = %q![{"foo":{"bar":"2009-08-30 : 22:49"}}]!
lambda {
Crack::JSON.parse(data)
}.should_not raise_error(Crack::ParseError)
#!/usr/bin/env ruby
require 'ftools'
def get_sub_dirs_in_dir(dir)
`find #{dir} -type d`.split("\n") - [dir]
end
def get_sub_dirs_in_current_dir
get_sub_dirs_in_dir Dir.pwd
end
@kaichen
kaichen / run_tags.rb
Created September 9, 2009 14:56 — forked from bryanl/run_tags.rb
a useful script for vim user
#!/usr/bin/env ruby
#-*-ruby-*-
# A script to run ctags on all .rb files in a project. Can be run on
# the current dir, called from a git callback, or install itself as a
# git post-merge and post-commit callback.
CTAGS = `which ctags`.chomp
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'
@kaichen
kaichen / _gem
Created September 17, 2009 02:17 — forked from alexvollmer/_gem
#compdef gem gem1.9
gem_general_flags=("(-h --help)"{-h,--help}"[Get help on this command]"
"(-V --verbose)"{-V,--verbose}"[Set the verbose level of output]"
"(-q --quiet)"{-q,--quiet}"[Silence commands]"
"--config-file[Use this config file instead of default]:file:_files"
"--backtrace[Show stack backtrace on errors]"
"--debug[Turn on Ruby debugging]"
$nul_arg
)