Skip to content

Instantly share code, notes, and snippets.

@TimLang
TimLang / lisp.rb
Last active August 29, 2015 14:22 — forked from dahlia/lisp.rb
# 30 minutes Lisp in Ruby
# Hong Minhee <http://dahlia.kr/>
#
# This Lisp implementation does not provide a s-expression reader.
# Instead, it uses Ruby syntax like following code:
#
# [:def, :factorial,
# [:lambda, [:n],
# [:if, [:"=", :n, 1],
# 1,
@TimLang
TimLang / deploy.rake
Last active August 29, 2015 14:15 — forked from shmatov/deploy.rake
# lib/tasks/deploy.rake
namespace :deploy do
desc 'Deploy to staging environment'
task :staging do
exec 'mina deploy -f config/deploy/staging.rb'
end
end
#!/bin/bash
set -e # exit on error
### README
# * installs your desired ruby versions using rbenv
# ** including openssl (needed by bundler)
# ** including sqlite (probably needed for rails apps)
#
# Before you start:
# * put ssh-keys in place

ruby-1.9.3-p484 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p484 with the railsexpress patchsets: https://github.com/skaes/rvm-patchsets

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@TimLang
TimLang / ruby_gc.sh
Last active August 29, 2015 14:10 — forked from mikhailov/ruby_gc.sh
- http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/
- http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
article’s settings: ("spec spec" took 17-23!sec)
export RUBY_HEAP_MIN_SLOTS=1250000
export RUBY_HEAP_SLOTS_INCREMENT=100000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=30000000
export RUBY_HEAP_FREE_MIN=12500
@TimLang
TimLang / xor
Last active August 29, 2015 14:05
XOR two binary strings
("00000001".to_i(2) ^ "0110".to_i(2)).to_s(2)
# reuturn "111"
#mongodb
db.senior_questions.find({bankID:11, $where: "(Number(this.categoryID).toString(2) ^ 10000000).toString(2).replace(/0/g,'').length == 11"})
#postgresql
select length(replace(((192::bit(16) # id::bit(16)) :: text), '0', '')) as comparsion, id, name from accounts order by comparsion limit 1;
#mysql
@TimLang
TimLang / rake.rb
Created June 16, 2014 08:51
rake with arguments
require 'rake'
require 'optparse'
# Rake task for creating an account
# rake user:create -- --user test@example.com --pass 123
# exit at the end will make sure that the extra arguments won't be interpreted as rake task.
namespace :user do |args|
desc 'Creates user account with given credentials: rake user:create'
# environment is required to have access to Rails models
task :create => :environment do
options = {}
var mongo = require('mongoskin');
var db = mongo.db('127.0.0.1:27017/test');
// create index:
// key, unique, callback
db.collection('user').ensureIndex([['name', 1]], true, function(err, replies){});
// bind method: db.user ===> db.collection('user')
db.bind('user');
@TimLang
TimLang / imgBase64.js
Created April 29, 2014 02:12
nodejs image base64 encoding and decoding
var encoded = new Buffer(imagedata, 'binary').toString('base64');
var decoded = new Buffer(encoded, 'base64').toString('binary');
@TimLang
TimLang / encoding.rb
Created April 22, 2014 07:18
force encoding 'GB18030'
"UTF-8 string".encode('GB18030').force_encoding(::Encoding::BINARY)