Skip to content

Instantly share code, notes, and snippets.

@tyom
tyom / require.js
Created January 27, 2023 14:04
Require in ESM
View require.js
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
export const expoConfig = require('/package.json')
@tyom
tyom / helpers.ts
Created September 6, 2022 12:57
Appium three-finger long-press (Expo dev menu)
View helpers.ts
// W3C Actions
await driver.performActions([
{
type: 'pointer',
id: 'finger1',
parameters: { pointerType: 'touch' },
actions: [
{ type: 'pointerMove', x: 100, y: 300 },
{ type: 'pointerDown', duration: 1000 },
{ type: 'pointerUp' },
@tyom
tyom / workflow.yml
Created December 23, 2021 13:06
GH workflows tricks
View workflow.yml
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)' }}
@tyom
tyom / useMountedEffect.tsx
Created February 13, 2021 15:08
useEffect which runs after component is mounted
View useMountedEffect.tsx
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);
}
@tyom
tyom / divider.css
Created December 15, 2020 13:13
Dividing lines for centred text (CSS)
View divider.css
.divider {
margin: 1.5rem 0;
position: relative;
overflow: hidden;
&::before,
&::after {
content: '';
position: absolute;
top: 50%;
@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.
View redirect-to-trailing-slash.js
window.location.href.match(/[^/]$/) && (window.location.href += '/');
@tyom
tyom / global.js
Created November 12, 2018 14:06
Import all Vue components that match regex as global
View global.js
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 / config.yaml
Last active August 17, 2018 10:41
PR preview and tests with now.sh
View config.yaml
version: 2
references:
container_config: &container_config
docker:
- image: circleci/node:10.8
restore_deps_cache: &restore_deps_cache
restore_cache:
keys:
@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.
View js-enabled
<script>(function(d){d.className=d.className.replace(/\bno-js\b/,'js-enabled')})(document.documentElement)</script>
@tyom
tyom / .eslintrc
Created September 7, 2016 14:20
ESLint config template
View .eslintrc
{
"extends": "eslint:recommended",
"root": true,
"env": {
"es6": true,
"browser": true,
"node": true
},
"parserOptions": {
"sourceType": "module"