Skip to content

Instantly share code, notes, and snippets.

@ClickerMonkey
ClickerMonkey / types.ts
Last active August 8, 2024 00:25
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]
@swalkinshaw
swalkinshaw / tutorial.md
Last active June 6, 2025 19:24
Designing a GraphQL API
@b-barry
b-barry / InstallMissingModules.js
Created November 29, 2016 07:37 — forked from Hendrixer/InstallMissingModules.js
list and install npm packages before webpack build
const thenify = require('thenify')
const webpack = require('webpack')
const MemoryFS = require('memory-fs')
const validateNpmPackageName = require('validate-npm-package-name')
class InstallMissingModules {
constructor(options) {
this.options = options
}

Angular 2 uses observables for many features and has a peer dependency on RxJs for its robust API around observables. The community has adopted a single store approach for dealing with state in modern applications. Let's build a store for our Angular applications that is both reactive and easy to use with RxJs.

Single store is awesome

We'll create this store with intentions on it being the only store in our app. By doing this, we can provide a better experience and lower the difficulty of reasoning about state in our app, because all the state is in one place! First we'll create the provider for the store itself.

export class AppStore {}

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

@robmiller
robmiller / git-cleanup-repo
Last active November 24, 2024 19:55
A script for cleaning up Git repositories; it deletes branches that are fully merged into `origin/master`, prunes obsolete remote tracking branches, and as an added bonus will replicate these changes on the remote.
#!/bin/bash
# git-cleanup-repo
#
# Author: Rob Miller <rob@bigfish.co.uk>
# Adapted from the original by Yorick Sijsling
git checkout master &> /dev/null
# Make sure we're working with the most up-to-date version of master.
git fetch