Skip to content

Instantly share code, notes, and snippets.

View qubyte's full-sized avatar

Mark S. Everitt qubyte

View GitHub Profile
@qubyte
qubyte / uint8-array-to-base64.js
Created November 15, 2021 09:59
Convert a Uint8Array to base64.
/**
* There's no real reason to use this. Buffer is available in node:
*
* Buffer.from(typedArray.buffer).toString('base64');
*
* and the browser has atob/btoa (which are fine to use for the ascii
* characters used to represent bytes.
*/
function byteToBin(byte) {
@qubyte
qubyte / .eslintrc.json
Created March 26, 2020 10:10
Disallow .only in mocha test files.
{
"env": {
"mocha": true
},
"rules": {
"max-nested-callbacks": ["error", 7],
"no-restricted-properties": [
"error",
{ "object": "describe", "property": "only" },
{ "object": "context", "property": "only" },
@qubyte
qubyte / index.html
Created November 13, 2019 12:35
Conway's Game of Life. I put this together quickly as something to iterate on as a generative art project.
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module" src="index.js"></script>
<title>Game of Life</title>
<meta charset="utf-8">
</head>
<body>
<h1>Game of Life</h1>
<canvas width="600" height="600"></canvas>
@qubyte
qubyte / Cargo.toml
Last active August 18, 2022 12:10
My revised solution to Advent of code 2018 day 10 (both parts) in Rust, this time using recap.
[package]
name = "task-1"
version = "0.1.0"
authors = ["Mark S. Everitt <[email protected]>"]
edition = "2018"
[dependencies]
recap = "0.1"
serde = "1.0.90"
@qubyte
qubyte / Cargo.toml
Last active January 1, 2019 13:03
My solution to Advent of code 2018 day 10 (both parts) in Rust.
[package]
name = "task-1"
version = "0.1.0"
authors = ["Mark S. Everitt <[email protected]>"]
edition = "2018"
[dependencies]
regex = "1"
lazy_static = "1.2.0"
@qubyte
qubyte / d08-t2.rs
Last active December 9, 2018 11:59
Advent of Code 2018 day 8 task 2.
use std::io::{self, BufRead};
use std::str;
struct Node {
children: Vec<Box<Node>>,
metadata: Vec<usize>
}
impl Node {
fn evaluate(&self) -> usize {
@qubyte
qubyte / d06-t2.rs
Created December 7, 2018 04:13
Advent of Code day 06 task 2
use regex::Regex;
use std::io::{stdin, BufRead};
use std::cmp::{max};
#[macro_use]
extern crate lazy_static;
const MAX_TOTAL_DIST: usize = 10000;
fn abs_diff(a: &usize, b: &usize) -> usize {
@qubyte
qubyte / advent-of-code-2018-day-01-task-2.rs
Last active December 2, 2018 18:04
Advent of Code 2018 day 01 task 2.
use std::io::{stdin, BufRead};
use std::collections::BTreeSet;
fn main() {
let shifts: Vec<i32> = stdin().lock()
.lines()
.filter_map(|line| line.unwrap().parse().ok())
.collect();
let mut frequency = 0;
@qubyte
qubyte / d20p2.js
Created January 2, 2018 20:45
Advent of Code day 20 part 2
'use strict';
const rawInput = require('fs').readFileSync(process.argv[2], 'utf8').trim().split('\n');
const input = rawInput.map(line => {
const [p, v, a] = line.split(', ').map(part => part.slice(3, -1).split(',').map(n => parseInt(n, 10)));
return { p, v, a };
});
function isNaturalNumber(num) {
// Usage: node advent-of-code-2017-d04p2-boring.js /path/to/input.txt
// This boring version works by lexicographically sorting the characters
// in each word of the pass phrase, and then adding them all to a set.
// If the size of the set is less than the number of words in the
// passphrase, then at least one pair of words were anagrams of each
// other and the passphrase invalid.
'use strict';