Skip to content

Instantly share code, notes, and snippets.

View alvinsj's full-sized avatar

Alvin alvinsj

  • Singapore
View GitHub Profile
task :my_task => :environment do
File.open(ENV['PIDFILE'], 'w') { |f| f << Process.pid } if ENV['PIDFILE']
Model.perform_task!
end
@alvinsj
alvinsj / doi.js
Created March 22, 2014 03:59
doi concept
(function(w){
// doi.viewController(config)
// config.viewDelegate
var homeController = doi.ViewController(function(){
// doi.view.TableView(config)
// config.tableViewDelegate
// config.tableViewDatasource
var tableView = doi.view.TableView({
@alvinsj
alvinsj / english.html
Last active August 29, 2015 13:57
0324
<!doctype html>
<!--[if IE 6]>
<html id="ie6" dir="ltr" lang="zh-TW">
<![endif]-->
<!--[if IE 7]>
<html id="ie7" dir="ltr" lang="zh-TW">
<![endif]-->
<!--[if IE 8]>
<html id="ie8" dir="ltr" lang="zh-TW">
<![endif]-->
@alvinsj
alvinsj / memory.rb
Created August 18, 2014 12:54
Analyze object size. Usage: Memory.analyze(object)
module Memory
# sizes are guessed, I was too lazy to look
# them up and then they are also platform
# dependent
REF_SIZE = 4 # ?
OBJ_OVERHEAD = 4 # ?
FIXNUM_SIZE = 4 # ?
# informational output from analysis
MemoryInfo = Struct.new :roots, :objects, :bytes, :loops
#!/bin/env ruby
# lazy hack from Robert Klemme
module Memory
# sizes are guessed, I was too lazy to look
# them up and then they are also platform
# dependent
REF_SIZE = 4 # ?
OBJ_OVERHEAD = 4 # ?
@alvinsj
alvinsj / gist:6967159d05eff2c66a82
Last active August 29, 2015 14:07
chrome-cli reload all 'localhost:3000'
chrome-cli list links \
| grep localhost:3000 \
| sed -E "s/\\[([0-9]+:)?(.*)\\](.*)/\\2/" \
| xargs -L1 chrome-cli reload -t
{
"name": "my-app",
"version": "0.0.0",
"dependencies": {
"browserify": "~2.36.1",
"less": "~1.5.1"
},
"devDependencies": {
"watchify": "~0.4.1",
"catw": "~0.2.0"
@alvinsj
alvinsj / sneakySwift-currying.swift
Last active August 29, 2015 14:21
Sneaky Swift
func add(x: Int) (_ y: Int) -> Int{
return x + y;
}
add(1)(2); // 3
/** @jsx React.DOM */
// NOTE: This file is formatted for React.js + Browserify
// You might need to make some changes to use it without Browserify
var MousetrapMixin,
Mousetrap = require('br-mousetrap');
MousetrapMixin = {
@alvinsj
alvinsj / deep-assign.weird.js
Last active September 4, 2015 08:59
deep-assign (with weird mode)
var deepAssignFactory = function(weirdMode){
return function deepAssign(){
var objs = Array.prototype.slice.apply(arguments);
return objs.reduce(function(exObj, curObj){
if(Object.keys(curObj).length == 0) return exObj;
// merge whatever in curObj to exObj
return mergeSecondObjectToFirst(exObj, curObj)