Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View alvinsj's full-sized avatar

Alvin alvinsj

  • Singapore
View GitHub Profile
@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
@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 / 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({
task :my_task => :environment do
File.open(ENV['PIDFILE'], 'w') { |f| f << Process.pid } if ENV['PIDFILE']
Model.perform_task!
end
public class Product implements Cachable{
public Product(String type, String key){
mType = type;
mKey = key;
}
public String cacheId() {
return mKey;
}
// Initialization
cacheStore = new CacheStore(getContext()) {
@Override
public String storeName() {
return "ProductsStore";
}
};
// store value
cacheStore.put(TYPE, KEY, VALUE);
new APIRequest( new APIClient(HomeActivity.this), APP_SERVER+"/download_pdf", APIRequest.GET)
.withDefaultParams(defaultParamsHashMap())
.addParam("format", "json")
.addParam("id", pdfId)
.addHeaderParam("Referer", APP_REFERER);
.startDownload(CACHE_ID, DOWNLOAD_FOLDER, new APIDataRequestHandler(){
@Override
public void before(){
showProgressBar();
new APIRequest( new APIClient(HomeActivity.this), APP_SERVER+"/latest_news", APIRequest.GET)
.withDefaultParams(defaultParamsHashMap())
.addParam("format", "json")
.addParam("limit", 10)
.addHeaderParam("Referer", APP_REFERER);
.startWithCache(CacheStategy.RESPONSE_VERSION, CACHE_GROUP_KEY, CACHE_KEY,new JSONRequestHandler(){
@Override
public String getVersion(HttpEntity response){
return versionFromResponse(response);
}
new APIRequest( new APIClient(HomeActivity.this), APP_SERVER+"/search", APIRequest.GET)
.withDefaultParams(defaultParamsHashMap())
.addParam("format", "json")
.addParam("q", searchTerm)
.addHeaderParam("Referer", APP_REFERER);
.start(new JSONRequestHandler(){
@Override
public void before(){
showProgressBar();
class CreateTableS3Uploads < ActiveRecord::Migration
def up
create_table :s3_uploads do |t|
t. :url
t.timestamps
end
end
def down
drop_table :s3_uploads
end