Skip to content

Instantly share code, notes, and snippets.

View tobie's full-sized avatar

Tobie Langel tobie

View GitHub Profile
@tobie
tobie / gist:81118
Created March 18, 2009 13:35
SpiderMonkey's uneval for common types
function repr(v) {
print(uneval(v))
}
repr(false)
//-> false
repr(true)
//-> true
/* jsonp.js for Protototype
*
* Copyright (c) 2009 Tobie Langel (http://tobielangel.com)
*
* jsonp.js is freely distributable under the terms of an MIT-style license.
*--------------------------------------------------------------------------
Requires: Prototype >= 1.6
Usage:
new Ajax.JSONRequest('http://api.flickr.com/services/feeds/photos_public.gne', {
onComplete: function(json) {
document.observe('click', function(event) {
var element = event.findElement('a.quickdetails');
if (!element) { return; }
var href = element.readAttribute('href'),
m = href.split('/');
if (m.length < 3) { return; }
new Ajax.Request('/VacancyInfo', {
method: 'get',
parameters: { id: m.last() },
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" charset="utf-8">
document.addEventListener('resize', function() { throw 'resized!' }, false);
var event = document.createEvent('HTMLEvents');
event.initEvent('resize', true, false);
document.documentElement.dispatchEvent(event);
// should throw a "resized!" error. No longer does in FF > 3.5
// https://bugzilla.mozilla.org/show_bug.cgi?id=503244
// Untested. Requires Prototype >= 1.6
//
// Copyright (c) 2009 Tobie Langel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// Untested. Requires Prototype >= 1.6
//
// Copyright (c) 2009 Tobie Langel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// Untested. Requires Prototype >= 1.6
//
// Copyright (c) 2009 Tobie Langel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
Prototype.Selector.select(<String: selector>[, <Node: scope=document>]) -> [Element...]
Prototype.Selector.match(<Node: element>, <String: selector>) -> Boolean
Prototype.Selector.filter(<Iterable: elements>, <String: selector>) -> [Element...]
@tobie
tobie / gist:225259
Created November 3, 2009 17:35
Installing Rhino on Mac OSX
mkdir ~/Desktop/src/
cd ~/Desktop/src/
curl -O ftp://ftp.mozilla.org/pub/mozilla.org/js/rhino1_7R2.zip
unzip rhino1_7R2.zip
mkdir ~/Library/Java/
mkdir ~/Library/Java/Extensions/
cp ~/Desktop/src/rhino1_6R5/js.jar ~/Library/Java/Extensions/
testEmile: function(testcase) {
var element = document.getElementById('test_basic');
testcase.assertEqual('0px', element.style.left);
testcase.pause();
emile(element, 'left:300px', {
onComplete: function() {
testcase.resume(function() {
testcase.assertEqual('300px', element.style.left);
});
}