Skip to content

Instantly share code, notes, and snippets.

@3ZsForInsomnia
3ZsForInsomnia / discriminated-unions.ts
Last active July 28, 2020 21:19
Typescript expressive types workshop examples
/**
* `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 };
#!/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):
@3ZsForInsomnia
3ZsForInsomnia / funWithPatternMatching.ts
Created January 11, 2020 17:06
Exploring a ts article on scala's pattern matching and another approach
interface IShape {
area: number;
sayHi(...args: any[]): string;
type: string;
}
interface Circle extends IShape {
type: 'circle';
}
interface Rectangle extends IShape {
@3ZsForInsomnia
3ZsForInsomnia / lensCompositionFun.js
Created January 2, 2020 13:33
Simple example of nice, clean lens composition in ramda using a helper
const nameLens = R.lensProp('name');
const user = {
name: 'Joe',
age: 34,
isLoggedIn: true,
address: {
number: 123,
street: 'best'
}
@3ZsForInsomnia
3ZsForInsomnia / setLatestConfig.sh
Last active December 25, 2019 21:36
Set latest config using gist cli
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
@3ZsForInsomnia
3ZsForInsomnia / pullLatestConfig.sh
Last active December 25, 2019 21:36
Pull the latest config using gist cli
# 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
@3ZsForInsomnia
3ZsForInsomnia / .nvimrc
Last active September 29, 2021 11:50
Vimrc
" set syntax=on
" syntax on
" set termguicolors
set noswapfile
" set t_Co=256
set ignorecase
set spelllang=en
@3ZsForInsomnia
3ZsForInsomnia / abstracted-extensions.js
Last active March 15, 2018 15:05
A React component that shows a comparison of checks using no constants, with open checks of constants, and with abstracted constants
import React from 'react'
const teacher = 'teacher';
const student = 'student';
const isTeacher = (userType) => {
return userType === teacher;
}
const isStudent = (userType) => {
@3ZsForInsomnia
3ZsForInsomnia / detectWhenPageIsLoaded.js
Last active February 12, 2018 20:20
Quick, ES5-based method for detecting when a page has (probably) fully loaded without relying on the "onload" event
/*
* 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,
@3ZsForInsomnia
3ZsForInsomnia / video-player-excerpt.jsx
Last active December 1, 2017 01:16
Example of method wrapped usage of constants
// 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() {