Skip to content

Instantly share code, notes, and snippets.

View enriched's full-sized avatar

Rich Adams enriched

  • Seattle, WA
View GitHub Profile
@enriched
enriched / usefulbashping.sh
Last active May 2, 2016 19:20
Ping with packet loss % and millisec output
usefulbashping()
{
read loss rttavg <<< $(ping -q -c 100 -w 60 -A $1 | \
awk 'BEGIN {FS="[/ ]"}; /loss/ {print substr($6,0,length($6))}; /rtt/ {print $9*1000}')
}
@enriched
enriched / completebasedonfile.sh
Created May 2, 2016 19:21
bash command completion based on lines in a file
_list_from_file()
{
local curr_arg;
curr_arg=${COMP_WORDS[COMP_CWORD]}
filelines=$(cat /some/file)
COMPREPLY=( $(compgen -W "$filelines" -- $curr_arg) );
}
@enriched
enriched / ngreplocalport.sh
Created May 2, 2016 19:24
ngrep local loopback port .bash_profile function
ngreplocalport(){
sudo ngrep -q -W byline -d lo0 '' "port $1";
}
@enriched
enriched / foreachdir.sh
Created May 2, 2016 19:25
Bash for each directory in current folder
# you can add this little gem to your .bash_profile to run a command inside of each directory in the current folder
# eg: foreachdir 'git status'
foreachdir() { /usr/bin/find . -type d -mindepth 1 -maxdepth 1 -exec sh -c "(cd {} && echo '\033[0;31m// '\$PWD'------>\033[0m' && $1)" ';' ; }
@enriched
enriched / awkeval.sh
Created May 2, 2016 19:26
Floating point math in bash without bc (using awk)
#!/bin/bash
# Uses awk to do the comparison so it can handle floating point numbers
awke()
{
echo "$1 $3" | awk '{ print ($1 '"$2"' $2) }'
}
awke '3.124' '*' '6'
@enriched
enriched / jsonSchemaInterface.ts
Last active December 8, 2023 07:28
TypeScript interface for Json-Schema V4
/**
* MIT License
*
* Copyright (c) 2016 Richard Adams (https://github.com/enriched)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@enriched
enriched / durable.ts
Created May 23, 2016 18:07
Typescript definitions for durable
var durable: DurableStatic = require('durable');
export {durable};
export interface DurableStatic {
state: <M extends EventBase, S extends StateBase>(name: string) => State<M, S>;
statechart: <M extends EventBase, S extends StateBase>(name: string) => Statechart<M, S>;
stage: <M extends EventBase, S extends StateBase>(name: string) => Stage<M, S>;
flowchart: <M extends EventBase, S extends StateBase>(name: string) => Flowchart<M, S>;
ruleset: <M extends EventBase, S extends StateBase>(name: string) => Ruleset<M, S>;
@enriched
enriched / keybase.md
Created July 29, 2016 03:56
keybase.md

Keybase proof

I hereby claim:

  • I am enriched on github.
  • I am enriched (https://keybase.io/enriched) on keybase.
  • I have a public key whose fingerprint is 4647 E8D8 7A94 3EE9 14D1 3A29 C0F0 DA43 480F 6E04

To claim this, I am signing this object:

@enriched
enriched / run-in-folder.sh
Created August 2, 2017 00:50
Run Bash command in another folder
run-in-folder ()
{
CUR_PWD=$PWD;
cd $1;
eval "${@:2}";
cd $CUR_PWD;
}
@enriched
enriched / extract_npm_token.sh
Created September 12, 2017 19:57
Get NPM Token from .npmrc
if [ -z "$NPM_TOKEN" ]; then
NPM_TOKEN=$(sed -En 's|^//registry\.npmjs\.org/:_authToken=(.*)|\1|p' ~/.npmrc);
fi