Skip to content

Instantly share code, notes, and snippets.

View aviflombaum's full-sized avatar

Avi Flombaum aviflombaum

View GitHub Profile
// The bestest event-delegator ever!
jQuery.fn.delegate = function(eType, r) {
return this.bind(eType, function(e) {var $t = $(e.target); for(var s in r) if($t.is(s)) return r[s].apply(this, arguments)})
};
@aviflombaum
aviflombaum / gist:11442
Created September 18, 2008 16:25 — forked from sudara/gist:11441
delegate: function(rules) {
return function(e) {
var target = $(e.target), parent = null;
for (var selector in rules) {
if (target.is(selector) || ((parent = target.parents(selector)) && parent.length > 0)) {
return rules[selector].apply(this, [parent || target].concat($.makeArray(arguments)));
}
parent = null;
}
}
# Will yield sets of size, useful when you have to iterate over large sets
# if you have an array of 50k elements, running .each is slow.
def in_blocks_of(s)
(1..(self.size/s)).each{|i| yield self[((s)*(i-1))...((s)*i)]} and yield self[((self.size/s)*s)...self.size]
end
ebay_data = Scrubyt::Extractor.define do
fetch 'http://www.ebay.com/'
fill_textfield 'satitle', 'ipod'
submit
click_link 'Apple iPod'
record do
item_name 'APPLE NEW IPOD MINI 6GB MP3 PLAYER SILVER'
price '$71.99'
def after_save
unless @skip_callbacks
import_products_by_id(self.product_ids_for_import) if should_import_products?
import_keywords(keywords_for_import) if should_import_keywords?
import_product_ads_by_id(ad_ids_for_import) if should_import_ads?
campaign_products_to_product_ids_delimited if should_update_product_ids_delimited?
campaign_keywords_to_keywords_delimited if should_update_keywords_delimited?
campaign_ads_to_ad_ids_delimited if should_update_ad_ids_delimited?
end
@aviflombaum
aviflombaum / google_search.rb
Created February 7, 2009 02:21
A ruby wrapper to search google using the Google AJAX Search API
require 'rubygems'
require 'httparty'
class GoogleSearch
include HTTParty
format :json
base_uri 'http://ajax.googleapis.com/ajax/services'
default_params :output => 'json', :v => "1.0"
def self.find(query)
#!/usr/bin/env ruby
#
# usage: script/server_restarter
#
# Rails autoloading, while nice in theory, frequently doesn't work. Since Rails 2.3+
# is so fast when completely reloading the server, I wrote this script to listen to the
# given directories, and kill/restart the server when any file is changed.
#
# It's quick, simple, and it reliably reloads your application when changes are made.
#
<iframe src="http://www.designerpages.com/collections/yanko-design/widget" style="border:0; overflow: hidden; height: 620px" border="0"></iframe>
# What Does Harvest Do?
# Connects to a DataSource
# Downloads a Set of Data
# Normalizes Format
# Stores it in Sharded Harvest DB -> Silos
# Possibly removes data?
# What Does Processor Do?
# What Does Harvest Do?
# Connects to a DataSource
# Downloads a Set of Data
# Normalizes Format
# Stores it in Sharded Harvest DB -> Silos
# Possibly removes data?
# What Does Processor Do?