Skip to content

Instantly share code, notes, and snippets.

View markalfred's full-sized avatar

Mark Battersby markalfred

View GitHub Profile
@joshdover
joshdover / README.md
Last active September 28, 2023 21:38
Idiomatic React Testing Patterns

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed:

@markalfred
markalfred / Skepticisms.sh
Last active August 29, 2015 14:06
Skepticisms. And other long words.
# Find the longest words you can type, alternating hands at each character. Y and B excluded.
egrep "^[$right]?([$left][$right]){6,}[$left]?\$" /usr/share/dict/words
# Qwerty
left=qwertasdfgzxcv
right=uiophjklnm
# Colemak
left=qwfpgarstdzxcv
@stefansundin
stefansundin / install-pre-push.sh
Last active June 9, 2024 13:02
Git pre-push hook to prevent force pushing the master/main branch.
#!/bin/bash
# This script will install a Git pre-push hook that prevents force pushing the master/main branch.
# There are three variants that I have built:
# - pre-push: prevents force-pushing to master/main.
# - pre-push-2: prevents force-pushing to master/main depending on the remote (you need to edit the file!).
# - pre-push-3: prevents any type of pushing to master/main.
# Set the desired version like this before proceeding:
# FILE=pre-push
# Single repo installation:
@brysgo
brysgo / post_checkout_migrations.sh
Last active November 15, 2024 14:24 — forked from skyriverbend/rails_switch_branch.py
Post checkout hook for managing rails migrations and bundle install
CHECKING_OUT_BRANCH=$3
OLD_BRANCH=$1
NEW_BRANCH=$2
if [ $CHECKING_OUT_BRANCH -eq 1 ]
then
FILES_CHANGED=`git diff $OLD_BRANCH $NEW_BRANCH --name-status`
MIGRATIONS_REMOVED=`echo "$FILES_CHANGED" | egrep 'D\tdb/migrate/([0-9]+)' | sort -r`
MIGRATIONS_ADDED=`echo "$FILES_CHANGED" | egrep 'A\tdb/migrate/([0-9]+)'`
@aesnyder
aesnyder / Kompressor.coffee
Created March 27, 2014 14:18
Remove base64 heads from array - whammy.js
# remove the heads off arrays of base_64 encoded datauris
#
# in this example we take the array of images encoded from
# whammy.js and return an array without the heads. This is
# an admittedly vain optimization but, every byte counts.
Base64Header = (type) ->
head: "data:#{type};base64,"
add: (string) ->
"#{HEAD}#{string}"
section: screens
desktop:
laptop:
end
section: aliases
desktop:
Williams-Mac-Pro.local
laptop:
will.local
@brandonb927
brandonb927 / osx-for-hackers.sh
Last active November 14, 2024 17:18
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx