Skip to content

Instantly share code, notes, and snippets.

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 {}
@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
}
@b-barry
b-barry / tutorial.md
Created June 15, 2018 13:17 — forked from swalkinshaw/tutorial.md
Designing a GraphQL API

Tutorial: Designing a GraphQL API

This tutorial was created by Shopify for internal purposes. We've created a public version of it since we think it's useful to anyone creating a GraphQL API.

It's based on lessons learned from creating and evolving production schemas at Shopify over almost 3 years. The tutorial has evolved and will continue to change in the future so nothing is set in stone.

<?
// this bot tries to match chat messages to previous forum posts and links to them
require_once(__DIR__.'/../app/config.php');
require_once(__DIR__.'/../app/functions.php');
loadDbs(array('users_global','messages','questions'));
var axios = require('axios');
var firebase = require('firebase').initializeApp({
"serviceAccount": "./service-account.json",
"databaseURL": "https://quiver-two.firebaseio.com/"
});
var ref = firebase.app().database().ref();
var peopleRef = ref.child('swapi/people');
// Calling ref.toString() outputs the ref's entire path: https://...firebaseio.com/some/ref/path
var peopleUrl = peopleRef.toString() + '.json?shallow=true';
@b-barry
b-barry / index.html
Created November 30, 2018 07:25 — forked from karbassi/index.html
How to handle single and double click events separately in javascript.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Single and Double Click</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="the_div"></div>
<span>Double click the block</span>
@b-barry
b-barry / gitclean.sh
Created April 20, 2019 06:29 — forked from ericelliott/gitclean.sh
gitclean.sh - cleans merged/stale branches from origin
git remote prune origin
git branch -r --merged master | egrep -iv '(master|develop)' | sed 's/origin\///g' | xargs -n 1 git push --delete origin
@b-barry
b-barry / github_bitbucket_multiple_ssh_keys.md
Created April 22, 2019 09:18 — forked from yinzara/github_bitbucket_multiple_ssh_keys.md
Managing SSH keys and repo cloning using multiple accounts on GitHub and BitBucket

Why Multiple SSH keys?

There are numerous reasons you may need to use multiple SSH keys for accessing GitHub and BitBucket

You may use the same computer for work and personal development and need to separate your work.

When acting as a consultant, it is common to have multiple GitHub and/or BitBucket accounts depending on which client you may be working for.

You may have different projects you're working on where you would like to segregate your access.

function usePromise(createPromise) {
const [error, setError] = useState()
const [value, setValue] = useState()
useEffect(() => {
let current = true
createPromise().then(
value => {
if (current) setValue(value)
@b-barry
b-barry / remove-all-from-docker.sh
Last active June 16, 2019 20:20 — forked from beeman/remove-all-from-docker.sh
Remove all from Docker
# One command
docker stop `docker ps -qa` && docker rm `docker ps -qa` && docker rmi -f `docker images -qa ` && docker volume rm $(docker volume ls -qf) && docker network rm `docker network ls -q`
# Stop all containers
docker stop `docker ps -qa`
# Remove all containers
docker rm `docker ps -qa`
# Remove all images