Skip to content

Instantly share code, notes, and snippets.

View MarkTiedemann's full-sized avatar

Mark Tiedemann MarkTiedemann

View GitHub Profile
@MarkTiedemann
MarkTiedemann / README.md
Created November 23, 2015 19:04
Using Next Generation Node

Using Next Generation Node

Features

ES6 (ES2015)

🚩 TODO Explain some ES6 language features

ES7 (ES2016)

@MarkTiedemann
MarkTiedemann / README.md
Created November 29, 2015 23:20
Promisifying A Callback-based Function In Node 5

Promisifying A Callback-based Function In Node 5

Node 5 is awesome! <3 By default, it comes with lots of ES6 features.

Among them are, for example, arrow functions. And there's the spread operator which, in combination with the arguments object, makes writing a promisify() function beautifully simple:

function promisify (foo) {
 return function () {
@MarkTiedemann
MarkTiedemann / README.md
Last active December 3, 2015 18:00
A Simple Node.js File Server for Bluemix with Superstatic by Firebase

A Simple Node.js File Server for Bluemix with Superstatic by Firebase

Step 1: Install Superstatic

npm install superstatic

Step 2: Create File Server

@MarkTiedemann
MarkTiedemann / README.md
Last active January 16, 2016 21:59
Building A Simple Countdown Clock

Building A Simple Countdown Clock

Live example: http://codepen.io/abk955/pen/YwQmMJ

1. Creating the clock structure (in Jade)

  • The countdown clock is supposed to display seconds, minutes, hours and days.
@MarkTiedemann
MarkTiedemann / README.md
Last active July 18, 2021 11:42
An Easier Way to Enforce Required Parameters in ES6

An Easier Way to Enforce Required Parameters in ES6

Expands on Handling required parameters in ECMAScript 6 by Axel Rauschmayer.

The idea (which is credited to Allen Wirfs-Brock) is, in essence, to use default parameter values to call a function which throws an Error if the parameter is missing:

const throwIfMissing () => { throw new Error('Missing parameter') }
@MarkTiedemann
MarkTiedemann / file-gen.js
Last active February 10, 2017 21:27
Generate a random file with a specified size
#!/usr/bin/env node
/* Usage: node file-gen [mb]
*
* Example: Generate a 1 GB file
* $ node file-gen 1024
* time: 9163.383ms
*/
const fs = require('fs')
@MarkTiedemann
MarkTiedemann / power-query-pagination.m
Last active March 5, 2024 23:43
Power Query Pagination Example
let
BaseUrl = "https://fake-odata-api.com/v1/Entities?",
Token = "F4K3-T0K3N-D0NT-U5E-L0L",
EntitiesPerPage = 1000,
GetJson = (Url) =>
let Options = [Headers=[ #"Authorization" = "Bearer " & Token ]],
RawData = Web.Contents(Url, Options),
Json = Json.Document(RawData)
in Json,
@MarkTiedemann
MarkTiedemann / clean.cmd
Last active March 2, 2017 23:10
Remove files and directories via batch script
@ECHO off
:: delete all upgrade logs
:: >nul 2>&1 = drop stdout and stderr output
DEL UpgradeLog*.htm >nul 2>&1
:: loop over all backup directories
FOR /d %%G IN (Backup*) DO (
:: /s = remove all sub directories, too
:: /q = remove quietly, without confirmation
@MarkTiedemann
MarkTiedemann / download.cmd
Created March 2, 2017 23:11
Download file and print content via batch script
@ECHO off
SET downloadUrl=https://api.github.com/users/marktiedemann
SET tempFile=%cd%\.%random%-tmp
BITSADMIN /transfer /download %downloadUrl% %tempFile% >nul
TYPE %tempFile%
DEL %tempFile%
@MarkTiedemann
MarkTiedemann / index.js
Last active March 13, 2017 17:26
Bare Bones Node.js HTTP Proxy
const http = require('http')
const url = require('url')
const apiPort = 3000
const proxyPort = 3001
const apiResStatus = 200
const apiResBody = `"Hi, I'm the API!"`
const clientReqMethod = 'GET'