Skip to content

Instantly share code, notes, and snippets.

View dinocarl's full-sized avatar

Carl Albrecht-Buehler dinocarl

View GitHub Profile
grep -R --exclude-dir={node_modules,build,.git} --exclude=*.{png,jpg,vim,swp,swo} 'searchString' ./
@dinocarl
dinocarl / kramdownAttrsRemark.js
Last active March 16, 2020 18:34
Adding kramdown-style attributes to remark
const remark = require('remark');
const html = require('remark-html');
const visit = require('unist-util-visit');
const { log } = console;
const inputMD = `
[A Link](#){: data-track="footer-link" .xclass onclick=alert() } with text that has *some*{: .emphclass } emphasis and something **strong**{: .strngclss}
[![github logo](https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png){: height=100 width=100 }](/){: .rspnsv-img data-track="logo click" }
const {
compose,
concat,
curry,
flatten,
flip,
identity,
isNil,
isEmpty,
join,
const {
compose,
concat,
cond,
curry,
flatten,
flip,
identity,
is,
isNil,
const basicSurround = curry((char, text) => `${char}${text}${char}`);
const snglQt = basicSurround(`'`);
const dblQt = basicSurround(`"`);
const OrderPrefixTmplt = jsonKey => `${dblQt(jsonKey)}->>`;
const OrderBaseTmplt = (field, dir) => `${field} ${dir}`;
@dinocarl
dinocarl / smplTmplt.js
Last active August 31, 2024 02:39
Using Ramda to parse a template string, and apply data
const dot = (f, g) => (a) => f(g(a));
const cmp = (list) => list.reduce(dot, (a) => a);
const pthOr = (fallback, keys, obj) => keys.reduce(
(acc, item) => typeof acc === 'undefined' ||
acc === null ||
acc === fallback ||
typeof acc[item] === 'undefined'
? fallback
: acc[item],
obj
;; leiningen profile
;; ~.lein/profiles.clj
{:user {:plugins [
[cider/cider-nrepl "0.20.0"]
[lein-pprint "1.2.0"]]
:dependencies [[cider/piggieback "0.3.10"]
[cljfmt "0.6.3"]]
:repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}}}
const test = require('tape');
const emptyContainer = () => null;
const checkWith = el1 => el2 => el1 === el2 ? el2 : null;
const inContainer = ( containingFn, el ) => containingFn( el ) === el;
const inEither = ( a, b ) => el => inContainer( a, el ) ? el : b( el );
const inAny = ( ...containingFns ) => containingFns.reduce( inEither, checkWith( null ) );
const inBoth = ( a, b ) => el => inContainer( a, el ) && inContainer( b, el ) ? el : null;
const inAll = ( ...containingFns ) => containingFns.reduce( inBoth, checkWith );
@dinocarl
dinocarl / javascript.snippet
Created January 2, 2019 16:51
For UltiSnips
snippet log "console.log(...)" b
console.log($0);
endsnippet
snippet tg "generic JSX tag" b
<$1>$0</$1>
endsnippet
@function apply-unit($unit, $val) {
@return unquote('#{$val}#{$unit}');
}
@function strip-unit($number) {
@if type-of($number) == 'number' and not unitless($number) {
@return $number / ($number * 0 + 1);
}
@return $number;
}