Skip to content

Instantly share code, notes, and snippets.

View liamross's full-sized avatar

Liam Ross liamross

View GitHub Profile
@liamross
liamross / appsync.go
Created July 14, 2021 18:07
Types for AWS AppSync event sent to Lambda resolvers.
package util
// ResolverType is one of "Query", "Mutation", or "Subscription".
type ResolverType string
const (
// QueryResolver is the resolver type for query operations.
QueryResolver ResolverType = "Query"
// MutationResolver is the resolver type for mutation operations.
MutationResolver ResolverType = "Mutation"
@liamross
liamross / instructions.md
Last active November 12, 2020 17:06
Get all songs from Google Play Music as CSV string.

Edit: You should be able to just use Google Takout to export your song data: https://takeout.google.com

With the recent moves towards YouTube Music which is pretty terrible, I figured it was time to embrace Spotify, so I wrote a script to get all of my Google Play Music songs as a CSV so I can add them to Spotify.

  1. Paste in the function below (getAllSongs) into the console when you are in https://play.google.com/music/listen#/all and scrolled all the way to the top
  2. Type await getAllSongs() and wait for the script to scroll all the way down
  3. Confirm that your LENGTH: output matches the total songs on the top of the page
  4. Copy the output string, it's valid CSV for importing into Google Sheets, Excel, etc.
@liamross
liamross / eventSubscriber.ts
Last active March 31, 2020 00:05
Different patterns for listening/subscribing to events within a class
export type Subscriber = (event: YourEvent) => void;
/**
* When you have specific events and want to use a subscriber pattern.
*/
class WithEventSubscribers {
private _subscribers: Partial<{ [type in YourEventTypes]: Subscriber[] }>;
constructor() {
this._subscribers = {};
@liamross
liamross / random_IDs.ts
Last active October 26, 2020 19:39
Utils for generating IDs.
const POSSIBLE_LETTERS = 'bcdghjklmnpqrstvwxyz'; // No vowels: attempting to avoid "bad words".
const POSSIBLE_NUMBERS = '0123456789';
const ONLY_UPPERCASE = POSSIBLE_LETTERS.toUpperCase() + POSSIBLE_NUMBERS;
const UPPER_AND_LOWERCASE = ONLY_UPPERCASE + POSSIBLE_LETTERS;
/**
* Generates a random string to use as a unique identifier. This should be used
* over `getId` if you need to use it as a DOM id, or a React key.
*
* @param prefix Optional. Prefix for the string id.
@liamross
liamross / subscriber-pattern.ts
Created September 27, 2019 21:37
Documenting the pattern I liked in React's useSubscription hook.
// https://github.com/facebook/react/blob/master/packages/use-subscription/src/useSubscription.js
type Subscription<Value> = () => {
getValue: () => Value;
subscribe: (callback: Function) => () => void;
};
const subscription: Subscription<string> = () => ({
getValue: () => something.value,
subscribe: callback => {
@liamross
liamross / typeUtils.ts
Last active January 23, 2020 02:12
Custom types for working with complex TypeScript types.
/* eslint-disable @typescript-eslint/no-explicit-any */
/**
* Remove the specified Keys of T. Like Omit, but with autocompletion.
*
* @example
* type SomeProps = {field1: string; field2: string};
* const x: Remove<SomeProps, 'field2'> = {field1: 'Hello, World!'};
*/
export type Remove<T, Keys extends keyof T> = Pick<T, Exclude<keyof T, Keys>>;
@liamross
liamross / media-query-breakpoints.scss
Last active May 6, 2019 21:29
Easy media query mixin for multiple breakpoints.
// Breakpoints - NOTE: use the provided mixins for breakpoint media queries.
$phone-upper-boundary: 768px; // > "phone"
$tablet-upper-boundary: 1200px;
$small-desktop-upper-boundary: 1920px;
$large-desktop-upper-boundary: 2200px; // < "huge desktop"
/**
* Mixin for adding size media queries. Size should be:
* - phone-only - < 768px (rare use case, use mobile first instead)
* - tablet-up - >= 768px
@liamross
liamross / padding-bottom-fix.scss
Last active February 25, 2020 18:20
A Sass mixin to replace padding-bottom on scrolling containers to fix the issue where there is no bottom padding in scrolling containers in Firefox.
/*
Browsers like firefox ignore the bottom padding in scrolling containers. The
fix, other than inserting padding on the last child (which can cause visual
issues if the last child has a border or background color) is to add the
padding height `::after` the last child.
> Note: if you are using grids, the gap will be placed between `::after`
> pseudo-element and the target element. Therefore you must subtract the
> `$grid-row-gap` from the `$paddingBottom`.
@liamross
liamross / .prettierignore
Last active May 29, 2019 16:01
Basic prettier configs
# Ignore any files you wish to preserve format in (scss files?).
# somefile.scss
# Ignore build folders
dist
lib
storybook-build
# Ignore node modules folder
node_modules
@liamross
liamross / .eslintrc.yaml
Last active March 26, 2019 15:50
ESLint configuration for TypeScript
env:
browser: true
es6: true
commonjs: true
node: true
jest: true
settings:
react:
version: 'detect'
parser: '@typescript-eslint/parser'