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 / github.js
Last active February 13, 2024 14:19
Commiting multiple files to github over API
'use strict';
var Octokat = require('octokat');
var extend = require('lodash/object/assign');
var defaults = {
branchName: 'master',
token: '',
username: '',
reponame: ''
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 / filterinput.js
Created May 20, 2015 10:07
Select2-like mithril input
'use strict';
var m = require('mithril');
var icons = require('client/utils/icons');
var remove = require('lodash/array/remove');
var transform = require('lodash/object/transform');
var last = require('lodash/array/last');
var code = require('yields-keycode');
function sameAs(filterA) {
@StephanHoyer
StephanHoyer / tooltip.js
Last active September 22, 2017 06:25
tooltip component
'use strict';
function noop(){}
var contentView = noop;
var elPos = { left: 0, bottom: 0};
var tooltip = {
show: function(content, options) {
return function(event) {
@StephanHoyer
StephanHoyer / elasticsearch-example.js
Created September 29, 2015 10:56
Simple example how to use elastic search with node.js
'use strict';
var elasticsearch = require('elasticsearch');
var Promise = require('bluebird');
var log = console.log.bind(console);
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
'use strict';
var m = require('mithril');
var t = require('client/utils/translate');
var vagueTime = require('vague-time');
var l16n = require('client/utils/l16n');
function assignValue(obj, objAttr) {
return function (event) {
@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(),
//...
];
}
@StephanHoyer
StephanHoyer / checkbox.js
Created December 8, 2015 11:15
Simple multiselect with mithril.js
'use strict';
var m = require('mithril');
var icons = require('client/utils/icons');
function checkbox(label, options) {
options = options || {};
var onclick = function(event) {
event.stopImmediatePropagation();
options.onchange && options.onchange({
'use strict';
var omit = require('lodash/object/omit');
var extend = require('lodash/object/extend');
var m = require('mithril');
function apiUrl(type) {
return '/api/v1/' + type;
}