Skip to content

Instantly share code, notes, and snippets.

@chapmanjacobd
chapmanjacobd / swimming.ts
Last active Aug 13, 2020
swimlanes.io to XState FSM
View swimming.ts
swimlaneToXState(`
idle -> loading: fetch
loading -> success: resolve
loading -> failure: reject
failure -> loading: retry
`);
export function swimlaneToXState(swimlane: string) {
const initial = swimlane.split("->")[0].trim();
const states = swimlane
@rundef
rundef / merge-nyc-code-coverage-reports.js
Last active Oct 2, 2020
Script to merge multiple nyc/istanbul code coverage json reports into a single html report: http://rundef.com/typescript-code-coverage-istanbul-nyc
View merge-nyc-code-coverage-reports.js
var path = require('path'),
fs = require('fs'),
libCoverage = require('nyc/node_modules/istanbul-lib-coverage'),
libReport = require('nyc/node_modules/istanbul-lib-report'),
reports = require('nyc/node_modules/istanbul-reports');
var rootFolder = __dirname;
var mergeIntoFolder = 'final';
var files = fs.readdirSync(rootFolder);
var mergedCoverageMap = null;
@JosefJezek
JosefJezek / the-10-commandments-of-modern-web-application.md
Last active Jun 12, 2020
The 10 Commandments of Modern Web Application
View the-10-commandments-of-modern-web-application.md
@pkuczynski
pkuczynski / parse_yaml.sh
Last active Nov 27, 2020
Read YAML file from Bash script
View parse_yaml.sh
#!/bin/sh
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
@earthgecko
earthgecko / bash.generate.random.alphanumeric.string.sh
Last active Nov 29, 2020
shell/bash generate random alphanumeric string
View bash.generate.random.alphanumeric.string.sh
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
@cjus
cjus / jsonval.sh
Created Jun 26, 2011
Extract a JSON value from a BASH script
View jsonval.sh
#!/bin/bash
function jsonval {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop`
echo ${temp##*|}
}
json=`curl -s -X GET http://twitter.com/users/show/$1.json`
prop='profile_image_url'
picurl=`jsonval`
You can’t perform that action at this time.