Skip to content

Instantly share code, notes, and snippets.

View sapegin's full-sized avatar
🌄
Disconnected

Artem Sapegin sapegin

🌄
Disconnected
View GitHub Profile
// How do you avoid name clashes between functions, variables, components, and types?
// OK
const crocodiles = getCrocodiles({ color: 'green' })
// ???
const isCrocodile = isCrocodile(crocodiles[0])
// OK
const user: User = { name: 'Chuck Norris' }
import styled from 'styled-components/native';
import { space, layout, position, flexbox, SpaceProps, LayoutProps, PositionProps, FlexboxProps } from 'styled-system';
import { composeNative } from './styledSystem';
export type BoxProps = SpaceProps & LayoutProps & PositionProps & FlexboxProps;
/**
* A generic container with responsive props to control whitespace, layout, positioning and colors.
*/
export const Box = styled.View<BoxProps>(composeNative(space, layout, position, flexbox));
@sapegin
sapegin / fabfile.py
Created November 9, 2012 05:42
Deploy script from bare Git repo
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.files import exists
env.use_ssh_config = True
env.hosts = ['locum']
REPO = 'git/sapegin.git'
DEST = 'projects/sapegin'
@sapegin
sapegin / gist:1675531
Created January 25, 2012 09:05
Simple Node.js static HTTP server
function serve(lang, port) {
if (!lang && o.LANGS.length) lang = o.LANGS[0];
if (!port) port = 8000;
var mimeTypes = {
'default': 'text/plain',
'.html': 'text/html',
'.jpg': 'image/jpeg',
'.png': 'image/png',
'.js': 'text/javascript',
'.css': 'text/css'

aria-label doesn’t always replaces element’s own text

<span aria-label="pizza"></span>

I was sure that a screen reader would just read “pizza” but at least VoiceOver in Chrome reads “pizza, group, bullet”.

Where the “group” comes from? VoiceOver (I don’t know about other screen readers) considers a “group” any piece of text wrapped in an HTML tag, even a span that has no semantic meaning and should be ignored.

Reading of the element’s own text isn’t that clear. The example from MDN with a button works fine — a screen reader reads “close”:

@sapegin
sapegin / bad.js
Last active May 19, 2020 17:51
Common Testing Library antipatterns
import { render } from "@testing-library/react";
import { MyComponent } from './MyComponent';
describe("MyComponent", () => {
let wrapper;
beforeEach(async () => {
wrapper = render(<MyComponent butiful />);
});
@sapegin
sapegin / useScroll.ts
Created March 12, 2020 12:36
An accessible React Hook that scrolls to an element
import { useCallback, useRef, RefObject } from 'react';
/**
* Scroll to an element.
*/
export default function useScroll<T extends HTMLElement>(
options: Omit<ScrollIntoViewOptions, 'behavior'> = {},
): [RefObject<T>, () => void] {
const ref = useRef<T>(null);
const callback = useCallback(() => {
@sapegin
sapegin / fabfile.py
Created November 26, 2012 06:03
Deploy via BitBucket repo using Fabric
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.files import exists
env.use_ssh_config = True
env.hosts = ['locum']
REPO = 'git@bitbucket.org:sapegin/grunt-talk.git'
DEST = 'projects/sapegin/htdocs/subprojects/pres/grunt'
@sapegin
sapegin / preload.js
Created February 21, 2016 07:42
Tamia image preload es6
// Image preload
import { ensureArray } from './util';
export default function preload(images, callback) {
let done = () => {
counter--;
if (counter === 0) {
callback(errors.length ? errors : null);
}
@sapegin
sapegin / config.php
Created February 22, 2011 15:41
Microstock FTP Uploader
<?php
$stocks = array (
'shutterstock' => array (
'name' => 'Shutterstock',
'host' => 'ftp.shutterstock.com',
'login' => '',
'password' => '',
'dir' => '/',