Skip to content

Instantly share code, notes, and snippets.

View skulptur's full-sized avatar
👹
_

skulptur

👹
_
  • Berlin - Germany
View GitHub Profile
@skulptur
skulptur / .prettierrc
Created February 2, 2019 02:19
The best prettier settings ever
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"jsxBracketSameLine": false,
"jsxSingleQuote": true,
@skulptur
skulptur / parseJSON.ts
Created December 19, 2019 14:44
parse json safely using promises
export const parseJSON = <T = {}>(json: string) => {
return new Promise<T>((resolve, reject) => {
try {
resolve(JSON.parse(json));
} catch (error) {
reject(error);
}
});
};
@skulptur
skulptur / git_useConfigOnly.bash
Created March 10, 2020 22:58
prevent common issue of committing with wrong email account
$ cat ~/.gitconfig
[user]
useConfigOnly = true
// https://medium.com/@reidev275/creating-a-type-safe-dsl-for-filtering-in-typescript-53fe68a7942e
export type Filter<A> =
| { kind: 'Equals'; field: keyof A; val: A[keyof A] }
| { kind: 'Greater'; field: keyof A; val: A[keyof A] }
| { kind: 'Less'; field: keyof A; val: A[keyof A] }
| { kind: 'And'; a: Filter<A>; b: Filter<A> }
| { kind: 'Or'; a: Filter<A>; b: Filter<A> }
export const equals = <A, K extends keyof A>(
field: K,
@skulptur
skulptur / createPath.ts
Created February 1, 2021 13:43
Util for replacing params in a React router style url config
/**
* Builds a path from a template and replaces the params
*
* @function createPath
* @param path The configured path (e.g. /foo/:bar)
* @param params The param values you want to replace it with (e.g. \{bar: 'baz'\})
* @param search Any query string values that you want to add
* @category routing
*/
export const createPath = (