Skip to content

Instantly share code, notes, and snippets.

View Slackwise's full-sized avatar
🛸
Evangelizing Lisp

Adam Flanczewski Slackwise

🛸
Evangelizing Lisp
View GitHub Profile
@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
Created June 9, 2019 18:44
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">
@Slackwise
Slackwise / calc.js
Created February 8, 2019 17:49
Infix calculate() function (naively implemented)
const operators = {
'+': (x, y) => x + y,
'-': (x, y) => x - y,
'*': (x, y) => x * y,
'/': (x, y) => x / y
};
const calculate = (expressions) =>
expressions.reduce(({result, operator}, currentExpressionItem) =>
isNaN(currentExpressionItem) // is an operator?
@Slackwise
Slackwise / DictionaryToTupleExtensions.cs
Created December 13, 2018 22:48
Created a generic Dictinary to Tuple set of extension methods...
static class DictinaryToTupleExtenions {
public static (T1, T2) ToTuple<T1, T2>(this KeyValuePair<T1, T2> kv) => (kv.Key, kv.Value);
public static IEnumerable<(T1, T2)> ToTupleList<T1, T2>(this IDictionary<T1, T2> d) => d.Select(ToTuple);
}
@Slackwise
Slackwise / Array.prototype.disassoc.js
Last active September 29, 2020 19:24
Implementation of Clojure's dissoc for JavaScript Arrays.
Array.prototype.dissoc = function(i) {
return [
...this.slice(0, i),
...this.slice(i + 1, this.length)
];
};