Skip to content

Instantly share code, notes, and snippets.

@umcconnell
umcconnell / README-Template.md
Created May 9, 2019 16:18 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
@umcconnell
umcconnell / API.md
Created May 11, 2019 14:10 — forked from iros/API.md
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

@umcconnell
umcconnell / pipe.js
Created May 26, 2019 16:39
Curried JS pipe function
/**
* JS Curried Pipe Function
*
* @param {array} arr input function chain
* @example
* let calculateCost = pipe([
* products => products.reduce(plus), // Total Price
* price => price * 1.2, // Tax
* price => price - 50 // Discount
* ]);
@umcconnell
umcconnell / wait.js
Created May 26, 2019 16:50
Fancy JS setTimeout function
/**
* JS promisified setTimeout
*
* @param {number} ms timeout time in ms
* @example
* wait(2000).then(console.log)
* // => logs after 2 seconds
* @returns {Promise} A promise that resolves after the specified time `ms`
*/
let wait = ms => new Promise(res => setTimeout(res, ms));
@umcconnell
umcconnell / curry.js
Created May 26, 2019 16:52
Curry a JS function
/**
* Takes a function and curries it
* @param {function} func input non-curried function
* @param {number} [amountArgs=func.length] number of arguments to collect; defaults to func.length
* @example
* let plus = (a, b) => a+b;
* let curriedPlus = curry(plus);
* curriedPlus(1)(2)
* // => 3
* @returns a collect function for collecting the arguments and calling the input function
@umcconnell
umcconnell / fib.js
Last active August 20, 2019 14:52
Recursive fibonacci sequence
/**
* Generate the fibonaccie sequence recursively
* @param {number} num amount of recursion
* @returns {array} fibonacci sequence
*/
let fib = num => {
if (num == 1) return [1];
else {
let prev = fib(num - 1);
return prev.concat((prev[prev.length - 2] || 0) + prev[prev.length - 1])
@umcconnell
umcconnell / loader.js
Created November 26, 2019 18:00
Loading animation for node console
// Adapted from https://stackoverflow.com/questions/34848505/how-to-make-a-loading-animation-in-console-application-written-in-javascript-or
/**
* Create and display a loader in the console.
*
* @param {string} [text=""] Text to display after loader
* @param {array.<string>} [chars=["⠙", "⠘", "⠰", "⠴", "⠤", "⠦", "⠆", "⠃", "⠋", "⠉"]]
* Array of characters representing loader steps
* @param {number} [delay=100] Delay in ms between loader steps
* @example
@umcconnell
umcconnell / fib.rs
Last active August 18, 2020 14:17
Generate the Fibonacci Sequence in Rust.
pub struct Fib {
a: u32,
b: u32,
count: i32,
}
impl Fib {
pub fn new(count: i32) -> Fib {
Fib { a: 1, b: 1, count }
}
@umcconnell
umcconnell / fizzbuzz.rs
Created July 7, 2020 13:48
Fizzbuzz in Rust
fn main() {
for x in 1..101 {
let mut out = String::new();
if x % 3 == 0 {
out += "fizz";
}
if x % 5 == 0 {
out += "buzz";