Skip to content

Instantly share code, notes, and snippets.

@tyom
tyom / .eslintrc
Created September 7, 2016 14:20
ESLint config template
{
"extends": "eslint:recommended",
"root": true,
"env": {
"es6": true,
"browser": true,
"node": true
},
"parserOptions": {
"sourceType": "module"
@tyom
tyom / .editorconfig
Last active April 12, 2018 08:48
Editorconfig settings
# http://editorconfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
@tyom
tyom / js-enabled
Created June 27, 2018 16:57
Insert in the head of the document to replace `no-js` class with `js-enabled` before `body` gets parsed.
<script>(function(d){d.className=d.className.replace(/\bno-js\b/,'js-enabled')})(document.documentElement)</script>
@tyom
tyom / config.yaml
Last active August 17, 2018 10:41
PR preview and tests with now.sh
version: 2
references:
container_config: &container_config
docker:
- image: circleci/node:10.8
restore_deps_cache: &restore_deps_cache
restore_cache:
keys:
@tyom
tyom / global.js
Created November 12, 2018 14:06
Import all Vue components that match regex as global
const requireComponent = require.context(
'~/components', // components dir
true, // recursive
/^(\.\/.*)*V[A-Z].+\.vue$/, // name regex
);
requireComponent.keys().forEach(fileName => {
let baseComponentConfig = requireComponent(fileName);
baseComponentConfig = baseComponentConfig.default || baseComponentConfig;
@tyom
tyom / redirect-to-trailing-slash.js
Created May 8, 2019 17:05
This is technique is useful when dealing with static subdirectories. Unless the current directory has trailing slash it won't be regarded it as such, leading to wrong relative path.
window.location.href.match(/[^/]$/) && (window.location.href += '/');
@tyom
tyom / divider.css
Created December 15, 2020 13:13
Dividing lines for centred text (CSS)
.divider {
margin: 1.5rem 0;
position: relative;
overflow: hidden;
&::before,
&::after {
content: '';
position: absolute;
top: 50%;
@tyom
tyom / useMountedEffect.tsx
Created February 13, 2021 15:08
useEffect which runs after component is mounted
import { useRef, useEffect } from 'preact/hooks';
export function useMountedEffect(cb: () => void, deps?: ReadonlyArray<unknown>): void {
const didMount = useRef(false);
useEffect(() => {
if (didMount.current) cb();
else didMount.current = true;
}, deps);
}
body {
background: #222;
color: #ddd;
white-space: pre;
font-family: monospace;
}
a {
color: #6482c8;
}
@tyom
tyom / workflow.yml
Created December 23, 2021 13:06
GH workflows tricks
env:
# Add an optional dynamic string based on a PR number
SOME_ENV_VAR: static-string/${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || '' }}
jobs:
some-job:
steps:
# Conditionally name a step
- name: Step for ${{ github.event_name == 'pull_request' && '(PR)' || '(main)' }}