View discriminated-unions.ts
/** | |
* `kind` is what is called a "discriminator", as it allows us to determine (at runtime) | |
* what type the returned data is, _without_ relying on introspection of the values in the data. | |
* | |
* This let's us do "if (claim.kind === 'prescription') ...", which is much less fragile or "hacky" than | |
* "if (Object.keys(claim).includes('surgeryType') ..." | |
*/ | |
type surgicalProcedure = { kind: 'surgicalProcedure'; surgeryType: string }; | |
type prescription = { kind: 'prescription'; refillsAllowed: number; medicationName: string }; |
View Simple HTTP server
#!/usr/bin/env python3 | |
""" | |
Very simple HTTP server in python for logging requests | |
Usage:: | |
./server.py [<port>] | |
""" | |
from http.server import BaseHTTPRequestHandler, HTTPServer | |
import logging | |
class S(BaseHTTPRequestHandler): |
View funWithPatternMatching.ts
interface IShape { | |
area: number; | |
sayHi(...args: any[]): string; | |
type: string; | |
} | |
interface Circle extends IShape { | |
type: 'circle'; | |
} | |
interface Rectangle extends IShape { |
View lensCompositionFun.js
const nameLens = R.lensProp('name'); | |
const user = { | |
name: 'Joe', | |
age: 34, | |
isLoggedIn: true, | |
address: { | |
number: 123, | |
street: 'best' | |
} |
View setLatestConfig.sh
gist -u 234409331d0e01851a5e4cf1402c604d ~/pullLatestConfig.sh | |
gist -u 005449d0adaa90d798f4bc0b93bebe27 ~/.bookmarks | |
brew list > brewList.txt | |
gist -u 8dade12e382afa0be6ee59d1b6b73d05 ~/brewList.txt | |
gist -u 903202277e1f22dd06fbc7127363c795 ~/.bashrc | |
gist -u d968207d98c8984849ca2f7349e8ac48 ~/.bash_profile | |
gist -u ed2ac2193c29b43b07a56ffb5b55d8fd ~/.vimrc | |
gist -u f05dabf617e353a98f5faa051704dafb ~/.zshrc |
View pullLatestConfig.sh
# get 8ball.sh | |
curl https://gist.githubusercontent.com/3ZsForInsomnia/d51754d5b1359f30b4c203fe30ab9ce5/raw/8c058a423826736e35c8359f5f720fd63f40d17a/8ball.sh > 8ball.sh | |
chmod +x 8ball.sh | |
# get pomo.sh | |
curl https://gist.githubusercontent.com/3ZsForInsomnia/38904db41b40eee4498d1cf5e416ad50/raw/6f19a47d241152540284148473da49e60d982f15/pomo.sh > pomo.sh | |
chmod +x pomo.sh | |
# get bookmarks for zshmarks | |
curl https://gist.githubusercontent.com/3ZsForInsomnia/005449d0adaa90d798f4bc0b93bebe27/raw/99980283642d6b780dd4e4a7e9ca2e31ba203250/.bookmarks > .bookmarks |
View .nvimrc
set syntax=on | |
syntax on | |
set noswapfile | |
set ignorecase | |
set spelllang=en | |
set spellfile=~/.vim/spell/en.utf-8.add | |
set nospell |
View abstracted-extensions.js
import React from 'react' | |
const teacher = 'teacher'; | |
const student = 'student'; | |
const isTeacher = (userType) => { | |
return userType === teacher; | |
} | |
const isStudent = (userType) => { |
View detectWhenPageIsLoaded.js
/* | |
* Explanation of approach | |
* Check if an element exists with the tag, class, or id of "loading" | |
* Wait half of interval for things to load/setup/render | |
* If a "loading" element was found, check if it is visible every time the interval fires | |
* If the targeted element is not visible when checked, assume loading is complete | |
* If the targeted element is visible but is changed after the initial timeout, assume that loading is complete | |
* If no "loading" element is found, then watch <body> for changes | |
* This causes us to check for when <body> has not been modified for 3 seconds | |
* While this does add performance overhead (it is called every time <body> or any element below it is modified, |
View video-player-excerpt.jsx
// Import the constants file | |
const VideoPlayerComponent = React.createClass({ | |
getInitialState: function() { | |
return { | |
// Default view - it does not matter how or when it is updated, so that is left out | |
view = views.viewing | |
}; | |
}, | |
render: function() { |