Skip to content

Instantly share code, notes, and snippets.

View jkarttunen's full-sized avatar

Juha Karttunen jkarttunen

View GitHub Profile
git config --global alias.lol "log --graph --decorate --pretty=oneline --abbrev-commit"
git config --global alias.lola "log --graph --decorate --pretty=format:\"%C(yellow)%h %Cred%cr %Cblue(%an)%C(white)%d%Creset %s\" --abbrev-commit --all"
@jkarttunen
jkarttunen / autolayout.css
Last active June 22, 2022 17:39
Figma autolayout as css
.autolayout {
display: flex;
flex-direction: row;
flex-shrink: 0;
justify-content: flex-start;
align-items: flex-start;
}
/* Horizontal */
@jkarttunen
jkarttunen / visualize-stacking-contexts.js
Created February 7, 2021 08:07 — forked from tlrobinson/visualize-stacking-contexts.js
Some console output to help you visualise stacking contexts on a page (no jquery)
/*
Usage:
* Paste this into your dev tools console (or even better as a snippet)
* It will parse the page and find all the things that create a new stacking context
and dump some info about them to the console. It will also outline them on the page.
* This is pretty rough and probably misses heaps of bugs and edge cases.
*/
function highlight(el) {
@jkarttunen
jkarttunen / .eleventy.js
Created August 9, 2020 05:56
.eleventy.js
module.exports = config => {
return {
dir: {
input: 'src',
output: 'dist'
}
};
};
@jkarttunen
jkarttunen / .gitignore
Created August 9, 2020 05:55
.gitignore
# Misc
*.log
npm-debug.*
*.scssc
*.swp
.DS_Store
Thumbs.db
.sass-cache
.env
.cache
We couldn’t find that file to show.
@jkarttunen
jkarttunen / gulpfile.js
Created April 12, 2020 10:14
Build multiple apps with Create-React-App without ejecting
const { series, src, dest } = require('gulp');
const fs = require('fs');
const del = require('del');
const json = require('json-update');
var rename = require("gulp-rename");
var cp = require('child_process');
const package = require('./package.json');
const deployment = require('./deployment.json');
@jkarttunen
jkarttunen / bem.js
Created April 12, 2020 07:26
Simple Bem classname utility
/**
* Stupid simple BEM utility for class names. Useful for creating className strings in simple components
* @param {string} block - Block name
* @param {string} [element] - Element name
* @param {string} [modifier] - modifier name
* @return {string} A BEM string,
*
* @example
* bem('button', 'icon', 'red');
* // returns 'button button--icon button--icon--red'
@jkarttunen
jkarttunen / getSubdomain.js
Created April 12, 2020 07:19
Get subdomain from hostname
/**
* Extracts subdomain from hostname. Works with localhost, but not with full url with ports.
* @example
* getSubdomain(location.hostname); //www.google.com
* // returns 'www'
* @example
* getSubdomain(location.hostname); //localhost
* // returns 'localhost'
**/
@jkarttunen
jkarttunen / findParentTag.js
Last active April 12, 2020 06:54
Find parent tag
/**
* Recursively find parents until matching tag has been found.
* Useful when observing clicks on elements with child elements, but you need to use data- attributes from parent.
* @param {HTMLElement} element - Element to find parent from.
* @param {string} tag - Parent tag to find. Eg. 'DIV' or 'H1'
**/
function findParentTag(element, tag) {
const tagName = tag.toUpperCase();
if (element.tagName === tagName) return element;