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 'rubygems' | |
| require 'hpricot' | |
| require 'open-uri' | |
| BBC_URL = 'http://news.bbc.co.uk' | |
| SELECTORS = '.ticker_content_anchor , #other-top-stories .story, #third-story .story, #most-popular .story, #featured-site-top-stories---democracy-live .story, #more-from-bbc-news .story, #featured-site-top-stories---bbc-sport .story, #geo-uk-news-digest li .story, #also-in-the-news .story, #second-story .story, #top-story .story' | |
| bbc = open(BBC_URL) | |
| links = Hpricot(bbc).search(SELECTORS) |
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
| Element.implement({ | |
| toObject: function () { | |
| var obj = {}; | |
| this.getElements('input, select, textarea, button').each(function(el){ | |
| if (!el.name || el.disabled) return; | |
| var value = (el.tagName.toLowerCase() == 'select') ? Element.getSelected(el).map(function(opt){ | |
| return opt.value; | |
| }) : ((el.type == 'radio' || el.type == 'checkbox') && !el.checked) ? null : el.value; | |
| $splat(value).each(function(val){ | |
| if (typeof val !== "undefined") { obj[el.name] = 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
| if (Browser.Features.query) { | |
| Native.implement([Document, Element], { | |
| getElements: function(expression, nocash) { | |
| return new Elements(this.querySelectorAll(expression), {ddup: (expression.length > 1), cash: !nocash}); | |
| } | |
| }); | |
| } |
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
| $(document.body).live('mouseup', function () { console.log("mouseup from elem") }); | |
| $('body').live('mouseup', function () { console.log("mouseup from string selector") }); |
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
| addDelegatedEvent: function (selectorOrElement, event, functionName) { | |
| var __obj = this; | |
| $(this.element).bind(event, function (ev) { | |
| for(var el = ev.target; el !== __obj.element.parentNode; el = el.parentNode) { | |
| if (el === selectorOrElement || $(el).is(selectorOrElement)) { | |
| return __obj[functionName].apply(__obj, arguments); | |
| } | |
| } | |
| }); | |
| } |
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
| #include "particle.hh" | |
| #include "simulator.hh" | |
| using namespace std; | |
| Particle::Particle(string n, const double m, Point x0, Arrow v0) : name(n), mass(m), x(x0), v(v0) | |
| {} | |
| void Particle::setSimulator(Simulator* sim) | |
| { |
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
| J = 1 | |
| Mu = 1 | |
| if ARGV.length != 2 | |
| puts "Usage: #{File.basename(__FILE__)} <T> <H>" | |
| exit 1 | |
| else | |
| KbT = ARGV.shift.to_f | |
| H = ARGV.shift.to_f | |
| 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
| // Stub the console when not available so that everything still works. | |
| (function () { | |
| var i, functions = ["log", "debug", "info", "warn", "exception", "assert", "dir", "dirxml", "trace", "group", "groupEnd", "groupCollapsed", "time", "timeEnd", "profile", "profileEnd", "count", "clear", "table", "error", "notifyFirebug", "firebug", "userObjects"]; | |
| if (!("console" in this)) { | |
| this.console = {}; | |
| for (i = 0; i < functions.length; i += 1) { | |
| this.console[functions[i]] = function () {}; | |
| } |
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
| // Before running this file, do `touch foo` in the same directory. | |
| var fs = require('fs'), | |
| sys = require('sys'); | |
| var f = fs.readFileSync('foo', 'utf8'); | |
| sys.puts("sync: " + sys.inspect(f)); | |
| fs.readFile('foo', 'utf8', function (err, data) { | |
| sys.puts("async: " + sys.inspect(data)); |
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
| var fs = require('fs'), | |
| sys = require('sys'); | |
| fs.writeFileSync('foo-sync', '', 'utf8'); | |
| try { | |
| fs.writeFile('foo-async', '', 'utf8', function (err) { | |
| if (err) sys.puts("callback caught: " + sys.inspect(err)); | |
| }); | |
| } catch(e) { |