Skip to content

Instantly share code, notes, and snippets.

Pontus Lundin hontas

View GitHub Profile
@hontas
hontas / MutationObserver
Created Apr 4, 2014
A simple DOM-change handler using MutationObserver
View 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 Mar 9, 2014
Recursively walk through tree-structure
View treeMatrix
// 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 Jan 4, 2016
Ember footer component with bubbling actions
View EmberFooterComponent.js
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 Jan 26, 2014
Express server for fakeEnd
View server.js
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 Jan 26, 2014
Gruntfile setup with proxies, fakeEnd and Express server
View Gruntfile.js
/*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 Oct 25, 2012
HTML/CSS3: Star Wars Crawl
View gist:3955052
<!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 Oct 23, 2012 — forked from BrendanEich/minimalist-classes.js
less minimalism, richer leather
View minimalist-classes.js
// 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 Oct 23, 2012
JavaScript: PubSub
View gist:3937905
// 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 Oct 23, 2012
JavaScript: jQuery PubSub
View gist:3937887
(function($){
var o = $( {} );
$.each({
on: 'subscribe',
trigger: 'publish',
off: 'unsubscribe'
}, function( key, api ) {
$[api] = function() {
You can’t perform that action at this time.