Skip to content

Instantly share code, notes, and snippets.

View gerardpaapu's full-sized avatar
🏠
Working from home

Gerard Paapu gerardpaapu

🏠
Working from home
View GitHub Profile
(var OrderedSet)
(set! OrderedSet (function (arr ordered? uniq?)
(set! this.items (arr or #[]))
(if uniq?.not this.uniquify
ordered?.not this.sort)
this))
(OrderedSet implement #{
"length": (function () this.items.length)
var Schemi = (function () {
function NamedType(name) {
this.name = name;
}
function Into(schema, convert) {
this.schema = schema;
this.convert = convert;
}

Calling methods from a constructor's prototype on objects of another type, is a common pattern in javascript: e.g. using Array::slice to use all or part of the arguments object as an array.

function (first/*, rest... */) {
    var rest = Array.prototype.slice.call(arguments, 1);
    ...
}
// just thinking about using closures to expose
// interface and conceal implementation after
// reading some stuff about lisp, and animation
// came to mind
function doNothing () {}
function createAnimationContext (framerate) {
// framerate should be in frames per second
// interval must be in ms per frame

I love Coffeescript, but write Javascript

This is an example of why even though I love coffeescript, I still frequently write code in raw javascript.

This is the coffeescript I originally had:

pairs = []
@gerardpaapu
gerardpaapu / OrderedSet.chitchat
Created July 3, 2012 04:03
An example of chitchat code and the javascript it compiles to
;;; OrderedSet
;;; ----------
;;;
;;; A Collection class that wraps an Array.
;;; It maintains immutability, an order, and
;;; does not contain duplicates
;;;
;;; Items of the Ordered Set should implement 'Ord'
(class OrderedSet
(constructor (items, ordered, distinct)
using System;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Net;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
@gerardpaapu
gerardpaapu / html-string.js
Created June 12, 2012 05:34
Wrap Strings that represent html to provide sanitation
function HTMLString (value, safe) {
if (value instanceof HTMLString)
return value;
if (!this instanceof HTMLString)
return new HTMLString(value, safe);
if (arguments.length < 1)
return this;
<!doctype HTML>
<head>
<link href="styles.css" type="text/css" rel="stylesheet" />
</head>
<div id="widget">
<div class="wrap">
<div id="rating">&#x2605;&#x2605;&#x2605;&#x00bd;&nbsp;</div>
<div id="controls"
style="display: none"
<script src="http://localhost:8089/loader.js" ></script>
<script>
new Poll({
id: "harry-potter-question",
question: "Which is the best Harry Potter",
answers: ["The first one", "The second one", "The Emperor Strikes Back"]
}).load();
</script>