Skip to content

Instantly share code, notes, and snippets.

View sebmarkbage's full-sized avatar

Sebastian Markbåge sebmarkbage

View GitHub Profile
@sebmarkbage
sebmarkbage / Math.js
Created November 27, 2011 16:37
Module Syntax With Global Imports (Designed to Emulate ECMAScript 6 Modules)
var two = 2, four = 4, five = 5;
exports: function sum(x, y) {
return x + y;
}
exports: var pi = 3.141593, birthday = 12;
exports: two, four;
@sebmarkbage
sebmarkbage / Example.coffee
Created October 24, 2011 21:54
CoffeeScript Whitespace After a Statement Creates an Object Context
###
The indentation on a line following a statement creates an implicit variable.
That variable can be reused by placing more statements on the same whitespace level.
###
createElement 'a'
.style
.width = 100
.height = 100
.setAttribute 'href', 'http://...'
class Point(x, y) extends Something {
move(x, y);
public X = 0, Y = 0;
public move(x, y) {
X = x;
Y = y;
repaint();
var Browser = require('Browser').Browser;
var Request;
(function(){
Request = Browser.something ? new Class(...) : new Class(...);
})();
// Util
function placeholder(){}
function derive(Child, Parent){
placeholder.prototype = Parent.prototype
var proto = new placeholder()
for (var i = 2, l = arguments.length; i < l; i++){
var mixin = arguments[i]
for (var key in mixin) proto[key] = mixin[key]
ART; // inherits ART.SVG
ART.Shape; // inherits ART.SVG.Shape
var surface = new ART(100, 100); // inherits ART.SVG
new ART.Shape().inject(surface); // inherits ART.SVG.Shape
var CustomClass = new Class({
Extends: ART.Shape
String.implement({
substitute: function(object, regexp){
return this.replace(regexp || (/\\?\{([^{}:]+)(?::([^{}:]+))?\}/g), function(match, name, format){
if (match.charAt(0) == '\\') return match.slice(1);
var value = (object[name] != null) ? object[name] : '';
if (format && typeof value.format == 'function') value = value.format(format);
return value;
});
@sebmarkbage
sebmarkbage / ART.Events.js
Created November 21, 2010 02:35
Extends ART.Element with listen/ignore event subscriptions.
/*
---
name: ART.Events
description: "Extends ART.Element with listen/ignore event subscriptions."
requires: [ART/ART.Element, More/Table]
provides: [ART.Events]
...
*/
ART.Element.implement({
var readSVG = function(text, doc){
var svg = doc.documentElement;
var w = +svg.getAttribute('width'), h = +svg.getAttribute('height');
w = 500;
h = 400;
var art = new ART(w, h);
art.element.setAttribute('viewBox', svg.getAttribute('viewBox'));
var myiframe = document.getElementById('#frame');
import 'MyLegacyClass' with { document: myiframe.contentWindow.document };
var frameBody = myiframe.contentWindow.document.body
new MyLegacyClass().toElement().inject(framebody); // Doesn't work without proper IoC