Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Just coding

Kyle Simpson getify

💭
Just coding
View GitHub Profile
View 1.js
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 Mar 30, 2021
Ever noticed how vw/vh units in CSS seem to be a bit unreliable on various devices (especially mobile)? Here's my solution.
View 1.html
<!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 Mar 28, 2021
Converting English number sentences ("one hundred forty two point three") to numeric digits ("142.3")
View 1.js
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 Feb 24, 2021
mass accept/reject of linked-in invitations
View mass-linked-in-invitation.js
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 Dec 5, 2020
the "problem" with asynchronous closing of an async iterator
View 1.js
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 Dec 15, 2020
a better "async generator", where `return(..)` immediately tears it down? Insipired from: https://alinacierdem.com/the-problem-with-async-generators/
View 1.js
// 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 Nov 28, 2020
how to do this in react?
View App.jsx
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 Nov 21, 2020
insert object keys in order, enumerate them in order
View 1.js
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 Nov 5, 2020
trying to make race/all combinators for AbortController signals that aren't leaky
View 1.js
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 Oct 20, 2020
troubles with pbkdf2 between node and browser
View 1.md

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