Skip to content

Instantly share code, notes, and snippets.

View getify's full-sized avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
function Article({ id }) {
const [article, setArticle] = useState(null);
useEffect(() => {
let cancelToken = new CAF.cancelToken();
let fetchData = CAF(function *fetchData(signal) {
const article = yield API.fetchArticle(id);
setArticle(article);
});
@getify
getify / 1.html
Last active May 10, 2023 03:25
Ever noticed how vw/vh units in CSS seem to be a bit unreliable on various devices (especially mobile)? Here's my solution.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<title>Test Page</title>
<script>
// early compute the vw/vh units more reliably than CSS does itself
computeViewportDimensions();
@getify
getify / 1.js
Last active August 4, 2023 06:24
Converting English number sentences ("one hundred forty two point three") to numeric digits ("142.3")
convert("one hundred five"); // "105"
convert("six hundred and fifty three"); // "653"
convert("zero zero one two three"); // "123"
convert("twelve o three"); // "1203"
convert("thirteen zero nine"); // "1309"
convert("fifteen sixteen"); // "1516"
convert("fourteen ninety two"); // "1492"
convert("nineteen ten"); // "1910"
convert("twelve hundred"); // "1200"
convert("twenty three hundred"); // "2300"
@getify
getify / mass-linked-in-invitation.js
Last active June 30, 2022 18:51
mass accept/reject of linked-in invitations
processInvitations().catch(console.log);
function delay(ms) { return new Promise(res => setTimeout(res,ms)); }
async function processInvitations() {
var cards = [...document.querySelectorAll("li.invitation-card")];
var acceptCards = cards.filter(card => {
var title = (card.querySelectorAll(".invitation-card__subtitle")[0] || {}).innerHTML || "";
return accept(title);
@getify
getify / 1.js
Created December 5, 2020 01:56
the "problem" with asynchronous closing of an async iterator
async function *getStuff(urls) {
showSpinner();
try {
for (let url of urls) {
let resp = await fetch(url);
yield await resp.json();
}
}
finally {
hideSpinner();
@getify
getify / 1.js
Last active December 15, 2020 15:01
a better "async generator", where `return(..)` immediately tears it down? Insipired from: https://alinacierdem.com/the-problem-with-async-generators/
// NOTE: ag(..) is defined in 2.js below
for await (let v of ag("hello")) {
console.log(`v: ${v}`);
}
// a: hello
// b
// v: 42
// c: some data: 10
// d
@getify
getify / App.jsx
Created November 28, 2020 21:37
how to do this in react?
import React, { Component } from "react";
import MyStuffParent from "./my-stuff-parent";
import MyStuff from "./my-stuff";
export default class App extends Component {
constructor() {
super();
this.state = {
showMyStuff: true
}
@getify
getify / 1.js
Last active July 20, 2022 19:24
insert object keys in order, enumerate them in order
var obj = { a: 1, b: 2, c: 3, d: 4 };
insert(obj,{ property: "g", value: 7 });
insert(obj,{ before: "g", property: "e", value: 5 });
insert(obj,{ property: "h", value: 8 });
insert(obj,{ before: "g", property: "f", value: 6 });
obj.i = 9;
console.log(keys(obj));
// [ "a", "b", "c", "d", "e", "f", "g", "h", "i" ]
@getify
getify / 1.js
Last active November 5, 2020 01:17
trying to make race/all combinators for AbortController signals that aren't leaky
class cancelToken {
constructor(controller = new AbortController()) {
this.controller = controller;
this.signal = controller.signal;
({
pr: this.signal.pr,
rej: this.rej,
} = signalPromise(this.signal));
this.signal.pr.catch(() => {
this.controller.abort();
@getify
getify / 1.md
Created October 20, 2020 15:51
troubles with pbkdf2 between node and browser

In the code below, I generate a PBKDF2 key from my password using the same salt/iterations, first in node, then in the browser.

I'm not using any libraries on either side. I'm using the built-in crypto module in node, and the SubtleCrypto web API in the browser.

I'm trying to get both sides to generate the same base64 string of the derived key. Here's what I get:

Node:    UJ3XzqSfs1IjU3/1USt8jPb9Z9jnhevBy3TPCAPGzHPbwXI0jVk+0LoVO7zYmb1BVEtajPmkcuLUPpwju+x+IQ==
Browser: UJ3XzqSfs1IjU3_1USt8jPb9Z9jnhevBy3TPCAPGzHM