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: ''
@StephanHoyer
StephanHoyer / gist:de107b794c43f28ffd75
Last active August 10, 2023 17:16
SVG Icons with mithril.js

Icons have been part of applications since ages. Also most websites rely on icons. There were several ways to use them. First we used plain files then image sprites to reduce requests. Nowadays everyone uses icon fonts like font-awesome or glyphicons.

They are infinetly scaleable and styleable with css. The downside is they use pseudo elements for displaying. This is not only difficult to handle but also non-optimal for accessibilty.

A famous CSS-Tricks post brings SVG icons into play. The are also scalable and they behave like normal images. But we also want to have a sprite to not load any images seperatly and kill our servers and our sites performance. The proposed version is to create sprites with grunt or gulp using the symbol-trick. It's basically add every icon to a hidden sprite-image and give every icon an id-property.

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  
  <symbol id="beaker" viewBox="214.7 0 182.6 792">
@StephanHoyer
StephanHoyer / gist:bddccd9e159828867d2a
Last active March 29, 2022 11:46
Isomorphic applications with mithril

Attention

This post described how to create an application with mithril 0.2.x. Now that ver 1.0 is out, some things are a little differnent.

The example is updated with the current version of mithril, though.

Isomorphic applications with mithril

@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 model = require('prosemirror/model');
var ProseMirror = require('prosemirror/edit').ProseMirror;
var toDOM = require('prosemirror/convert/to_dom');
var fromDOM = require('prosemirror/convert/from_dom');
var elt = require('prosemirror/dom').elt;
function inline(dom, context, added) {
var old = context.styles;
;(function() {
"use strict"
function Vnode(tag, key, attrs0, children, text, dom) {
return {tag: tag, key: key, attrs: attrs0, children: children, text: text, dom: dom, domSize: undefined, state: undefined, events: undefined, instance: undefined}
}
Vnode.normalize = function(node) {
if (Array.isArray(node)) return Vnode("[", undefined, undefined, Vnode.normalizeChildren(node), undefined, undefined)
if (node != null && typeof node !== "object") return Vnode("#", undefined, undefined, node === false ? "" : node, undefined, undefined)
return node
}
@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) {
'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 / diff.js
Created November 22, 2016 10:39
make a diff-list of two mailchimp exports
'use strict';
var fsp = require('fs-promise');
var differenceBy = require('lodash/differenceBy');
var keys = require('lodash/keys');
var values = require('lodash/values');
var parseCsv = require('csv-parse');
function parse(fileContent) {
return new Promise(function(resolve, reject) {
parseCsv(fileContent, {delimiter: ',', quote: '"', columns: true}, function (err, data) {