Skip to content

Instantly share code, notes, and snippets.

View dinocarl's full-sized avatar

Carl Albrecht-Buehler dinocarl

View GitHub Profile
const data = {
selected: 2,
opts: [
{id: 1, name: `A`},
{id: 2, name: `B`},
{id: 3, name: `C`},
]
};
const selected = (a, b) => R.equals(a, b) ? `selected="selected"` : ``;
@mixin decl($props) {
// layout
display: prop('display', $props);
position: prop('position', $props);
top: prop('top', $props);
right: prop('right', $props);
bottom: prop('bottom', $props);
left: prop('left', $props);
float: prop('float', $props);
clear: prop('clear', $props);
// https://codepen.io/anon/pen/LgJPmv
// https://codepen.io/anon/pen/qJMaER
// https://codepen.io/anon/pen/vQNxaN
// https://codepen.io/anon/pen/mQrbQV
// https://codepen.io/anon/pen/wLPxOV
// Functions
// convenience type-checking functions
@function is_null( $val ) { @return type-of( $val ) == 'null'; }
@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;
}
@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
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 );
;; 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]}}}
@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
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}`;
const {
compose,
concat,
cond,
curry,
flatten,
flip,
identity,
is,
isNil,