Skip to content

Instantly share code, notes, and snippets.

View mStirner's full-sized avatar

Marc Stirner mStirner

View GitHub Profile
@mStirner
mStirner / http.cluster.js
Created September 7, 2018 18:10
nodejs cluster without redis, support sticky balancing / websockets
const cluster = require("cluster");
const http = require("http");
const os = require("os");
const net = require("net");
const ip = require('ip');
// create seed
const seed = (Math.random() * 0xffffffff) | 0;
/**
@mStirner
mStirner / http.master.js
Created September 7, 2018 18:28
HTTP cluster, load balancing, witout redis. Support socket.io / user logins / cookies
const net = require("net");
const ip = require('ip');
const os = require("os");
const cluster = require("cluster");
module.exports = function (seed) {
/**
* Hash IP
@mStirner
mStirner / client.js
Created September 30, 2018 11:10
UDP Service discover, node.js
const dgram = require("dgram");
var client = dgram.createSocket("udp4");
client.on("message", function(data, remote){
let str = data.toString("utf8");
let obj = JSON.parse(str);
@mStirner
mStirner / upload.js
Created October 24, 2018 17:49
Express/Multer http upload
const os = require("os");
const fs = require("fs");
const path = require("path");
const express = require('express');
const multer = require('multer');
const bodyParser = require('body-parser');
// build/normalize paths
const src = path.resolve(os.tmpdir(), "uploads");
@mStirner
mStirner / README.md
Last active August 4, 2019 17:15
Pioneer & Onkyo eISCP wrapper

node command.js --cmd=PWR01 Power On
node command.js --cmd=PWR00 Power Off
node command.js --cmd=MVL010 Master volume = 10
node command.js --cmd=MVL000 Master volume = 0\

const events = require("events").EventEmitter;
/*
Added complex matches by Shimon Doodkin 2012
Developed by Elijah Rutschman 2009 - http://elijahr.blogspot.com/2009/03/javascript-cron.html
*/
/*
a typical cron entry has either wildcards (*) or an integer:
@mStirner
mStirner / README.md
Created March 22, 2020 00:51
*tgz verification (for signed plugins)
  • Quick & dirty tar.gz/.tgz verification
  • add extra header filed
  • sub header contains:
    • Author information (email & name)
    • Signature from server (public + private key)

lib coming soon...

@mStirner
mStirner / fingerprint.js
Created March 29, 2020 22:29
canvas fingerprint
var makeCRCTable = function(){
var c;
var crcTable = [];
for(var n =0; n < 256; n++){
c = n;
for(var k =0; k < 8; k++){
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
}
crcTable[n] = c;
}
@mStirner
mStirner / README.md
Last active March 20, 2022 21:21
Lightweight, stream based, expandable, node.js logger with zero dependencies

This is a example of a very lightweight, stream based, node.js logger. It creates a "record" object for each log call, and pipe it throught the spicified streams. In the streams its possible to modifie the record, format the message, and many more.

Bunyan, there is no one responding on issues, Winstons is way to big and have unecesseray dependencies.

I wanted a lightweight, easy to use, expandable, stream based, logging utily with zero dependencies. You can all merge this down into a single file. You bascily need class.logger.js & levels.js which can simple merged into a single file.

The other files (demo.js, formatter.js) are for demonstration & formatting and not needed for the functionality.

@mStirner
mStirner / adapter.js
Created April 26, 2022 19:47
WebSocket l4 adapter minimal reproducible example
const { Transform } = require("stream");
module.exports = () => {
let encode = new Transform({
transform(chunk, encoding, cb) {
console.log("[encode]", chunk);
cb(null, chunk);