Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
# Input file
FILE=/tmp/test.txt
# How many seconds before file is deemed "older"
OLDTIME=120
# Get current and file times
CURTIME=$(date +%s)
FILETIME=$(stat $FILE -c %Y)
TIMEDIFF=$(expr $CURTIME - $FILETIME)
#!/bin/bash
function try()
{
[[ $- = *e* ]]; SAVED_OPT_E=$?
set +e
}
function throw()
{
#!/bin/bash
DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
# Loads named arguments for script (ie. ./script.sh --some-arg some_arg_value)
# Supports "--" as prefix. If no value is supplied to an entry, then
# it defaults to `true` as the value.
# This script can be used in other scripts by referance: `. ./load_args.sh`.
while [ $# -gt 0 ]; do
if [[ $1 == "--"* ]]
then # Parse command/option.
key="${1/--/}"
val=$2
if [[ $key == *"="* ]]; then # Handle args with equals sign.
@lukaswelinder
lukaswelinder / typed_immutable.d.ts
Created July 4, 2020 03:07
Typescript Interfaces for Immutable.js Structs - Early Draft
import { Seq } from 'immutable';
type RequiredLiteralKeys<T> = {
[K in keyof T]-?: string extends K
? never
: number extends K
? never
: {} extends Pick<T, K>
? never
: K;
@lukaswelinder
lukaswelinder / immutable_intersect.js
Last active June 28, 2019 12:22
Deeply Intersect Immutable.js Structures.
import { Map, List, Set, Seq, fromJS } from 'immutable';
// keyPaths(val: any, root: Seq)
// - Deeply maps iterable keypaths.
const keyPaths = (val, root = new Seq()) => {
if(typeof val !== 'object')
return [root];
return new Seq(val).reduce((curr, value, key) =>
curr.concat(keyPaths(value, root.concat(key))), new Seq());
};