Skip to content

Instantly share code, notes, and snippets.

View alfredwesterveld's full-sized avatar

Alfred Westerveld alfredwesterveld

View GitHub Profile
@alfredwesterveld
alfredwesterveld / index.js
Last active August 19, 2016 08:13
Keep printing to same line from [0, 100]. When done print done on same line and exit program.
const log = require('single-line-log').stdout
let i = 0
const id = setInterval(() => {
log(i++)
if (i === 100) {
clearInterval(id)
log.clear()
log('done\n')
@alfredwesterveld
alfredwesterveld / .npmrc
Last active August 11, 2016 13:31
add private npm token to .npmrc
touch .npmrc; grep -q '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' .npmrc || echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' >> .npmrc
@alfredwesterveld
alfredwesterveld / index.js
Created July 27, 2016 20:10
fake longpoll server
'use strict';
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
let i = 0;
const server = http.createServer((req, res) => {
'use strict';
const timestamp = 'timestamp: "{{timestamp}}"';
const title = 'title: "{{title}}"';
const file = 'file: "{{file}}"';
const line = 'line:"{{line}}"';
const method = 'method: "{{method}}"';
const message = 'message: "{{message}}"';
const jsonlogger = require('tracer').console({
format: `{${timestamp},${title},${file}, ${line},${method},${message}}`
@alfredwesterveld
alfredwesterveld / .gitignore
Last active June 17, 2016 16:53
tunnel insecure https to http
# Created by .ignore support plugin (hsz.mobi)
### Node template
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
@alfredwesterveld
alfredwesterveld / replace.sh
Created June 3, 2016 21:14
removing sample from extension => app.php.sample renamed as app.php
#!/bin/bash
# -n => test only
# rename -n 's/\.sample$//' *.sample
# Do it for real
rename 's/\.sample$//' *.sample
// https://github.com/cthackers/JSProfiler/blob/master/test.html
function readable(bytes, precision) {
var kilobyte = 1024,
megabyte = kilobyte * 1024,
gigabyte = megabyte * 1024,
terabyte = gigabyte * 1024;
precision = precision || 2;
if ((bytes >= 0) && (bytes < kilobyte)) {
return bytes + ' B';
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
var sharp = require('sharp');
var fs = require('fs');
// Read image data from readableStream, resize and write image data to writableStream
for (var i=0; i < 100; i++) {
var rs = fs.createReadStream('./direct.png');
var ws = fs.createWriteStream(`./thumbs/direct-thumb-${i}.png`);
rs.pipe(sharp()
.resize(437, 315)
// Does (still) have bad performance. But think can be fixed?
package main
import "fmt"
import "github.com/nfnt/resize"
import "github.com/rwcarlsen/goexif/exif"
import "net/http"
import "strings"
import "strconv"
package main
import (
"github.com/nfnt/resize"
"image/png"
"log"
"os"
)
func main() {