Skip to content

Instantly share code, notes, and snippets.

View herber's full-sized avatar
🦄
Focusing

Tobias Herber herber

🦄
Focusing
View GitHub Profile
@herber
herber / container
Last active November 12, 2016 14:49
a simple node js container platform
const execFile = require('child_process').execFile;
var portSet = function(port, fn) {
var net = require('net')
var tester = net.createServer()
.once('error', function (err) { if (err.code != 'EADDRINUSE') return fn(err); fn(null, true) })
.once('listening', function() {
tester.once('close', function() { fn(null, false) })
.close()
})
@herber
herber / app.js
Last active March 7, 2017 18:56
Change url without reloading the site.
const express = require('express');
const app = express();
app.get('*', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.listen(3000);
@herber
herber / prime.js
Created July 30, 2017 19:11
A simple, inefficient algorithm for generating prime numbers.
const fs = require('fs');
let last = 0;
const p = () => {
const n = last + 1;
for (let i = 2; i < n; i++) {
if (n % i === 0) {
return;
@herber
herber / toArray.js
Created August 20, 2017 12:11
Transform anything into an array.
const toArray = array => {
if (array instanceof Array) return array;
if (array === null || array === undefined) return [];
return [array];
};
@herber
herber / index.js
Last active September 4, 2017 19:02
A simple gifs microservice.
const app = require('express')();
const fetch = require('node-fetch');
const cache = require('memory-cache');
const request = require('request');
app.get('/', (req, res) => {
res.status(404);
res.json({ body: `gifs.tobihrbr.com // Get a random gif: gifs.tobihrbr.com/random // Search for a gif: // gifs.tobihrbr.com/_TERM_` });
});
@herber
herber / index.js
Created October 18, 2017 19:43
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
const fetch = require('isomorphic-fetch');
fetch('https://offline-news-api.herokuapp.com/stories')
.then(function(response) {
if (response.status >= 400) {
throw new Error("Bad response from server");
@herber
herber / hashicle.js
Last active October 26, 2017 15:24
An example for draft
const crypto = require('crypto');
module.exports = (str, algorithm, out) => {
algorithm = algorithm || 'md5';
out = out || 'hex';
const hash = crypto.createHash(algorithm);
hash.update(str);
return hash.digest(out);
@herber
herber / snap.go
Last active October 26, 2017 12:23
package main
import (
"fmt"
"strings"
"io/ioutil"
"log"
"os"
"path/filepath"
"strconv"
@herber
herber / Readme.md
Last active October 26, 2017 16:55
My single readme file

Longa mediique pennis ut mane equus Baucida

Sarisa vocato munus carens clamata subigebant tulerant

Lorem markdownum; Sic corporis vixque et haesit caudas verborum iactu deo contemptuque frangit hederae gemini. Iuncta at amens abrepti te traherent ille ponunt capitisque galeaque quidem ire. Cum non valuisse ignare promunturiumque feraxque: sors sub ver neque et scilicet veniensque quae. Avulsumque ducunt imas praestans, sua ego admovet castos.

@herber
herber / sort.js
Last active October 26, 2017 20:10
A simple bubble sort function.
const bubbleSort = (arr) => {
for (let i = arr.length - 1; i >= 0; i--){
for(let j = 1; j <= i; j++){
if(arr[j - 1] > arr[j]){
const temp = arr[j - 1];
arr[j - 1] = arr[j];
arr[j] = temp;
}
}
}