Skip to content

Instantly share code, notes, and snippets.

View matths's full-sized avatar
💻
In a former live I was a flash developer.

Matthias Dittgen matths

💻
In a former live I was a flash developer.
View GitHub Profile
@matths
matths / install_sqlcipher.sh
Last active December 31, 2019 13:46
Install better-sqlite3 node package with custom sqlcipher amalgamation
#!/bin/bash
# build the SQLCipher .c/.h files
git clone https://github.com/sqlcipher/sqlcipher.git
cd sqlcipher
./configure --enable-tempstore=yes --enable-fts5 CFLAGS="-DSQLITE_HAS_CODEC"
make sqlite3.c
# prepend better-sqlite3 configuration
# https://github.com/JoshuaWise/better-sqlite3/blob/v5.0.1/docs/compilation.md
@matths
matths / as-object.js
Last active February 9, 2019 18:53
"You can also use the approach below, which will result in a very nice data table at the top of your markdown when viewing the file GitHub:"
{
Title: 'My awesome markdown file',
Author: 'Me',
Scripts: [
'js/doStuff.js',
'js/doMoreStuff.js'
]
}
@matths
matths / example_with_middleware.js
Created February 6, 2019 22:21
basic reverse proxy middleware in comparison to the node-http-proxy module
var http = require('http');
var createProxyMiddleware = require('./proxy_middleware');
/*
/etc/hosts
127.0.0.1 hostA
127.0.0.1 hostB
*/
@matths
matths / Binding.js
Created November 24, 2018 15:00
simple two way binding with vanilla js as explained by Blaize Stewart (@theonemule) at https://www.wintellect.com/data-binding-pure-javascript/
// inspired by @theonemule (Blaize Stewart) via https://www.wintellect.com/data-binding-pure-javascript/
window.Binding = (function () {
var bindingStore = {};
function Binding(prop, obj) {
if (!obj) {
obj = bindingStore;
bindingStore[prop] = undefined;
}
@matths
matths / index.js
Last active January 27, 2016 21:48
composition with lodash _.flow(), and with flowArg to differently distribute arguments
var _ = require('lodash'); // 4.0.1
// filter implementations doesn't matter right now
var _method = function (method, handler) {
return function (req, res, next) {
console.log('_method middleware', method);
handler(req, res, next);
// or call next()
}
@matths
matths / TestApp.js
Created August 12, 2014 19:04
NodObjC Example of drawRect call (not working)
// dependencies
var ObjC = require('NodObjC');
// ObjC dependencies
ObjC.import('Foundation');
ObjC.import('Cocoa');
ObjC.import('AppKit');
ObjC.import('QuartzCore');
// using ARC
@matths
matths / http-and-ssh-proxy.js
Last active August 29, 2015 14:01 — forked from bnoordhuis/http-and-https-proxy.js
A node.js proxy listening on port 80 that forwards HTTP or SSH traffic to different ports. Thus SSH might become reachable to a somewhat restrictive hotel or corporate firewall, while HTTP can still be served as well.
var fs = require('fs');
var net = require('net');
var http = require('http');
var sshAddress = '22';
var httpAddress = '8080';
var incoming = '80';
http.createServer(httpConnection).listen(httpAddress);
net.createServer(tcpConnection).listen(incoming);
@matths
matths / parse.js
Created May 7, 2014 09:10
Line-by-line manipulation of text files (eg. error log files) using node.js' new Stream.Transform functionality and pipe(). You can call this directly from your shell, eg. $ node parse.js error.log
var fs = require('fs');
var TransformLine = require('./TransformLine');
// syntax example:
// $ node parse.js error.log
var inFile = process.argv[2];
var outFile = process.argv[3];
if (!inFile) {
@matths
matths / https2http.md
Created April 30, 2014 15:26
https2http Snippet

https2http Bookmarklet

Replace all occourences of "https" with "http" in the following tags.atrributes:

  • script.src
  • link.href
Array.prototype.slice.call(document.querySelectorAll('script')).map(function(v,i) { v.src = v.src.replace(/https/, 'http'); console.log(i, v.src);});Array.prototype.slice.call(document.querySelectorAll('link')).map(function(v,i) { v.href = v.href.replace(/https/, 'http'); console.log(i, v.href);});
@matths
matths / output.txt
Last active August 29, 2015 13:58
When beginning with node.js and modules, it's always difficult to understand the difference between exports and module.exports. Exports is a local reference to an empty plain object ({}), where module.exports is also referring to. But module.exports is what is assigned to the return value of the require() method, not exports. Changing exports to…
exports {}
module.exports {}
module.exports == exports YES
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
exports {}
module.exports function myExport() { console.log('an exported function instead of a plain object'); }
module.exports == exports NO
an exported function instead of a plain object