Skip to content

Instantly share code, notes, and snippets.

View thesephist's full-sized avatar
🍷
Ridin' in a getaway car

Linus Lee thesephist

🍷
Ridin' in a getaway car
View GitHub Profile
#!/usr/bin/env node
var request = require('request');
var given = process.argv.splice(2);
function command(args) {
var payload = {};
if (args[0]) payload.power = args[0];
if (parseFloat(args[1])) payload.brightness = parseFloat(args[1]);
@thesephist
thesephist / rank.js
Created October 20, 2016 07:35
Recursive ranking function calculator
#!/usr/bin/env node
'use strict';
// memoization: factorial of n is FACTORIALS[n]
const FACTORIALS = [0, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 620448401733239439360000, 15511210043330985984000000, 403291461126605635584000000, 10888869450418352160768000000, 304888344611713860501504000000, 8841761993739701954543616000000, 265252859812191058636308480000000, 8222838654177922817725562880000000, 263130836933693530167218012160000000, 8683317618811886495518194401280000000, 295232799039604140847618609643520000000, 10333147966386144929666651337523200000000, 371993326789901217467999448150835200000000, 13763753091226345046315979581580902400000000, 523022617466601111760007224100074291200000000, 20397882081197443358640281739902897356800000000, 8159152832478977343456112695961158942720000
@thesephist
thesephist / scrollreveal.js
Created November 24, 2016 05:27
Detector for if an element is in-viewport
const THRESHOLD = 0.8; // I find this to be a good number
function isInViewPort(el) {
// getBoundingClientRect() compared with body scrolltop and innerHeight
const BCR = el.getBoundingClientRect();
const elTop = BCR.top;
const elWidth = BCR.height;
return (elTop > 0 && elTop < THRESHOLD * window.innerHeight) || elTop < 0;
@thesephist
thesephist / scrollreveal.scss
Created November 24, 2016 05:28
Detector for if an element is in-viewport (SCSS portion)
.js {
// javascript executing environment
.reveal {
transition: opacity .8s, transform .7s;
opacity: 0;
transform: translateY(50px);
&.appear {
opacity: 1;
transform: translateY(0);
@thesephist
thesephist / ytfixer.js
Created December 24, 2016 05:42
Youtube Bookmarklets
console.log("YTFixer Enabled");var xsp=document.getElementById("player"),xsh=document.getElementById("placeholder-player"),xsw=document.getElementById("watch7-content"),xst,xso,xsn=document.getElementById("watch7-sidebar-contents");function YTFix(){xst=document.getElementById("theater-background").clientHeight;xtn=(xst+10).toString()+"px";xsp.style.position="fixed";xsh.style.display="none";xsp.style.top="62px";xsp.style.zIndex="10";xsw.style.position="relative";xsw.style.top=xtn;if(xst==720){xsp.style.marginLeft="calc(50% - 853px)"}else if(xst==480){xsp.style.marginLeft="calc(50% - 640px)"}else if(xst==360){xsp.style.marginLeft="calc(50% - 533px)"}else if(xst==240){xsp.style.marginLeft="calc(50% - 213px)"}else{xsp.style.marginLeft="100px"}if(window.innerWidth<=1084 && window.innerWidth>640){xsp.style.marginLeft="0"};if(window.innerWidth>640){xsn.style.position="relative";xsn.style.top=xtn}console.log("YT Video Fixed by YTFixer")};function hashX(){if(window.location.href.indexOf("://www.youtube.com/watch")>-1)
@thesephist
thesephist / bbpr.js
Last active November 27, 2017 21:41
A simple script that I use to pipe BitBucket push message into it and auto-open a browser page for the PR.
#!/usr/bin/env node
var exec = require('child_process').exec
// accept input from pipe in
var data = ''
var IN = process.stdin
IN.resume()
IN.setEncoding('utf8')
@thesephist
thesephist / darwin.js
Created May 6, 2018 02:15
Mutation rate vs. Population Simulation
// Constants
const M_RATES = [
0,
0.001,
0.01,
0.1,
];
const POP_SIZE = 100;
const GENERATIONS = 50;
@thesephist
thesephist / index.html
Created May 24, 2018 18:34
Highway Lane Changes Simulation
// This is pretty crude. I didn't really care though since it was
// mostly something fueled by curiosity after a long road trip
// and wasn't intended to capture things like collisions / AI control of speeds.
// All code in this file is licensed under the MIT License.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
@thesephist
thesephist / index.html
Created May 26, 2018 09:08
TypeScript Todo Example (incl. baseline webpack + tsconfig)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>TypeScript Practice</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: sans-serif;
@thesephist
thesephist / main.js
Created May 29, 2018 15:38
Polymer / WebComponents Todo Example
import {LitElement, html} from '@polymer/lit-element';
let __taskid_ref = 0;
const taskid = () => {
return __taskid_ref ++;
}
class PolyItem extends LitElement {
static get properties() {