Skip to content

Instantly share code, notes, and snippets.

$ ./hpricot_vs_nokogiri.rb
user system total real
hpricot:doc 0.230000 0.010000 0.240000 ( 0.265904)
nokogiri:doc 0.030000 0.010000 0.040000 ( 0.041641)
user system total real
hpricot:xpath 1.050000 0.020000 1.070000 ( 1.114454)
nokogiri:xpath 0.210000 0.010000 0.220000 ( 0.226418)
user system total real
hpricot:css 1.140000 0.030000 1.170000 ( 1.339635)
nokogiri:css 0.700000 0.010000 0.710000 ( 0.835559)
@chuyeow
chuyeow / Results
Created December 1, 2008 04:08
Is JSON.parse! faster?
user system total real
json:parse 0.100000 0.010000 0.110000 ( 0.106557)
json:parse! 0.110000 0.000000 0.110000 ( 0.129599)
# Micro-benchmark for new OrderedHash impl in http://github.com/rails/rails/commit/355f41d8aafd75d76db25cdda4736e0052b0605c
class OrderedHash < Hash
def initialize(*args, &block)
super
@keys = []
end
def []=(key, value)
if !has_key?(key)
@keys << key
// Show popup when user hovers over a child element of a container div.
$('div.child', '#container').mouseover(function() {
$('#popup').show();
});
// But hide it only when the mouse pointer leaves the container. Mouseout doesn't
// work here because of event bubbling - it'll trigger on child elements of
// #container as well.
$('#container').bind('mouseleave', function() {
$('#popup').hide();
function foo() {
if (!arguments.callee.done) {
arguments.callee.done = true;
} else {
return;
}
// Actual code here.
}
builder = Nokogiri::XML::Builder.new do |xml|
xml.listings {
xml.language 'en'
properties.each do |property|
xml.listing {
# Instantiate a Nokogiri::XML::Node and insert it manually.
node = Nokogiri::XML::Node.new('id', doc) # doc is actually Nokogiri::XML::Builder#doc.
node.content = property.id
// Clear newsletter textbox on focus if it contains the default text.
$('#newsletter_email').focus(function() {
var value = $(this).val();
// Clear the textbox if it's the default value.
if (!$(this).data('default') || value == $(this).data('default')) {
$(this).data('default', value);
$(this).val('');
}
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("friendfeed.com") {
body,input.l_toinput {
background-color: #202420!important;
color: #fff!important;
}
div.comments {
color: #eaeaea!important;
./scan-build -k -V -o foo/ xcodebuild -configuration Debug -sdk iphonesimulator3.0
static NSString *CellIdentifier = @"Cell";
cell = (MyCustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:@"TableCell" owner:self options:nil];
cell = [nibContents objectAtIndex:0];
}
// do your customization
return cell;