Skip to content

Instantly share code, notes, and snippets.

View MKRhere's full-sized avatar
πŸ˜•
In a mid-youth crisis

Muthu Kumar MKRhere

πŸ˜•
In a mid-youth crisis
View GitHub Profile
@MKRhere
MKRhere / fold.ts
Last active May 23, 2021 20:48
Early returnable Fold
class FoldBreak <T> {
constructor(public value: T) {};
};
const foldBreak = <T>(value: T) => new FoldBreak(value);
export const fold = Object.assign(<X, Acc>(
reducer: (acc: Acc, x: X) => Acc | FoldBreak<Acc>,
init: Acc,
xs: X[],
@MKRhere
MKRhere / event-middleware.js
Last active July 2, 2020 14:14
Superior generic middleware composition
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
const listeners = {};
const on = (ev, ...handlers) => {
if (!listeners[ev]) listeners[ev] = [];
listeners[ev].push(compose(...handlers)(x => x));
};
const emit = (ev, ctx) => {
@MKRhere
MKRhere / README.md
Last active November 22, 2022 20:42
nginx (static or reverse proxy) & acme.sh (DNS) configuration

1) Create the following directory structure

/etc
β”œβ”€β”€ nginx
β”‚   β”œβ”€β”€ sites-enabled
β”‚   β”‚   └── domain.tld.port.conf # template attached
β”‚   └── ssl
β”‚       β”œβ”€β”€ .conf # file attached as `ssl.conf`
β”‚       β”œβ”€β”€ dhparam.pem # generated
@MKRhere
MKRhere / hpg.js
Last active February 23, 2020 07:13
A commandline widget to run neofetch on watch mode
#!/bin/env node
const child = require("child_process");
const readline = require("readline");
const { promisify } = require("util");
const getLines = () =>
String(
child.execSync("neofetch --config ~/.mkr/config/neofetch.conf --off"),
)
@MKRhere
MKRhere / diff_line_numbers.js
Last active February 21, 2020 16:37
Add line numbers to unified diff format (is it bad code day?)
const state = {
watch: false,
range: {
src: {
start: 0,
end: 0
},
dest: {
start: 0,
end: 0
@MKRhere
MKRhere / compile.js
Last active February 21, 2020 10:49
HTML2HyperScript
"use strict";
const htmlparser = window.htmlparser2;
const html2hyperscript = (input, stream) => {
const elements = new Set();
let indentLevel = 0;
let attrOpen = false;
let textWritten = false;
let justClosed = false;
let size = 0;
@MKRhere
MKRhere / README.md
Last active March 15, 2020 06:16
nginx reverse proxy & acme.sh (stateless) configuration
  1. Create all attached files below as-is. Directory structure:
etc
β”œβ”€β”€ nginx
β”‚   β”œβ”€β”€ sites-enabled
β”‚   β”‚   └── domain.tld.port.conf (several)
β”‚   └── ssl
β”‚       β”œβ”€β”€ .conf # file attached as ssl.conf
β”‚ β”œβ”€β”€ well-known.conf # file attached
@MKRhere
MKRhere / betterArray.js
Last active February 18, 2020 11:57
Extend Array with Proxies for fancy features
const betterArray = xs => new Proxy(xs, {
get (xs, key) {
if (xs[key] || !xs.length) return xs[key];
const idx = Number(key);
if (!idx || idx > 0) return xs[key];
return xs[xs.length + idx];
},
});
const arr = betterArray([ 1, 2, 3, 4, 5 ]);
@MKRhere
MKRhere / mdn-clear-dark.css
Created February 12, 2020 02:00
MDN Dark Theme
@-moz-document domain("developer.mozilla.org") {
main {
background: #000;
}
html {
color: #fff;
}
.titlebar-container {
@MKRhere
MKRhere / iter.js
Last active October 31, 2019 12:52
iter-fns
function* map(f, iter) {
for (const i of iter) {
yield f(i);
}
}
function* filter(f, iter) {
for (const i of iter) {
if (f(i)) yield i;
}