I was reading up on Guile, figuring I should revisit Scheme annually. Found some examples, and translated them into Javascript.
(lambda (x) (+ x x))
(define add4 (let ((x 4)) (lambda (y) (+ x y))))
(define factorial (x) (if (zerop x) 1 (* x (factorial (- x 1)))))
function(x) { return add(x,x); }
function _defunmaker() { var x=4; return function(y) { return x + y; } }
var add4 = _defunmaker();
_defunmaker = null;
var factorial = function(x) { if (x==0) { return 1; } else { return x * factorial(x-1); }; };
This is a demo of a technique to transmit password encrypted. It's not a perfect solution yet, but it's getting there.
Normally, you should use canned Javascript or canned PHP modules to implement web features, but sometimes, that can suck. Typically, these products, if they're popular, start to suffer from feature bloat. Such was the case with some code for "interstitials", which are those ads that pop up on some web pages, interrupting your reading. Popups have been around a long time, and the drop-in code is just really huge.
nzakas has a great presentation about speeding up Javascript loops but it applies to any language that uses C-like loop structures.
Here's a way to cache data on the client side, via javascript. This was tested on Firefox 3.6.3 on Ubuntu.
The idea is to convert your data into Javascript, and then load it with the SCRIPT tag. You then use the Expires HTTP header to tell the client how long to cache the data. Finally, you use some Javascript code to display the data.
This Javascript widget strips non-numeric characters from the input. The result will be a space-separated list of numbers.
This is weird. The authors turn OpenOffice.org into a spreadsheet server -- and then create a front end in Dojo with Javascript, and tunnel events from the front end to the OOo spreadsheet via a Tomcat servlet.
At work I run Firefox without the (great) Adblock Plus plug-in. Adblock Plus mangles the HTML code to insert its own code that displays the "Block Ad" tabs, and this interferes with our CMS. Whenever I insert some code to embed video, Adblock Plus sees it and then adds its own code, ruining the code.
I forgot this, and installed ABP and then had to uninstall it.
Then, I started noticing that TinyMCE was altering URLs in links, so a url like http://example.com/go.php?id=100&start=344 would get mangled, so the ampersand (&) was replaced with & the HTML entity. I'd see: http://example.com/go.php?id=100&start=344
It turns out this is correct behavior, because xml doesn't allow & to be in an attribute. It needs to be escaped. The only problem is that IE6 won't handle these links correctly.
This is the Hello, World program, written in Javascript and encoded as a data URI.
<script src='data:application/javascript;base64,ZG9jdW1lbnQud3JpdGUoIkhlbGxvLCB3b3JsZCEiKQ=='></script>
Coroutines are back! They never really left, but, it looks like different languages are adding native support for coroutines.
A JavaScript Module Pattern is a fantastic example of how to use closures.
Javascript Closures has more detailed information.
Douglas Crockford brought the style over to JS, and his site has a lot of important articles about Javascript hacking (as a functional language).
Here's a Javascript calculator that was put together to deal with situations where you have to split up a grocery receipt with a friend. You can type in the prices, one per line. Check the box if it's a taxable item. (Set the tax rate if it's not 8.25%.) Then, click the "+" button to add it up.
The challenge with these names is twofold. For one, they follow a European convention of using "of" to denote the family, e.g. De La Cruz. This is like the Irish O'Connor or Italian del Vecchio.
Here's a snippet of javascript that breaks up a phone number into its parts, if it's formatted in the common formats.
var cell = namesArray[rownum]['Cell']; If you wish to comment, post this article on reddit or hacker news.