Skip to content

Instantly share code, notes, and snippets.

@souporserious
souporserious / args.js
Created June 25, 2021 05:26
Parse Node args using Object.fromEntries.
const args = Object.fromEntries(
process.argv.slice(2).map((arg) => {
const [key, value] = arg.split('=')
return [key.slice(2), value]
})
)
// input: --port=3000 --out=dist
// output: { port: '3000', out: 'dist' }
@scottrippey
scottrippey / template-helpers example.js
Last active February 13, 2019 10:49
ES6 Template Helpers
import { unindent, repeat, truthy } from "template-helpers";
function createMessage(user, notifications) {
return unindent(truthy`
Hello, ${ user.name }!
${(notifications.length > 0) && truthy`
You have ${ notifications.length } new notification${ (notifications.length > 1) && "s" }.
${repeat(notifications, notification => truthy`
* ${ notification.title } ${ notification.important && "!" }
`)}
@Buthrakaur
Buthrakaur / PingUrlParallel.ps1
Created December 4, 2015 15:10
Simple load test tool in powershell
workflow PingUrlParallel {
param(
[string]$url,
[int]$parallelCount = 10,
[int]$iterations = 10
)
foreach -parallel ($x in 1..$parallelCount) {
1..$iterations | %{
@Stuk
Stuk / exec.js
Created August 14, 2013 00:15
Wrap Node's `child_process.spawn` with a promise interface that rejects if the process has an error, or exits with a code other than zero.
var spawn = require("child_process").spawn;
var Q = require("q");
/**
* Wrap executing a command in a promise
* @param {string} command command to execute
* @param {Array<string>} args Arguments to the command.
* @param {string} cwd The working directory to run the command in.
* @return {Promise} A promise for the completion of the command.
*/