Skip to content

Instantly share code, notes, and snippets.

View garrytan's full-sized avatar

Garry Tan garrytan

View GitHub Profile
0x4217B17690dde35C7eC02D0b5FCcF153a997C996
@ExampleComponent = React.createClass
mixins: [HistoryJSMixin]
# so, in your search field, you can save the state to history and set the URL as well below...
#
search: (toSearch)->
handleResults = (err, content)=>
if content.query == @state.search
@setState(searchResults: content.hits)
@saveState(url: '/foo?bar=foo') # BINGO
/** Adapted from http://leifdenby.svbtle.com/reactjs-and-browser-history-a-historyjs-mixin */
var HistoryJSMixin = {
_historyjs_recoverState: function(state) {
received_state_serialized = state.data;
if (!$.isEmptyObject(received_state_serialized)) {
if (this.deserializeState !== undefined) {
received_state = this.deserializeState(received_state_serialized);
}
else {
@garrytan
garrytan / lazy_generate.rb
Last active February 16, 2016 00:53
LazyGenerate module lets you lazily generate properties for ActiveRecord
# LazyGenerate makes it easy to make new ActiveRecord objects with accessors
# that are generated and saved lazily
#
# To use, add this to your ActiveRecord class:
# extend LazyGenerate
# lazy_generate :my_lazy_property, :generate_lazy_property
#
# Side effect: Save is called on the object upon generation.
#
module LazyGenerate
@garrytan
garrytan / gist:704372
Created November 17, 2010 23:44
hi world
hello
Delivered-To: garry@posterous-inc.com
Received: by 10.14.37.77 with SMTP id x53cs147624eea;
Mon, 9 Aug 2010 13:51:03 -0700 (PDT)
Received: by 10.142.135.21 with SMTP id i21mr8948493wfd.92.1281387061871;
Mon, 09 Aug 2010 13:51:01 -0700 (PDT)
Return-Path: <press+bncCOC9uMyMHRC01IHjBBoEnnh3wg@posterous-inc.com>
Received: from mail-pz0-f70.google.com (mail-pz0-f70.google.com [209.85.210.70])
by mx.google.com with ESMTP id n6si13404264wfg.99.2010.08.09.13.51.00;
Mon, 09 Aug 2010 13:51:01 -0700 (PDT)
/usr/local/lib/ruby/gems/1.8/gems/passenger-2.2.7/lib/phusion_passenger/abstract_request_handler.rb:329:in `install_useful_signal_handlers' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/db.rb:515:in `call' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/db.rb:515:in `write' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/db.rb:515:in `print' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/db.rb:515:in `send_to_db' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/db.rb:376:in `remove_from_db' /usr/local/lib/ruby/1.8/mutex_m.rb:67:in `synchronize' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/db.rb:551:in `_synchronize' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/db.rb:375:in `remove_from_db' /vendor/gems/mongodb-mongo-0.14.1/lib/mongo/collection.rb:209:in `remove' /app/models/post.rb:234:in `delete_meta_data' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.3/lib/active_support/callbacks.rb:178:in `send' /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.2.3/lib/active_support/callbacks.rb:17
abcccd
if !use_javascript
body = body.gsub(/<script src="(http:\/\/gist.github.com\/.+?).js"><\/script>/i) do
github_url = $1
begin
SystemTimer.timeout(5) do
(Hpricot.new(open(github_url).read) % 'div.data').to_html
end
rescue Timeout::Error => detail
logger.debug(e)
%Q[<p><a href="#{github_url}">github_url</a></p>]
This is a gist