Skip to content

Instantly share code, notes, and snippets.

Math.floor(0.03 * 100) * 0.1
//>>> 0.30000000000000004
Math.floor(0.03 * 100) / 10
//>>> 0.3

== Javascript

~ » node
> console.log([1,2,3].map(function(n){n*2}))
[ undefined, undefined, undefined ]
> console.log([1,2,3].map(function(n){return n*2}))
[ 2, 4, 6 ]

== Ruby

#!/usr/bin/env coffee
queryString = require('querystring')
util = require("util")
parser = module.exports = (qs, sep, eq) ->
sep = sep || '&'
eq = eq || '='
params = {}
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
// try ruby-like mixin in javascript
function mixin(object, name, fn) {
var orignal = object[name];
object[name] = function() {
try {
this.super = orignal;
return fn.apply(this, arguments);
} finally {
@kaichen
kaichen / rails.zsh
Created March 19, 2011 12:00
a function for rails 2 & 3 via rails 3 cli interface
org_rails_cmd=`which rails`
function rails {
if [ $# -eq 0 ];then
$org_rails_cmd
elif [ -e script/rails ]; then
./script/rails $@
elif [ $1 = 'c' ];then
shift
./script/console $@
@kaichen
kaichen / config.ru
Created June 27, 2011 08:04
config.ru with sass autocompile support
require 'sass/plugin/rack'
Sass::Plugin.options.merge!(:css_location => "./path/to/stylesheets")
use Sass::Plugin::Rack
run Rack::Directory.new(".")
@kaichen
kaichen / kaichen.zsh-theme
Created June 28, 2011 09:11
My zsh theme
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
local current_dir='%{$terminfo[bold]$fg[blue]%} %~%{$reset_color%}'
local current_path='%{$terminfo[bold]$fg[blue]%}%c%{$reset_color%}'
local rvm_ruby='%{$fg[red]%}‹$(rvm-prompt i v g)›%{$reset_color%}'
local git_branch='$(git_prompt_info)%{$reset_color%}'
local current_time='%{$fg[yellow]%}%D{[%I:%M:%S]}%{$reset_color%}'
local arrow="%{$fg_bold[red]%}$%{$reset_color%}"
PROMPT="${current_dir} ${git_branch}${arrow} "
@kaichen
kaichen / sample.html
Created July 1, 2011 06:58
html5 video sample w/ jquery.tmpl
<!doctype html>
<html>
<head>
<title>Html5 video with jq.tmpl sample</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script>
<script type="text/javascript">
$(document).ready(function () {
@kaichen
kaichen / dummy.coffee
Created July 1, 2011 14:43
js function wtf
foobar = (x) -> not_exist
foobar(1)