Skip to content

Instantly share code, notes, and snippets.

View sebmarkbage's full-sized avatar

Sebastian Markbåge sebmarkbage

View GitHub Profile
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;
});
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
// 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]
var Browser = require('Browser').Browser;
var Request;
(function(){
Request = Browser.something ? new Class(...) : new Class(...);
})();
class Point(x, y) extends Something {
move(x, y);
public X = 0, Y = 0;
public move(x, y) {
X = x;
Y = y;
repaint();
@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://...'
@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 / parseCSStranform.js
Created February 8, 2012 22:00
Parse CSS Transform with ART
function parseCSStransform(transform){
var result = new ART.Transform(), tranform,
commandMatcher = /(\w+)\(([^\)]*)\)/g, command,
paramMatcher = /([\d\.]+)/g, params;
while (command = commandMatcher.exec(transform)){
params = command[2].match(paramMatcher);
for (var i = 0; i < params.length; i++)
params[i] = parseFloat(params[i]);
transform = new ART.Transform();
transform[command[1]].apply(transform, params);
@sebmarkbage
sebmarkbage / A.js
Created February 12, 2012 20:20
Module
setCurrentGlobalState('foo');
throw E;
@sebmarkbage
sebmarkbage / Template.js
Created February 15, 2012 18:43
HTML Template
var template = function(html){
var root = document.createElement('root');
root.innerHTML = html;
var nodes = root.getElementsByTagName('*'), ids = {};
for (var i = 0, l = nodes.length; i < l; i++){
var id = nodes[i].getAttribute('id');
if (id){
nodes[i].removeAttribute('id');
ids[id] = i;
}