Skip to content

Instantly share code, notes, and snippets.

type IsoFn<T> = {
(param: T): T;
}
interface User {
id: number;
name: string;
address: string;
}
interface User {
id: number;
name: string;
address: string;
}
interface UserStringAttrFunc {
(user: User): string;
}
const getName: UserStringAttrFunc = path('name');
const getAddress: UserStringAttrFunc = path('address');
interface User {
id: number;
name: string;
address: string;
}
interface UserStringAttrFunc {
(user: User): string;
}
interface User {
id: number;
name: string;
address: string;
}
const getName = (user: User): string => user.name;
const getName = path('name');
const upperCase = (str) => str.toUpperCase();
const shoutName = pipe(
getFirstName,
upperCase,
);
@amdilley
amdilley / post-checkout.sh
Last active March 26, 2019 16:21
Scans and caches working directory for JIRA tickets matching that referenced in branch name
#!/bin/bash
# Pulls JIRA ID from current branch
JIRA_ID=$(git branch | grep \* | grep -Eo '([A-Z]*-[0-9]*)' | head -n1)
# Only scan if JIRA ID found
if [[ -n "$JIRA_ID" ]]; then
TMP=$GIT_DIR/hooks/$JIRA_ID.txt
touch $TMP
# Write all matching TODOs to $TMP
@amdilley
amdilley / pre-commit.sh
Last active March 22, 2019 17:45
Scans current directory for JIRA tickets matching that referenced in branch name.
#!/bin/bash
# Excluding build/bin/lib directories and uncommented files
# this will scan the current dir for any JIRA ticket refs
# matching that found in the current git branch name.
# Example:
# current branch -> feature/DAS-1234-do-task
# greps for DAS-1234 and fails commit if found
CR=$'\n'
@amdilley
amdilley / tweetThread.js
Last active May 30, 2019 02:44
Compiles text backward from a specified tweet URL
const fetch = require('isomorphic-fetch');
const R = require('ramda');
const formatTweetText = R.pipe(
R.replace(/(?<=data-expanded-url="[^"]+)".*/, ''),
R.replace(/<a href=.*data-expanded-url="/, '\n'),
R.replace(/&quot;/g, '"')
);
const parseTweetText = R.pipe(
@amdilley
amdilley / animateUntil.js
Created January 25, 2019 05:06
Promise "animating" a sequence of characters until specified callback returns false.
const sleep = ms => new Promise(res => setTimeout(res, ms));
const animationCharGenerator = async function* (chars, rate = 5) {
const interval = 1000 / rate;
const numChars = chars.length;
let i = 1;
// return first char with no delay
yield chars[0];