Skip to content

Instantly share code, notes, and snippets.

@brianmario
brianmario / jquery.autocompleteme.js
Created January 22, 2009 06:34
Account Auto Suggest
// 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;
@brianmario
brianmario / fiscal_calendar_extensions.rb
Created January 26, 2009 22:05
Time extensions for Fiscal Calendar
# 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
@brianmario
brianmario / jquery.validation.js
Created January 31, 2009 04:58
jQuery form validation plugin
//
// validatesPresence
//
// This validator ensures value presence
// The default options are:
//
// invalidClass: 'invalid-presence',
// blankValue: '',
// when: callBack(context)
// validatesOn: ['change', 'blur']
@brianmario
brianmario / jquery.infinite_scroll.js
Created February 5, 2009 20:20
jQuery infinite scroll plugin
// 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)
static VALUE someCallback(void * ctx) {
ctx = Qtrue;
}
static VALUE blah() {
VALUE ctx = Qnil;
someCallback(ctx);
// Outputs: NilClass
VALUE ctx;
static VALUE someCallback(void * ctx) {
ctx = Qtrue;
}
static VALUE blah() {
ctx = Qnil;
someCallback(ctx);
for file in `find . -type f -name '*.jsn'`; do mv $file ${file%.jsn}.json; done
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 << "}"
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
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);