Skip to content

Instantly share code, notes, and snippets.

View hontas's full-sized avatar

Pontus Lundin hontas

  • Stockholm, Sweden
View GitHub Profile
@hontas
hontas / MutationObserver
Created April 4, 2014 21:46
A simple DOM-change handler using MutationObserver
// MutationObserver
(function(){
var pluginName = "domChangeHandler";
var defaults = {};
var DOMChangeHandler = function(HTMLElement, options) {
this.options = options || {};
this.handler = new MutationsObserver(changeEventHandler);
this.handler.observe(HTMLElement);
@hontas
hontas / treeMatrix
Created March 9, 2014 06:54
Recursively walk through tree-structure
// node { id: [Number], nodeTypeId: [String] }
// edge { fromNodeId: [Number], toNodeId: [Number], fromPort: [String] }
var decisionTree = {
nodes: [],
edges: [],
getTreeMatrix: function() {
var start = this.nodes.findBy('nodeTypeId', 'StartNode'),
self = this;
@hontas
hontas / EmberFooterComponent.js
Last active January 4, 2016 18:19
Ember footer component with bubbling actions
App.MemModuleFooterComponent = Ember.Component.extend({
tagName: 'footer',
classNames: ['mem-module-footer'],
actions: {
clearErrorMsg: function() {
this.set('errorMsg', '');
},
save: function() {
this.sendAction('save');
},
@hontas
hontas / server.js
Created January 26, 2014 02:18
Express server for fakeEnd
var express = require('express'),
fs = require('fs'),
app = express(),
port = 8080;
function getInt (num) {
return parseInt(num, 10);
}
function readJSONFile (path, callback) {
@hontas
hontas / Gruntfile.js
Created January 26, 2014 02:16
Gruntfile setup with proxies, fakeEnd and Express server
/*global module:false*/
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
module.exports = function(grunt) {
grunt.initConfig({
// Task configuration.
express: {
dev: {
options: {
@hontas
hontas / gist:3955052
Created October 25, 2012 20:00
HTML/CSS3: Star Wars Crawl
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css">
body {
background: black;
color: yellow;
font-family: Helvetica;
@hontas
hontas / minimalist-classes.js
Created October 23, 2012 10:46 — forked from BrendanEich/minimalist-classes.js
less minimalism, richer leather
// A response to jashkenas's fine proposal for minimalist JavaScript classes.
// Harmony always stipulated classes as sugar, so indeed we are keeping current
// JavaScript prototype semantics, and classes would only add a syntactic form
// that can desugar to ES5. This is mostly the same assumption that Jeremy
// chose, but I've stipulated ES5 and used a few accepted ES.next extensions.
// Where I part company is on reusing the object literal. It is not the syntax
// most classy programmers expect, coming from other languages. It has annoying
// and alien overhead, namely colons and commas. For JS community members who
@hontas
hontas / gist:3937905
Created October 23, 2012 09:37
JavaScript: PubSub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Hat tip Paul Irish
var o = $( {} );
$.sub = o.on.bind(o);
$.unsub = o.off.bind(o);
$.pub = o.trigger.bind(o);
@hontas
hontas / gist:3937887
Created October 23, 2012 09:33
JavaScript: jQuery PubSub
(function($){
var o = $( {} );
$.each({
on: 'subscribe',
trigger: 'publish',
off: 'unsubscribe'
}, function( key, api ) {
$[api] = function() {