Skip to content

Instantly share code, notes, and snippets.

View jacobrask's full-sized avatar

Jacob Rask jacobrask

  • Gothenburg, Sweden
View GitHub Profile
@jacobrask
jacobrask / next.config.mjs
Created November 11, 2022 21:42
Enhance in Next.js
import enhance from "@enhance/ssr";
import postProcess from "next/dist/server/post-process.js";
import MyButton from "./src/elements/my-button.mjs";
import MyIcon from "./src/elements/my-icon.mjs";
import styleTransform from "@enhance/enhance-style-transform";
const _postProcessHTML = postProcess.postProcessHTML;
postProcess.postProcessHTML = async function postProcessHTML(
pathname,
content,
@jacobrask
jacobrask / css-variable-proxy.ts
Last active October 15, 2023 14:43
CSS variable TypeScript proxy
/**
* PoC using recursive proxies to maintain a typed interface for your CSS variable themes.
*
* See https://www.joshwcomeau.com/css/css-variables-for-react-devs/ for an excellent intro to CSS variables.
*
* Using CSS variables as plain strings in TypeScript is not great though.
* It's prone to typos, difficult to refactor and you can't easily deprecate properties or add aliases.
* One solution is to create a JavaScript object of your theme, with the CSS variable as the value, but
* if users are already downloading your theme as CSS variables, why make them download it again as a JS object?
*/
import React from 'react';
// Composes any number of props transforms and applies them in a HOC.
const transform = (...transforms) =>
WrappedComponent =>
props =>
<WrappedComponent {...transforms.reduce((ps, t) => t(ps), props)} />;
// Example reusable transforms.
const addClass = className => props => ({ ...props, className });
@jacobrask
jacobrask / critic-docker
Created October 14, 2014 18:40
Critic Docker manager
#!/bin/bash
function install {
# Stop and clean up existing containers
docker ps -a | grep critic | awk '{print $1}' | xargs docker rm -f
# Run a postgres container based on the standard Docker postgres image
docker run --name critic-postgres -d postgres
# Build a Critic image based on Debian
@jacobrask
jacobrask / test.js
Last active December 21, 2022 13:50
JavaScript unit testing in the console
function test (name, fn) {
console.group(name);
var args = [ console.assert.bind(console) ];
// Async
if (fn.length > 1) {
var timeout = setTimeout(function(){ console.error(name+' timed out'); }, 2000);
args.push(clearTimeout.bind(null, timeout));
}
fn.apply(null, args);
console.groupEnd();
@jacobrask
jacobrask / domchain.js
Created October 31, 2012 21:53
Dom Chain
// Proof of concept DOM utility library
//
// Usage
// ------------------------------------------------------------------
// var html = window.domchain;
// html().p('.foo#bar').span().text("Hello World").render();
// => <p class="foo" id="bar"><span>Hello World</span></p>
//
// Inspired by [htmlutils](https://github.com/jensl/critic/blob/master/htmlutils.py),
// [domo](https://github.com/jed/domo) and [Sugared DOM](https://gist.github.com/1532562);
@jacobrask
jacobrask / domsugar.js
Created August 30, 2012 08:24 — forked from neilj/gist:1532562
DOM sugar
// DOM sugar
// ==================================================================
// Modified version of Neil Jenkins' "Sugared DOM" <https://gist.github.com/3524145>
//
// Usage
// ------------------------------------------------------------------
// var make = domsugar(document);
//
// make( 'p.foo#bar', { hidden: true }, [ make( 'span' ) ] );
// => <p class="foo" id="bar" hidden><span></span></p>
@jacobrask
jacobrask / _extends.scss
Created August 16, 2012 08:20
SASS @extend-only
%test {
foo: bar;
}
@jacobrask
jacobrask / dabblet.css
Created June 27, 2012 22:19
Fadeout and marquee
/*
Fadeout and marquee
*/
.fadeout-text {
overflow: hidden;
width: 130px;
/* Fallback solution for browsers that
doesn't support the next set of rules. */
text-overflow: ellipsis;
white-space: nowrap;
@jacobrask
jacobrask / .gitattributes
Created April 3, 2012 08:22
Text diff of images in git
*.png diff=xpm