Skip to content

Instantly share code, notes, and snippets.

@silent-e
silent-e / bench-rebuttal.rb
Last active May 13, 2023 04:59
Catch throw vs raise rescue vs baseline return but with unique lambda variable names (Ruby v3.2.2)
require 'benchmark/ips'
Benchmark.ips do |x|
code1 = -> { catch(:foo) { throw(:foo, 'catch/throw') } }
x.report("catch a throw") {
value = code1.call
}
code2 = -> { begin; raise RuntimeError; rescue RuntimeError; 'raise/rescue' end }
x.report("rescue and exception") {
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we're interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
@silent-e
silent-e / gist:32cd2b9c93737eed987c
Created April 10, 2015 18:52
Entity Translation upgrade to enable revisions
/**
* Create revision for existing translation.
*/
function module_update_7005(&$sandbox)
{
if (!isset($sandbox['progress'])):
$sandbox['progress'] = 0;
$sandbox['current_type'] = 0;
$sandbox["entity_type"] = array();
$sandbox['max'] = db_query('SELECT COUNT(*) FROM {entity_translation}')->fetchField();