Skip to content

Instantly share code, notes, and snippets.

@joshnuss
joshnuss / httpStore.js
Last active October 11, 2023 11:29
A Svelte store backed by HTTP
import { writable } from 'svelte/store'
// returns a store with HTTP access functions for get, post, patch, delete
// anytime an HTTP request is made, the store is updated and all subscribers are notified.
export default function(initial) {
// create the underlying store
const store = writable(initial)
// define a request function that will do `fetch` and update store when request finishes
store.request = async (method, url, params=null) => {
@jansim
jansim / vulgar_fractions.js
Last active May 4, 2022 02:33
Unicode Vulgar Fractions in JavaScript / JSON
// Vulgar fractions are Unicode characters for specific fractions i.e. ½
// List of fractions from: https://stackoverflow.com/questions/35012491/parse-%C2%BD-as-0-5-in-python-2-7
// See also: http://unicodefractions.com/
// Calculate fractions on-the-fly
const vulgar_fractions = {
'\u2189': 0/3,
'\u2152': 1/10,
'\u2151': 1/9,
@brandenbyers
brandenbyers / recipe-testing.md
Created August 12, 2019 03:26
Testing a recipe ingredient parser

Testing a recipe ingredient parser

The following lesson will introduce you to the basics of unit testing. More importantly, it will show you how to think like a tester.

Testing Infrastructure

We will be using Mocha and Chai. Mocha is the test runner; a framework for taking your test code and running the tests automatically. Chai is the assertion library; the syntax that you will use to write your tests.

Chai comes in three flavors: assert, should, and expect. For this lesson we will be using expect; an expressive and super readible style.