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
// HTML Response Autocompleter plugin | |
jQuery.fn.autocompleteme = function(options) { | |
return $(this).each(function() { | |
var input = $(this); | |
var settings = jQuery.extend({ | |
url: '/accounts/autocomplete', | |
delay: 250, | |
resultsSelector: input.selector+'.results' | |
}, options); | |
var req = null; |
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
# Time object extension adding fiscal calendar calculations based on an offset month | |
class Time | |
# The first day of the current fiscal quarter of this Time object instance, based on the passed offset_month | |
def beginning_of_fiscal_quarter(offset_month=1) | |
t = beginning_of_fiscal_year(offset_month) | |
4.times do | |
return t if self >= t && self < t+3.months | |
t = t+3.months | |
end | |
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
// | |
// validatesPresence | |
// | |
// This validator ensures value presence | |
// The default options are: | |
// | |
// invalidClass: 'invalid-presence', | |
// blankValue: '', | |
// when: callBack(context) | |
// validatesOn: ['change', 'blur'] |
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
// Infinite Scroll | |
jQuery.fn.infiniteScroll = function(options) { | |
return $(this).each(function() { | |
var el = $(this); | |
var settings = jQuery.extend({ | |
url: null, | |
triggerAt: 300, | |
page: 2, | |
appendTo: '.list', | |
container: $(document) |
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
static VALUE someCallback(void * ctx) { | |
ctx = Qtrue; | |
} | |
static VALUE blah() { | |
VALUE ctx = Qnil; | |
someCallback(ctx); | |
// Outputs: NilClass |
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
VALUE ctx; | |
static VALUE someCallback(void * ctx) { | |
ctx = Qtrue; | |
} | |
static VALUE blah() { | |
ctx = Qnil; | |
someCallback(ctx); |
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
for file in `find . -type f -name '*.jsn'`; do mv $file ${file%.jsn}.json; done |
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 Yajl | |
module Stream | |
def self.encode(obj) | |
case obj.class.name | |
when "Hash" | |
val = "{" | |
val << obj.keys.map do |key| | |
"\"#{key}\": #{encode(obj[key])}" | |
end * ", " | |
val << "}" |
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 'lib/yajl/http_stream' | |
require 'uri' | |
uri = URI.parse('http://jchrisa.net/toast/_all_docs_by_seq?include_docs=true') | |
Yajl::HttpStream.get(uri) do |hash| | |
# will take a few seconds, since the response is a single ~4MB JSON string | |
# if the response was a bunch of individual JSON strings, this would be fired | |
# for every string parsed off the stream, as they were parsed | |
puts hash.inspect | |
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
function messageInsertedCallback(message) { | |
// ... blah blah blah, I'm a dirty tramp | |
} | |
message = Message.parse(raw_data); | |
inserter = new DatabaseInserter(); | |
inserter.onMessageInsert = messageInsertedCallback; | |
DatabaseInserter.insert(message); |
OlderNewer