Skip to content

Instantly share code, notes, and snippets.

Avatar

3ZsForInsomnia

View GitHub Profile
@3ZsForInsomnia
3ZsForInsomnia / discriminated-unions.ts
Last active Jul 28, 2020
Typescript expressive types workshop examples
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):
@3ZsForInsomnia
3ZsForInsomnia / funWithPatternMatching.ts
Created Jan 11, 2020
Exploring a ts article on scala's pattern matching and another approach
View funWithPatternMatching.ts
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 Jan 2, 2020
Simple example of nice, clean lens composition in ramda using a helper
View lensCompositionFun.js
const nameLens = R.lensProp('name');
const user = {
name: 'Joe',
age: 34,
isLoggedIn: true,
address: {
number: 123,
street: 'best'
}
View .vimrc
syntax on
set ignorecase
set spelllang=en
set spellfile=~/.vim/spell/en.utf-8.add
" set shellcmdflag=-ic
let mapleader=" "
@3ZsForInsomnia
3ZsForInsomnia / pullLatestConfig.sh
Last active Dec 25, 2019
Pull the latest config using gist cli
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
@3ZsForInsomnia
3ZsForInsomnia / setLatestConfig.sh
Last active Dec 25, 2019
Set latest config using gist cli
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
@3ZsForInsomnia
3ZsForInsomnia / abstracted-extensions.js
Last active Mar 15, 2018
A React component that shows a comparison of checks using no constants, with open checks of constants, and with abstracted constants
View abstracted-extensions.js
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 Feb 12, 2018
Quick, ES5-based method for detecting when a page has (probably) fully loaded without relying on the "onload" event
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,
@3ZsForInsomnia
3ZsForInsomnia / video-player-excerpt.jsx
Last active Dec 1, 2017
Example of method wrapped usage of constants
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() {
You can’t perform that action at this time.