<?php
// TODO: Enter some task that needs to be done.
// FIXME: Enter some bug that needs to be fixed.
// FIXME(BugNumber): Reference a bug number for FIXME.
// CHANGED: Once finished with TODO, replacement with CHANGED is recommended.
// NOTE: Enter a simple note.
// OPTIMIZE: A TODO specifically for optimization notes.
// IMPROVE: A TODO specifically for improvement notes.
// Examples:
// TODO: Add in a update script.
// FIXME: Bug in update script (cannot download new file).
// FIXME(81239): Bug in update script (cannot download new file).
// CHANGED: Added update script.
// NOTE: The update script is still a bit buggy.
// OPTIMIZE: Update download speed.
// IMPROVE: Make the UI a bit better for update script.
?>
function flip() {
var result = flipString(document.f.original.value.toLowerCase());
document.f.flipped.value = result;
}
function flipString(aString) {
var last = aString.length - 1;
//Thanks to Brook Monroe for the
//suggestion to use Array.join
var result = new Array(aString.length)
for (var i = last; i >= 0; --i) {
var c = aString.charAt(i)
var r = flipTable[c]
result[last - i] = r != undefined ? r : c
}
return result.join('')
}
var flipTable = {
a : '\u0250',
b : 'q',
c : '\u0254', //open o -- from pne
d : 'p',
e : '\u01DD',
f : '\u025F', //from pne
g : '\u0183',
h : '\u0265',
i : '\u0131', //from pne
j : '\u027E',
k : '\u029E',
//l : '\u0283',
m : '\u026F',
n : 'u',
r : '\u0279',
t : '\u0287',
v : '\u028C',
w : '\u028D',
y : '\u028E',
'.' : '\u02D9',
'[' : ']',
'(' : ')',
'{' : '}',
'?' : '\u00BF', //from pne
'!' : '\u00A1',
"\'" : ',',
'<' : '>',
'_' : '\u203E',
';' : '\u061B',
'\u203F' : '\u2040',
'\u2045' : '\u2046',
'\u2234' : '\u2235'
}
for (i in flipTable) {
flipTable[flipTable[i]] = i
}
require 'benchmark'
# The original implementation by Daniel DeLorme
# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/256662
class NilClass
def ergo
@blackhole ||= Object.new.instance_eval do
class << self
for m in public_instance_methods
undef_method(m.to_sym) unless m =~ /^__.*__$/
end
end
def method_missing(*args); nil; end
self
end
@blackhole unless block_given?
end
end
class Object
def ergo
if block_given?
yield(self)
else
self
end
end
end
a,b = [1,2,3], nil
n = 100_000
Benchmark.bm(15) do |x|
x.report("Original") do
n.times { a.ergo[0]; b.ergo[0] }
end
# Turn to facets implementation
require 'rubygems'
require 'facets/nilclass/ergo'
x.report("Facets") do
n.times { a.ergo[0]; b.ergo[0] }
end
x.report("Logic operators") do
n.times { a && a[0]; b && b[0] }
end
end
// home.php?act=index
<?php
if (isset($_GET['act'])) $PAGEACTION = $_GET['act'];
else $PAGEACTION = 'index';
switch ($PAGEACTION) {
// index page
case 'index':
include ('index.php');
break;
// an about page
case 'about':
include ('about.php');
break;
// $PAGEACTION doesn't exist
default:
// or just forward to home.php?act=index
echo "page does not exist";
break;
}
?>
/*
* Since we are passing the inner function outside, a reference to it
* still exists, hence it is not collected by the garbage collector.
*
* The variable a persists through to the next increment, and is not overwritten
* by outer() var a = 0 since inner still has a local variable inside it's scope.
*
* By creating global2, you have created another scope that acts independently,
* even though they are using the same function literal!
*/
function outer(){//define outer scope
var a = 0;//this is the persistent variable
function inner(){//define the inner scope
a++;//increment a
console.log(a);
}
return inner;//IMPORTANT: return the inner function to the outside (scope)
}
var global = outer();//create a new scope in global
global();//a = 1
global();//a = 2
var global2 = outer();
global2();//a = 1
global2();//a = 2