Skip to content

Instantly share code, notes, and snippets.

View Slackwise's full-sized avatar
🛸
Proselytizing Parenthesized Programming

Adam Flanczewski Slackwise

🛸
Proselytizing Parenthesized Programming
View GitHub Profile
@Slackwise
Slackwise / arityMatch.js
Created February 10, 2020 14:34
Arity matching functions in JavaScript
// Example 1 or 2-arity function f
const f = (...args) =>
[
(x) => console.log("One param"),
(x, y) => console.log("Two params")
][args.length-1](...args);
f(1) // "One param"
f(1, 2) // "Two param"
@Slackwise
Slackwise / romanToInt.js
Created October 30, 2019 02:42
Convert Roman Numerals to Integers.
const values = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000
};
@Slackwise
Slackwise / apiAdd.js
Last active July 19, 2019 17:33
There was a challenge someone mentioned of implementing addition without using the `+` operator... CHALLENGE ACCEPTED!
function add(x, y) {
const apiUrl = `https://api.mathjs.org/v4/?expr=${x}%2B${y}`;
try {
let xhr = new XMLHttpRequest(apiUrl);
xhr.open('GET', apiUrl, false);
xhr.send();
return Number(xhr.responseText);
} catch (ex) {
console.log("Ya'll numbers fucky");
return NaN;
@Slackwise
Slackwise / grouping.js
Last active June 10, 2019 11:36
Vanilla ES6 functions to group database result sets, and example usage.
returnedUsers = {
"users": [
{
"name": "dusan",
"id": 1,
"skill": "node.js",
"skill_id": 1
},
{
"name": "dusan",
@Slackwise
Slackwise / groupBy.js
Last active July 16, 2025 16:07
Minimal implementation of an Array groupBy function.
// As a function:
const groupBy = (array, key) =>
array.reduce((a, c) => (
{
...a,
[ c[key]]: [ ...a[c[key]] || [], c ]
}
), {});
// As a method:
@Slackwise
Slackwise / closureListReduce.js
Last active March 4, 2021 06:23
Implemented the cons cell linked list data structure as well as reduce() using only recursive curried functions and closures.
cons = a => b => f => f(a)(b)
car = a => b => a
cdr = a => b => b
reduce = f => i => l =>
l
? reduce (f) (f(i)(l(car))) (l(cdr))
: i
l = cons(1)(cons(2)(cons(3)(null)))
@Slackwise
Slackwise / cycle.js
Created June 3, 2019 00:44
A JavaScript example of creating a cycling call function using a closure.
const foo = () => "foo";
const bar = () => "bar";
const baz = () => "baz";
const cycle = (...fns) =>
() => {
const [f, ...fs] = fns;
fns = [...fs, f];
return f();
};
@Slackwise
Slackwise / logged.js
Last active May 10, 2021 12:58
JavaScript HOF for creating logged functions.
const logged = logF => f =>
(...args) => {
const output = f(...args);
console.log(logF(args, output));
return output;
};
function writeFile(filename) {
console.log(`[ACTUALLY DOING STUFF WITH ${filename}]`);
}
@Slackwise
Slackwise / discord-theme
Created February 27, 2019 16:22
Discord Theme for Slack and Mattermost
// Slack
#2F3136,#2A2C30,#4F545C,#F6F6F7,#36393F,#DCDDDE,#43B581,#F04747
// Mattermost
{"sidebarBg":"#2f3136","sidebarText":"#9ca0a4","sidebarUnreadText":"#ffffff","sidebarTextHoverBg":"#42464d","sidebarTextActiveBorder":"#42464d","sidebarTextActiveColor":"#ffffff","sidebarHeaderBg":"#282b30","sidebarHeaderTextColor":"#ffffff","onlineIndicator":"#43b581","awayIndicator":"#faa61a","dndIndicator":"#f74343","mentionBj":"#f04747","mentionColor":"#ffffff","centerChannelBg":"#36393e","centerChannelColor":"#c0c1c2","newMessageSeparator":"#cb4445","linkColor":"#7289da","buttonBg":"#7289da","buttonColor":"#ffffff","errorTextColor":"#fd5960","mentionHighlightBg":"#3d414e","mentionHighlightLink":"#7289da","codeTheme":"monokai","mentionBg":"#f04747"}
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<title>Slackwise</title>
<meta name=author content="Adam 'Slackwise' Flanczewski">
<meta name=description content="Slackwise's Blog">
<meta name=keywords content="keywords,here">
<link rel=stylesheet href="https://fonts.googleapis.com/css?family=Press+Start+2P|Roboto|Roboto+Condensed|Roboto+Mono">
<link rel=stylesheet href="prism-vs.css">
<link rel=stylesheet href="screen.css">