This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Memoize | |
def remember(klass, method_name) | |
klass.class_eval do | |
memory = $redis | |
original = "original_#{method_name}" | |
original_method = method(method_name) | |
define_singleton_method(method_name) do |*args| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Data | |
attr_accessor :date_range | |
def initialize(type) | |
@type = type | |
end | |
def graph_points | |
SomeClass.graph_points( | |
@type, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ find /path/to/dir -type f -print0 | xargs -I {} -0 chmod 0644 {} | |
$ find /path/to/dir -type d -print0 | xargs -I {} -0 chmod 0755 {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'daemons' | |
Daemons.run('./proxy.rb') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To fix: | |
# LoadError: dlopen(/Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib | |
# Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle | |
# Reason: image not found – /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle | |
# from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle | |
# from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require’ | |
# from /Library/Ruby/Gems/1.8/gems/mysql2-0.2.6/lib/mysql2.rb:7 | |
# from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `gem_original_require’ | |
# from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:36:in `require’ | |
# from (irb):1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialization | |
cacheStore = new CacheStore(getContext()) { | |
@Override | |
public String storeName() { | |
return "ProductsStore"; | |
} | |
}; | |
// store value | |
cacheStore.put(TYPE, KEY, VALUE); |