Skip to content

Instantly share code, notes, and snippets.

View moosch's full-sized avatar
🦄
Trying stuff

Ryan Whitlie moosch

🦄
Trying stuff
View GitHub Profile
@moosch
moosch / code_kata.txt
Last active September 6, 2020 05:46
Code Kata
## Problem A - WHAT!?!?!
Many of us who have worked in the office, miss it. We miss hanging out with our friends, we miss the energy and sometimes we even miss the loud music.
Remember the dubstep Christmas carols playlist? It was awesome!
Write a function called what which will decipher the conversation from the loud music.
Input
The input will consist of a single string of words, punctuated by WUBs. There are 0 or more WUBs at the start and at the end. There will be 1 or more WUBs between each word.
/**
* A demonstration of building a Type Class in JavaScript with a custom DataType.
*
* This is a simple container that has three defined properties.
* The type methods are functional, mutating none of it's contents.
*/
const typeGuard = (ExpectedType, data) => {
if (!ExpectedType) {
throw new ReferenceError('Expected a Type as first argument');
/**
* Semigroup
*
* A Semigroup must have a concat method.
* Just like JS Array and String
*
* It simply takes 2 of the same datatype, concats them and returns that same datatype
*
* The type signature for the concat method:
* concat :: Semigroup a => a ~> a -> a
@moosch
moosch / svg-attack-vector.svg
Created August 2, 2018 23:05
A simple way to execute JS inside a browser-loaded SVG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
const register = async params => {
const verifyParams = await verify(params);
const passwordMatch = await passwordCheck(params);
const user = await createUser(params);
return { verifyParams, passwordMatch, user };
};
register({
username: 'moosch',
password: 'terryfolds',
const register = async params => {
let verifyParams;
try {
verifyParams = await verify(params);
} catch(error) {
throw new Error(error);
}
let passwordMatch;
try {
@moosch
moosch / example-nested-promise-calls.js
Last active March 6, 2018 21:43
A nested approach to calling async functions
const register = params => {
return verify(params)
.then(() => {
return passwordMatch(params)
.then(() => {
return createUser(params)
.then(user => {
// Awesome!
return user;
})
@moosch
moosch / example-promises.js
Last active March 6, 2018 21:54
Simple promise based functions for creating a user
const verify = params => {
return new Promise((resolve, reject) => {
const { username, password, confPassword } = params;
if (!username || !password || !confPassword) {
reject('Invalid params');
}
resolve({ username, password, confPassword });
});
}
@moosch
moosch / example-async-function.js
Created March 6, 2018 21:29
Example of calling an async function
const getUser = id => {
// Database call (with mongoose in this example)
  return User.findOne({ id });
};
getUser(‘xyz’)
.then(user => {
// Yay! I got my user
})
.catch(error => {
@moosch
moosch / example-promise.js
Last active March 6, 2018 21:29
Example of making an async function
const getUser = id => {
return new Promise((resolve, reject) => {
// Some kind of find, but not truely async
const user = {
id: 'xyz',
name: 'Hellboy',
};
if (id === user.id) {
resolve(user);
}