Skip to content

Instantly share code, notes, and snippets.

View HendrikRoth's full-sized avatar

Hendrik Roth HendrikRoth

  • Dusseldorf, Germany
View GitHub Profile
@HendrikRoth
HendrikRoth / main.go
Created June 30, 2016 23:27 — forked from nmerouze/main.go
JSON-API with Go and MongoDB: Final Part
package main
import (
"encoding/json"
"log"
"net/http"
"reflect"
"time"
"github.com/gorilla/context"
@HendrikRoth
HendrikRoth / main.go
Created June 29, 2016 20:10 — forked from nmerouze/main.go
Example for "Build Your Own Web Framework in Go" articles
package main
import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"time"
@HendrikRoth
HendrikRoth / gist:2d320c04d7def2cfcb6e96717eab5958
Created May 26, 2016 23:06 — forked from jfromaniello/gist:8418116
Example of authenticating websockets with JWTs.
var WebSocketServer = require('ws').Server;
var wss = new WebSocketServer({port: 8080});
var jwt = require('jsonwebtoken');
/**
The way I like to work with 'ws' is to convert everything to an event if possible.
**/
function toEvent (message) {
try {
@HendrikRoth
HendrikRoth / README.md
Last active November 5, 2015 20:29 — forked from bullshit/README.md
LIRC patch instruction/how-to for USB Infrared Toy from Dangerous Prototypes

LIRC patch instruction/how-to for USB Infrared Toy from Dangerous Prototypes

This is a instruction to patch the usb infrared toy driver into lirc sources. Most of the work is done by Peter Kooiman

Requirements

@HendrikRoth
HendrikRoth / mithril-touch.js
Last active September 2, 2015 18:37 — forked from webcss/mithril-touch.js
mithril-touch, consume touch and mouse events evenly with mithril
/*****************************************
/* DOM touch support module
/*****************************************/
if (!window.CustomEvent) {
window.CustomEvent = function (event, params) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
};
@HendrikRoth
HendrikRoth / eventsmixin.js
Last active September 2, 2015 12:14 — forked from webcss/eventsmixin.js
PubSub mixin using CustomEvents
// utilizes the browser eventsystem
// usefull in cases where you need communication between independent components
// registered events are automatically removed onunload with preserving any other onunload handler
var eventsMixin = function(target) {
var _subscriptions = [];
target.broadcast = function(type, payload) {
var ev = new CustomEvent(type, {
detail: payload,
@HendrikRoth
HendrikRoth / autocomplete.js
Last active August 30, 2015 20:59
mithril-autocomplete (horsey)
var pluck = require("lodash").pluck
var groupBy = require("lodash").groupBy
var forceRender = require("lodash").identity
var m = require("mithril")
var horsey = require("horsey")
var controller = function(label, data, property){
//split the data set into subsets for performance
@HendrikRoth
HendrikRoth / plural
Last active August 29, 2015 14:22 — forked from ArthurClemens/plural
/*
This code uses a regular expression to make the json safer.
An potentially safer alternative is https://github.com/joewalnes/filtrex (untested) at the cost of 130Kb.
Can be used for example with this JSON structure:
{
"_meta_po_header": "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
"COLLECTION_CONTENTS[0]": "Kolekcja zawiera %@ przepis.",
"COLLECTION_CONTENTS[1]": "Kolekcja zawiera %@ przepisy.",
"COLLECTION_CONTENTS[2]": "Kolekcja zawiera %@ przepisów."
var test = {};
test.getnews = function(exa) {
return m.request({
method: 'GET',
dataType: "jsonp",
url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&q=" + exa,
unwrapSuccess: function(response) {
return response.responseData.feed.entries;
},