Skip to content

Instantly share code, notes, and snippets.

View fitsum's full-sized avatar
💭
npx fitsum

ፍፁም fitsum

💭
npx fitsum
View GitHub Profile
@fitsum
fitsum / nextNumOfType.js
Last active April 26, 2024 05:24
get next even or odd number given n
nextNumOfType = (n, d) => {
let opts = {true: {'even': 2,'odd': 1}, false:{'even': 1,'odd': 2}}
return n + opts[n%2 == 0][d];
}
nextNumOfType(3,'odd') // 5
nextNumOfType(3,'even') // 4
nextNumOfType(4,'odd') // 5
nextNumOfType(4,'even') // 6
const r = document.querySelector('input[type="range"]'),
initVal = 20,
story = [];
let currVal = null;
r.value = initVal;
r.addEventListener('change', (e) => {
let finalVal = e.target.value,
@fitsum
fitsum / replacing-in-pairs.js
Last active April 26, 2024 05:24
replaces array items in pairs
console.clear()
let used = [],
replaced = []
/*
TODO: only needed for early testing. can del
len = 20,
createArr = function(N) {
return Array.apply(null, {
length: N
@fitsum
fitsum / transform-selected-text.js
Last active April 26, 2024 05:24
CSS transform selected text - NEEDS WORK
// From browser source/snippets
// TODO: use selection API
// IDEA: selecting -> uppercase => voices -> yelling one word at a time (AWS?)
//noting line breaks in chrome devtools between selection and post slice
//FIXME: better attach
document.styleSheets[document.styleSheets.length - 1].addRule("::selection", "background: red !important; color: pink !important; text-transform: uppercase !important");
//get whole parent
@fitsum
fitsum / dumb-console-animation.js
Last active April 26, 2024 05:25
dumb console animation
var angle = null,
step = 20,
rate = 90;
draw = () => {
if (!angle) {
angle = 0;
}
console.clear();
@fitsum
fitsum / tmux.conf
Last active May 23, 2022 02:50
tmux settings
# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g default-terminal "xterm"
set -g @continuum-restore 'on'
set -g @resurrect-capture-pane-contents 'on'
# for vim
o = {name: "Fitsum"}
f = function(obj){self = obj ? obj : this; return self.name}
f(o) === f.call(o)
//
@fitsum
fitsum / ticker.js
Last active April 26, 2024 05:26
request animation frame
var now, dt,
rate = 0.5,
last = performance.now();
function frame() {
now = performance.now();
dt = (now - last) / 1000; // duration in seconds
if(dt >= rate){
console.log("bing")
last = now;
:root {font-size: 16px; line-height: 1.5; font-family: sans-serif; padding: 20px}
body {}
h1 {font-size:2rem; margin-bottom:1rem; line-height: 1}
h2 {font-size:1.5rem; margin-bottom: .5rem;}
p {margin-bottom: 1rem;}
@fitsum
fitsum / noaa.js
Last active April 26, 2024 05:06
noaa.js
console.clear()
var latLon = '38.9031,-77.0507',
getForecastURL = 'https://api.weather.gov/points/' + latLon;
forecast = async (url) => {
//let r = await fetch(url);
let j = await (await fetch(url)).json();
j.properties.forecast ? forecast(j.properties.forecast) : console.table(j.properties.periods)
}