Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View DonMartin76's full-sized avatar
🤓
Crunch Time

Martin Danielsson DonMartin76

🤓
Crunch Time
View GitHub Profile
'use strict';
/* eslint-disable no-console */
// npm i smtp-server
// npm i mailparser
// https://nodemailer.com/extras/smtp-server/
// https://nodemailer.com/extras/mailparser/
@DonMartin76
DonMartin76 / gluecksspiel.js
Created April 26, 2019 12:49
Marc Elsberg - Gier - Glücksspiel-Simulation
'use strict';
// const BUCKETS = [0, 100, 500, 1000, 1500, 2000, 2500, 3000, 4500, 5000, 13150];
const ROUNDS = 100;
const ITERATIONS = 10000000.0;
const BUCKETS = [0, 1, 2.5, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 13150];
function initBuckets() {
const buckets = {};
for (let b of BUCKETS) {
@DonMartin76
DonMartin76 / azure-file-download.js
Last active October 14, 2018 09:53
Snippet in node.js to download a file from an Azure Files SMB Share using the REST API
'use strict';
// Uses request: npm install --save request
const request = require('request');
const fs = require('fs');
const crypto = require('crypto');
const dummyLog = function (s) {
console.log(s);
}
@DonMartin76
DonMartin76 / prometheus-middleware.js
Last active March 7, 2018 11:52
Middleware for auto instrumenting Express per Route with Prometheus histograms and status code statistics
'use strict';
// Needs:
// - npm install prom-client --save --save-exact
// - Express
//
// Usage:
// const promMiddleware = require('./prometheus-middleware');
//
// app.use(promMiddleware.middleware('some_prefix'[, options]));
'use strict'
// This is for winston < 3.0.0 (e.g. 2.4.0), unfortunately works
// differently in winston 3.0.0+
const winston = require('winston');
const logger = new (winston.Logger)({
transports: [
new (winston.transports.Console)({
timestamp: function () {
@DonMartin76
DonMartin76 / wicked_CLA.md
Last active May 22, 2018 19:34
wicked.haufe.io Contributor License Agreement

Contributor License Agreement

The following terms are used throughout this agreement:

  • You - the person or legal entity including its affiliates asked to accept this agreement. An affiliate is any entity that controls or is controlled by the legal entity, or is under common control with it.
  • Project - is an umbrella term that refers to any and all open source projects in the apim-haufe-io GitHub organization, maintained by Haufe Group.
  • Contribution - any type of work that is submitted to a Project, including any modifications or additions to existing work.
  • Submitted - conveyed to a Project via a pull request, commit, issue, or any form of electronic, written, or verbal communication with Haufe Group contributors or maintainers.

1. Grant of Copyright License.

@DonMartin76
DonMartin76 / template.sh
Last active March 2, 2017 15:55
Quick, ugly, efficient bash script for templating files - takes everything ending with .template and replaces env vars inside them
#!/bin/bash
for tmpl in $(find . | grep '\.template'); do
targetFile=${tmpl%.*}
echo "Templating ${tmpl} to ${targetFile}..."
perl -pe 's;(\\*)(\$([a-zA-Z_][a-zA-Z_0-9]*)|\$\{([a-zA-Z_][a-zA-Z_0-9]*)\})?;substr($1,0,int(length($1)/2)).($2&&length($1)%2?$2:$ENV{$3||$4});eg' $tmpl > $targetFile
done
'use strict';
let i = 2;
let done = false;
while (!done) {
console.log("Checking " + i);
const i3 = i.toString(3);
const i4 = i.toString(4);
const i5 = i.toString(5);