Skip to content

Instantly share code, notes, and snippets.

View dinocarl's full-sized avatar

Carl Albrecht-Buehler dinocarl

View GitHub Profile
@dinocarl
dinocarl / leftCond.js
Created September 15, 2022 18:30
Like cond, but simply returns the first truthy value it encounters when executing functions in fnList against initVal. Intended for the occastions when one wants to write a cond, but the left and the right sides end up with the same function, but can also be used in any circumstance where the function being run can both serve as predicate and re…
// accepts an argument object and a data object.
// first returns the value at lookupName in the data object
// and then applies the value of that back onto the data object
// treating it as meta data about the data object, eg
// lookWIthin(
// { lookupName: 'currPage', endOfPath: ['position'] },
// { currPage: 'page!', page!: {position: 55} }
// ) => 55
const lookWithin = ({ lookupName, endOfPath = [] }) => compose(
const juxtMerge = (fnList) => compose(
mergeAll,
juxt(fnList)
);
// given an object, a foreignKey (name), and a lookup object
// containing data keyed to the foreignKey,
// return the data of the lookup, or a fallback value
const propOfPropOr = (fallback, foreignKey, lookup) => (item) => propOr(
fallback,
@dinocarl
dinocarl / everyItemEqual.js
Last active August 5, 2022 02:11
Different ways of checking whether all items in an array are equal
const eq = (a) => (b) => a === b;
const everyItemEquala = compose(
apply(all),
juxt([compose(equals, head), identity])
);
const everyItemEqualb = compose(
equals(1),
length,
const filterOperations = {
eq: equals,
neq: complement(equals),
lt: gt,
gt: lt,
lte: gte,
gte: lte,
includes: includes,
}
const data = {'a.b': 1, 'c.d': 7, 'c.d': 9}
const assocPathDataLast = curry(
(mergeAble, pathList, val) => assocPath(pathList, val, mergeAble)
);
const processKeys = compose(
split('.'),
head
);
@dinocarl
dinocarl / clamp.js
Last active January 19, 2022 20:03
const clamp = (min, max, x) => Math.min(Math.max(x, min), max);
const clmp = (minVal, maxVal) => compose(
min(maxVal),
max(minVal)
);

Keyboard Basics

Basic Terms

  • Keycap: [Plastic outer covering][keycaps] of a particular key typically inscribed with the character that gets sent to the computer when struck.
  • PCB: Printed Circuit Board (really, just a circuit board), which registers keystrokes and sends them to the computer.
  • Switch: underlying mechanism that the keycap covers, and in some way creates contact with the PCB to let it know that a keystroke needs
@dinocarl
dinocarl / everyByProp.js
Created August 4, 2021 15:04
Ramda-based every and some Fns that rely on a specific prop
const data1 = [
{id: 1, status: true},
{id: 2, status: false},
{id: 3, status: true},
];
const data2 = [
{id: 1, status: true},
{id: 2},
{id: 3, status: true},
@dinocarl
dinocarl / input.scss
Created January 19, 2021 16:55
Generated by SassMeister.com.
// Given a value with a unit
// return the value without the unit
@function strip-unit($item) {
@if type-of($item) == 'number' and not unitless($item) {
@return $item / ( $item * 0 + 1 );
}
@return $item;
}

Keybase proof

I hereby claim:

  • I am dinocarl on github.
  • I am dinocarl (https://keybase.io/dinocarl) on keybase.
  • I have a public key ASDKE0ZRqX9N0qWa_W_hgF_DGsLmbgaWta9UtVWiQUAV2go

To claim this, I am signing this object: