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
@getify
getify / 1.js
Last active November 12, 2018 14:57
the "knights-dialer" problem
// https://medium.com/@alexgolec/google-interview-questions-deconstructed-the-knights-dialer-f780d516f029
function nearby(number) {
return (
number === 0 ? [4,6] :
number == 1 ? [6,8] :
number == 2 ? [7,9] :
number == 3 ? [4,8] :
number == 4 ? [3,9,0] :
number == 6 ? [1,7,0] :
@getify
getify / 1.js
Last active March 19, 2023 08:32
tag function for formatting console.log(..) statements
function logger(strings,...values) {
var str = "";
for (let i = 0; i < strings.length; i++) {
if (i > 0) {
if (values[i-1] && typeof values[i-1] == "object") {
if (values[i-1] instanceof Error) {
if (values[i-1].stack) {
str += values[i-1].stack;
continue;
}
@getify
getify / talk.md
Last active January 14, 2019 23:27
Talk Abstract: "The Web Must PWA"

The Web Must PWA

The web is the most important platform for individual empowerment and creative expression that mankind has ever invented. What was once a meager collection of a handful of scientific documents linked together, is now an expansive graph of billions of people interacting to exchange trillions of interconnected ideas. Getting to be even a small part of building that should be tremendously exciting.

But, even as great as it is, the web faces myriad existential threats. And it's up to us, the builders of the web, to confront them head on. Privacy, security, and accessibility are the obvious big ones, but less obvious are some far deeper problems at the core of the web and how we design/build it.

Should the web go all-HTTPS? Most think so, but uncacheable HTTPS alienates 1/3 of the world's population. We can all probably imagine how bad the web is on slow connections, or even how much it costs on expensive metered-data plans. But worse than slow connection is spotty/intermittent connection or

@getify
getify / 1.md
Last active January 17, 2020 16:35
A question about JS parameter scopes, and closures over them vs function scopes

I received a question about this snippet of code:

function def(first="oldValue" , second=function(){
         return first;
}){
        var first="updatedValue";
        console.log('inside',first);
        console.log('function',second());
}
@getify
getify / 1.js
Created June 30, 2018 04:03
illustrating a use-case for willfully violating "TDZ" for stylistic reasons
// my-common-js-module.js
const prefix = "ABC_";
// NOTE: what's good here is that I'm using a `const`, but what's bad is, it's not
// located down below where my other "private" implementation details are.
// my public API for my module
module.exports = {
[`${prefix}1`]: 42,
[`${prefix}2`]: 100,
@getify
getify / 1.md
Last active September 6, 2024 20:20
can't figure out the geometry... HELP!?
@getify
getify / 1.js
Created June 2, 2018 04:09
waitForEvent(..) -- promisified event listener
function waitForEvent(elem,evtName) {
return new Promise(function c(resolve){
elem.addEventListener(evtName,function onEvent(evt){
elem.removeEventListener(evtName,onEvent,false);
resolve(evt);
},false);
});
}
@getify
getify / 1.md
Last active March 6, 2023 05:28
bookmarking some useful unicode icons

βŽ˜πŸ“‹πŸ—‘β¬’πŸ’»β¬“πŸ”€πŸ“·πŸ“ΆπŸ”„πŸ”πŸ”ŠπŸ”‡πŸ”πŸ”ŽπŸ–₯πŸ—¨πŸ’¬πŸ“ŽπŸ“‚πŸ“„πŸ“…πŸ“ŒπŸ“πŸ“πŸ“žβ˜ŽπŸ”’πŸ”“πŸ””πŸ”•πŸ”—β–Άβ–²β–Όβ—€βŸ²βŸ³βŠ—βœŽβœ“βœ”βœ—βœ˜βŠ•β˜·βœ„β˜°β™₯β˜…β˜†βš›βŒ–βš™βŒ•βŒ”βŒ«

@getify
getify / 1.md
Last active October 15, 2020 01:44
BetterPromise: a strawman experiment in subclassing Promise and "fixing" a bunch of its awkward/bad parts

Some things that are "better" with this BetterPromise implementation:

  • BetterPromise # then(..) accepts a BetterPromise (or Promise) instance passed directly, instead of requiring a function to return it, so that the promise is linked into the chain.

    var p = BetterPromise.resolve(42);
    
    var q = Promise.resolve(10);
    
    p.then(console.log).then(q).then(console.log);
@getify
getify / 1.js
Created April 11, 2018 12:30
class (with bound method) vs module
class Foo {
constructor(x) {
this.x = x;
this.hello = () => {
console.log(this.x);
};
}
}
var a = new Foo(12);