Orangesoda

Sitemap and License. Everything on this site falls under the license unless otherwise noted.

Emacs

SRFI-1 List Utilities

by Lang 2009-12-07 Mon

Emacs-lisp implementations of a few functions from SRFI-1. I've also included intersperse, which is useful for string manipulation.

SRFI-2 and-let*

SRFI-2.el by Lang. 2009-07-17 Fri

An emacs-lisp implementation of SRFI-2, srfi-2.el. and-let* is a combination of and and let, which (optionally) binds the result of each form in the let block. It stops on the first false result, and executes the body only if all the forms are true.

(and-let* ((val (member 'foo '(a b c foo d e)))
           ((listp val))
           (val (car val)))
  val)

If foo was not found in the list, the form would return false rather than raising an error.

html-script.el

by Lang. 2009-10-07 Wed

My version of html-script.el. This code is originally from http://www.dur.ac.uk/p.j.heslin/Software/Emacs/, and is a simplified alternative to the various multi-modes.

Using the region definitions (each a list of starting regexp, ending regexp, and mode symbols) the keystroke (by default F12) will narrow to the region and invoke the first bound function. F12 a second time will widen the buffer and return to HTML mode.

I hacked up the code a bit to exclude the text matched by the starting and ending expressions. js2-mode flags any invalid syntax, and the script tags are certainly that. This seems like a workable solution for mixed javascript, at least until js2-mode can play nicely with multi-modes.

Javascript

Fluid Bindings (aka Dynamic Scoping, aka Parameters)

fluid.js by Lang. 2009-07-17 Fri

Fluid bindings follow the flow of control rather than the lexical order of a program. See wikipedia on Dynamic Scoping.

The code: fluid.js.

jquery.dataset: HTML5 Dataset jQuery Plugin

Posted by Ben on 2009-09-08 Tue.

The HTML5 specification allows custom data attributes to be added to any DOM element. This jQuery plugin provides methods to retrieve and manipulate custom attributes.

Read More: The jquery.dataset Plugin

Download: jquery.dataset.js

Squash: SQL Manipulation with Native Expressions

squash by Lang. 2009-12-07 Mon

This is an incomplete implementation of SQL in JavaScript objects. It's in the spirit of LINQ, but adds an additional layer of abstraction; clauses are interpreted with late-binding. It's possible to use the same set of where clauses in multiple contexts.

This is (sadly) the first implementation that occurred to me, it's got warts. Squash.

Scheme

A REQUIRE special form for Gambit-C

Posted by Ben on 2009-07-22 Wed.

The REQUIRE special form includes libraries only once. It is implemented using Gambit-C's INCLUDE and LOAD forms with COND-EXPAND to prevent a library from being loaded again (which is an error) or re-evaluated.

REQUIRE accepts a sequence of requirement specifications that identify libraries. The specifications are mapped onto the filesystem to find the corresponding source files or compiled modules. For example:

(require (srfi 1)
         (lib util))

;; Library code here...

See require#.scm for additional documentation. An easy way to integrate REQUIRE into a project is to include require#.scm from `.gambcini' or `~/.gambcini'. For more details, see Customization in the Gambit-C documentation.

Source: require#.scm _require.scm

Python

A namespace-aware SAX ContentHandler

Posted by Ben on 2010-01-19 Tue.

This ContentHandler provided generates PrefixMapping and ElementNS events from Element events. This can be used to act on namespace events when the underlying XMLReader is not namespace aware.

A subclass of this ContentHandler can implement the PrefixMapping and ElementNS event handlers and behave as if the underlying reader supports namepsaces. One caveat is that the qualified names of opening and closing tags must match since the reader is not namespace aware.

Source: saxns.py

kqueue() webserver

Posted by Ben on 2009-11-28 Wed.

kqueue() is a kernel event notification mechanism. This example uses it to drive a non-blocking "hello world" webserver without polling. The Python epoll() HOWTO and kqueue() tutorial are helpful references.

Source: httpd-kqueue.py

libev webserver

Posted by Ben on 2009-11-28 Wed.

libev is an event loop that provides a uniform interface to operating system specific event mechanisms such as kqueue() and epoll(). This example uses pyev to drive a non-blocking "hello world" webserver. Simple tests with httperf show performance is similar to the kqueue() webserver.

Source: httpd-pyev.py

Contributers

Ben Weaver

Ben lives in Chattanooga TN and works at Medium. Contact him by sending email to [his-first-name] at orangesoda.net.

Lang Martin

Lang Martin also lives in Chattanooga.

Wibler.com

Wibler email & apps are hosted by Google: