Skip to content

Instantly share code, notes, and snippets.

🤓
Crunch Time

Martin Danielsson DonMartin76

🤓
Crunch Time
Block or report user

Report or block DonMartin76

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View raetsel.js
'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);
@DonMartin76
DonMartin76 / template.sh
Last active Mar 2, 2017
Quick, ugly, efficient bash script for templating files - takes everything ending with .template and replaces env vars inside them
View template.sh
#!/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
View logger.js
'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 / prometheus-middleware.js
Last active Mar 7, 2018
Middleware for auto instrumenting Express per Route with Prometheus histograms and status code statistics
View prometheus-middleware.js
'use strict';
// Needs:
// - npm install prom-client --save --save-exact
// - Express
//
// Usage:
// const promMiddleware = require('./prometheus-middleware');
//
// app.use(promMiddleware.middleware('some_prefix'[, options]));
@DonMartin76
DonMartin76 / wicked_CLA.md
Last active May 22, 2018
wicked.haufe.io Contributor License Agreement
View wicked_CLA.md

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 / azure-file-download.js
Last active Oct 14, 2018
Snippet in node.js to download a file from an Azure Files SMB Share using the REST API
View azure-file-download.js
'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 / gluecksspiel.js
Created Apr 26, 2019
Marc Elsberg - Gier - Glücksspiel-Simulation
View gluecksspiel.js
'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) {
View smtp-server.js
'use strict';
/* eslint-disable no-console */
// npm i smtp-server
// npm i mailparser
// https://nodemailer.com/extras/smtp-server/
// https://nodemailer.com/extras/mailparser/
You can’t perform that action at this time.