Skip to content

Instantly share code, notes, and snippets.

View qubyte's full-sized avatar

Aura Everitt qubyte

View GitHub Profile
@qubyte
qubyte / getScrollAmount.js
Created October 13, 2016 17:17
Little function to get the amount a document has been scrolled by.
function getScrollAmount() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
return scrollTop / (scrollHeight - document.documentElement.clientHeight);
}
@qubyte
qubyte / gyoza.md
Last active August 25, 2020 15:21

Miya's famous gyoza

Miya makes gyoza on the fly, and doesn't work to exact quantities. However, this recipe is what she used the last time we made some.

Step 1

For the first step you will need:

  • 3 cloves of garlic, finely diced or minced
  • 2 tbsp ginger, finely diced or minced
@qubyte
qubyte / arcade.ino
Last active July 4, 2021 13:10
Arduino Leonardo code to behave as a keyboard with pins set to MAME-ish key bindings.
#include <Keyboard.h>
// MAMEish. An array of pin-key pairs.
struct { int pin; int key; } pinsToKeys[] = {
{ 2, KEY_LEFT_ARROW },
{ 3, KEY_UP_ARROW },
{ 4, KEY_RIGHT_ARROW },
{ 5, KEY_DOWN_ARROW },
{ 6, KEY_LEFT_CTRL }, // Fire 1
{ 7, KEY_LEFT_ALT }, // Fire 2
@qubyte
qubyte / observe-key.js
Created May 27, 2017 13:37
A module which returns an observable for a key. It streams `pressed` and `released` observations. Also has a getter for the pressed state of a key.
import Observable from 'zen-observable';
export default function observeKey(key) {
let pressed = false;
const observable = new Observable(observer => {
function downHandler(e) {
if (e.key === key && !pressed) {
pressed = true;
observer.next('pressed');
@qubyte
qubyte / json.js
Last active September 3, 2017 12:24
rollup plugin for wrapping a JSON file in a module with a default export only. This avoids the issue of fields being invalid names.
// An as-simple-as-possible JSON plugin for rollup. This plugin turns a JSON
// file into a module with a default export. No named exports are given since
// field names are not always valid names.
// Originally drawn from the official JSON plugin.
function buildAst(code) {
return {
type: 'Program',
sourceType: 'module',
// 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';
@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) {
@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 / 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 / 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 {