Skip to content

Instantly share code, notes, and snippets.

View willowell's full-sized avatar
🤖
Pressing the "do my job" key

William Howell willowell

🤖
Pressing the "do my job" key
  • Toronto, Ontario, Canada
View GitHub Profile
// for instance, this TS function
import fetch from "node-fetch";
const getData = async (url: string): Promise<any | null> => {
try {
const response = await fetch(url);
const json = await response.json();
return json;
} catch (error) {
@willowell
willowell / input.rs
Last active July 11, 2020 02:25
trouble translating Haskell functions to Rust
The Haskell functions I am trying to translate:
promptLine :: String -> IO String
promptLine msg = do
putStr msg
hFlush stdout
getLine
input :: Read a => String -> (a -> Bool) -> IO a
input msg validator = do
@willowell
willowell / main.cpp
Last active March 6, 2020 20:59
C++17 File Open
// Requires at least C++17
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
int main() {
// Path is relative to executable.
std::filesystem::path filePath = "./out.txt";
@willowell
willowell / main.cpp
Last active January 27, 2020 07:04
Playing with C++20 concepts
// Try it out on https://godbolt.org/ with Clang with concepts!
// GitHub insists on this having a tab size of 8 even though I told it to use 4, even after deleting and reuploading this. :-(
// Please excuse the massive indents!
#include <iostream>
#include <type_traits>
namespace MyProject {
template <typename T>
@willowell
willowell / main.cpp
Last active January 11, 2020 10:08
Pizza Problem
///! Version: C++17
#include <algorithm> // for std::reverse()
#include <cstdint> // int64_t
#include <filesystem> // std::filesystem::path
#include <fstream> // std::ifstream, std::ofstream
#include <iostream> // the usual console I/O stuff
#include <sstream> // istringstream for parsing a string, see split() below
#include <string> // std::getline(), std::stol()
#include <vector>