Skip to content

Instantly share code, notes, and snippets.

@kaichen
kaichen / gist:11280740
Last active August 29, 2015 14:00
你好MySQL,再见MySQL
SELECT 'normal' = 0 #=> 1
SELECT 'disable' = 0 #=> 1
SELECT 'disable1' = 0 #=> 1
SELECT '1disable' = 0 #=> 0
SELECT '123456' = 0 #=> 0
@kaichen
kaichen / gist:fae0c1bc836ee3cbec72
Created August 25, 2014 09:48
Rubygems Loading and Memory
Rubygems:rails mem=0KB
Rubygems:i18n mem=0KB
Rubygems:activesupport-json_encoder mem=0KB
Rubygems:actionpack-action_caching mem=0KB
Rubygems:actionpack-page_caching mem=0KB
Rubygems:rails-observers mem=0KB
Rubygems:pg mem=1488KB
Rubygems:unicorn mem=0KB
Rubygems:unicorn-worker-killer mem=0KB
Rubygems:polyamorous mem=32KB
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