Skip to content

Instantly share code, notes, and snippets.

View sebmarkbage's full-sized avatar

Sebastian Markbåge sebmarkbage

View GitHub Profile
public static class UrlHelperExtensions
{
public static string SmartAction(this UrlHelper url, object values)
{
return SmartAction(url, null, values);
}
public static string SmartAction(this UrlHelper url, RouteValueDictionary valueCollection)
{
return SmartAction(url, null, valueCollection);
@sebmarkbage
sebmarkbage / bootstrap.js
Created March 22, 2012 21:16
Using options
var loader = require('../path/to/link');
loader.alias('package', '../path/to/package.js');
loader.alias('package2', '../path/to/package2.js');
loader.base('../path/to/my/root/folder/');
loader.load('main');
@sebmarkbage
sebmarkbage / nothis.js
Created March 22, 2012 17:52
Super calls
var currentInstance;
function parent(){
currentInstance.parent();
}
function wrapMethod(method){
return function(){
var previousInstance = currentInstance;
currentInstance = this;
@sebmarkbage
sebmarkbage / DeferedModules.js
Created March 12, 2012 20:00
Defered Modules
// Deferred Labeled Modules.js
require: 'Foo';
function LoadSomething(){
var a = 'A'; // Synchronous
alert('Will now start loading the Foo module');
defer: {
@sebmarkbage
sebmarkbage / Work.js
Created March 11, 2012 15:12
Module Compilation
(function(){
var a, b, c;
function A(){
if (a) return a;
var exports = a = {};
var n = 'foo';
var x = function(){
function require(module){
if (module.cached) return module.cached;
module(module.cached = {});
return module.cached;
};
function MODULE1(exports){
};
function MODULE2(exports){
@sebmarkbage
sebmarkbage / moduleFunction.js
Created February 29, 2012 19:58
Module Function Export
module M {
function B(){ return 'B'; };
export this A(){ A = B; return 'A'; };
}
M(); // 'A'
M(); // ?
// If the second call yields 'B' then this should be ok as well:
@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;
}
@sebmarkbage
sebmarkbage / A.js
Created February 12, 2012 20:20
Module
setCurrentGlobalState('foo');
throw E;
@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);