Skip to content

Instantly share code, notes, and snippets.

View robertpenner's full-sized avatar

Robert Penner robertpenner

View GitHub Profile
@jcalz
jcalz / tuple.md
Last active March 1, 2024 03:33
TypeScript tuple inference

You can use the tuple() function in tuple.ts to infer tuple types in TypeScript and cut down on the need to repeat yourself. Without tuple(), declaring a constant of a tuple type looks like this:

const daysOfTheWeek: ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] = 
  ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];

You can't do this:

const daysOfTheWeek = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]; 
@paceaux
paceaux / tinyRules.css.md
Last active April 3, 2024 01:19
Tiny rules for how to name things in CSS and JS

Tiny rules for how to name stuff

CSS

How to name CSS classes

Stateful Class names

Is it a state that is only one of two conditions? (i.e. a boolean)

@josephrace
josephrace / .gitlab-ci.yml
Created May 18, 2017 17:44
Configuration file for create-react-app on GitLab Pages
image: node:7.9.0 # change to match your node version
cache:
paths:
- node_modules/
before_script:
- npm install
test:
@drkibitz
drkibitz / priority-signals.js
Last active June 6, 2023 03:30
Signal implementation with listener priorities
/**
* This object represents a single listener of a Singal.
* A listener is simply an object with a reference to a function and thisArg,
* with a priority for insertion sorting and a once flag.
* @class
*/
class Listener {
/**
* @param {Function} fn - The listener function
* @param {Function} [thisArg] - The listener thisArg
@xaviervia
xaviervia / README.md
Last active February 16, 2021 20:12
Sketch 43 files JSON types
@anaisbetts
anaisbetts / sparse-map.ts
Created February 15, 2017 22:58
TypeScript Is Amazing
//
// WRONG
///
class InMemorySparseMap<K, V> implements SparseMap<K, V> {
private latest: Map<K, Updatable<V>>;
private factory: ((key: K) => Observable<V>) | undefined;
subscribe(key: K): Updatable<V> {
let ret = this.latest.get(key);
@staltz
staltz / music.md
Last active September 29, 2023 15:42
coding music

Not for everyone. Each programmer has their own appreciation of what is good coding music.

For when I need to think deep, debug something, or design

(From most influential to least)

@developit
developit / async-examples.js
Last active February 19, 2020 00:43
Async Array utilities in async/await. Now available as an npm package: https://github.com/developit/asyncro
/** Async version of Array.prototype.reduce()
* await reduce(['/foo', '/bar', '/baz'], async (acc, v) => {
* acc[v] = await (await fetch(v)).json();
* return acc;
* }, {});
*/
export async function reduce(arr, fn, val, pure) {
for (let i=0; i<arr.length; i++) {
let v = await fn(val, arr[i], i, arr);
if (pure!==false) val = v;

Thanks everyone for participating in the quiz!
Many of you have posted correct answers.

What we know:

A top-level App component returns <Button /> from its render() method.

Question:

>What is the relationship between `` and this in that `Button`’s `render()`?

Applied Functional Programming with Scala - Notes

Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x