Skip to content

Instantly share code, notes, and snippets.

@tyom
tyom / wdio.config.js
Last active May 24, 2023 11:02
Support for testID on Android in Appium (WebDriver.io)
// In Android wdio config
config = {
before() {
global.$ = selector => {
const enhancedSelector =
typeof selector === 'string' && selector.startsWith('~')
? `//*[@resource-id="${selector.slice(1)}"]`
: selector
return driver.$(enhancedSelector)
@tyom
tyom / require.js
Created January 27, 2023 14:04
Require in ESM
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)
// 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
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
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)
.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.
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
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
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.
<script>(function(d){d.className=d.className.replace(/\bno-js\b/,'js-enabled')})(document.documentElement)</script>