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 / 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 / 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 / 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'
@MarkTiedemann
MarkTiedemann / alphabet-stream.js
Last active March 16, 2017 18:39
Simple Readable Stream Example
const { Readable } = require('stream')
const charArray = 'abcdefghijklmnopqrstuvwxyz'.split('')
class AlphabetStream extends Readable {
constructor () {
super()
this.position = 0
}
@MarkTiedemann
MarkTiedemann / clear-docker.sh
Created March 31, 2017 22:41
Clear all docker containers and images
docker ps -a -q | xargs -r docker rm -f
docker images -a -q | xargs -r docker rmi -f
@MarkTiedemann
MarkTiedemann / parallel-jobs.ps1
Last active April 4, 2017 14:53
Run jobs in parallel using Powershell
$code = {
param ($id)
$start = Get-Date
# your code here
Start-Sleep 1
$stop = Get-Date
$total = ($stop - $start).TotalMilliSeconds
"[$id] $total ms"
}