Skip to content

Instantly share code, notes, and snippets.

View StephanHoyer's full-sized avatar
🏠
Working from home

Stephan Hoyer StephanHoyer

🏠
Working from home
View GitHub Profile
@StephanHoyer
StephanHoyer / index.js
Created November 7, 2014 15:55
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
@StephanHoyer
StephanHoyer / index.js
Created November 7, 2014 15:56 — forked from kamilogorek/index.js
requirebin sketch
var AmpersandState = require('ampersand-state');
var Ingredient = AmpersandState.extend({
props: {
name: 'string'
}
});
var Meal = AmpersandState.extend({
props: {
var express = require('express');
function base(content) {
return [
'<!doctype html>',
'<html>',
'<head>',
'<link href="/index.css" media="all" rel="stylesheet" type="text/css">',
'<link href="/latin/firasans-bold,firasans-hair,firasans-light,firasans-book,firasans-italic,firamono-bold/fonts.css" type="text/css" rel="stylesheet"/ >',
'<script src="/index.js"></script>',
"use strict";
/*
Formatters
Usage:
f.append(f.trim(' foo '), 'bar') > foobar
With composition
"use strict";
/*
Chainable formatters
Usage:
function trim(value) {
return value.trim();
}
const directions = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]];
function evolve(currentCells) {
const equalTo = (a) => (b) => a[0] === b[0] && a[1] === b[1];
const isCurrentlyAlive = (cell) => currentCells.some(equalTo(cell));
const add = (a) => (b) => [a[0] + b[0], a[1] + b[1]]
const neighboursOf = (cell) => directions.map(add(cell));
const notIn = (list) => (item) => !list.some(equalTo(item));
const countNeighbours = (cell) => neighboursOf(cell).filter(isCurrentlyAlive).length;
'use strict';
var bus = require('./bus');
var throttle = require('lodash/function/throttle');
function getOffsetX(event) {
return event.offsetX || event.layerX;
}
function getOffsetY(event) {
@StephanHoyer
StephanHoyer / oojs.md
Last active October 13, 2015 16:45
Object orientation without new and the in JavaScript

Just saw Douglas Crockfords talk at Craft Conference

http://www.ustream.tv/recorded/46640057

Just tried it and must say, it has a certain beauty in it.

No tangeling with prototypes and this/that fuckup.

var Animal = function(name, legs) {
@StephanHoyer
StephanHoyer / inlineedit.js
Last active October 13, 2015 16:46
Inline edit mithril component
'use strict';
var m = require('mithril');
var extend = require('lodash').extend;
var setFocus = require('../util/viewhelper').setFocus;
var keymage = require('keymage');
function noop(){}
function addClass(el, className) {
@StephanHoyer
StephanHoyer / base.js
Last active November 19, 2015 21:17
Basic example of a j2c-mithril integration - http://jsfiddle.net/qe805q4q/1/
var styler = require('./styler');
function mainView() {
return [
styler.view(),
//...
];
}