Skip to content

Instantly share code, notes, and snippets.

0e4ef622 0e4ef622

View GitHub Profile
@0e4ef622
0e4ef622 / headset_buttons.py
Created Apr 20, 2020
Detects the built-in play/pause button on wired earbuds/headsets by monitoring the microphone.
View headset_buttons.py
#!/usr/bin/env python3
#
# Detects the built-in play/pause button on wired earbuds/headsets by
# monitoring the microphone.
#
# The script outputs a line containing either "press" or "release" whenever
# a press or release is detected.
#
# This script works by detecting a period of high (near maximum) sample values
# followed quickly by a period of low (near minimum) sample values, or vice
View scrape_osu_country_leaderboards.py
#!/usr/bin/env python3
import os
import re
import requests
from time import sleep
countries = [
"US", "RU", "DE", "PL", "FR", "JP", "CA", "BR", "GB", "TW",
"KR", "CN", "AU", "ID", "UA", "PH", "CL", "FI", "AR", "NL",
View lambdas.py
(lambda p:(lambda f:(lambda x:x(x))(lambda x:f(lambda v:x(x)(v))))(lambda f:lambda n:n(lambda x:lambda x:f((lambda n:lambda f:lambda x:n(lambda g:lambda h:h(g(f)))(lambda u:x)(lambda u:u))(n))((lambda a:lambda b:lambda x:(lambda a:lambda b:a(b)(a))(a)(b)(p("FizzBuzz"))(a(p("Fizz"))(b(p("Buzz"))(p(n(lambda x:x+1)(0))))))((lambda d:lambda n:(lambda f:(lambda x:x(x))(lambda x:f(lambda v:x(x)(v))))(lambda f:lambda n:(lambda n:n(lambda x:lambda a:lambda b:b)(lambda a:lambda b:a))(n)(lambda x:lambda a:lambda b:b)((lambda a:lambda b:a(b)(a))((lambda n:n(lambda x:lambda a:lambda b:b)(lambda a:lambda b:a))((lambda n:lambda m:m(lambda n:lambda f:lambda x:n(lambda g:lambda h:h(g(f)))(lambda u:x)(lambda u:u))(n))(n)(d)))((lambda n:n(lambda x:lambda a:lambda b:b)(lambda a:lambda b:a))((lambda n:lambda m:m(lambda n:lambda f:lambda x:n(lambda g:lambda h:h(g(f)))(lambda u:x)(lambda u:u))(n))(d)(n)))(lambda x:lambda a:lambda b:a)(lambda x:f((lambda n:lambda m:m(lambda n:lambda f:lambda x:n(lambda g:lambda h:h(g(f)))(lambda u:
@0e4ef622
0e4ef622 / solution.rs
Created Dec 17, 2019
aoc 2019 day 17
View solution.rs
use std::collections::*;
use std::borrow::Cow;
use rand::random;
pub fn part1(input: &str) -> impl std::fmt::Display {
let prog = input.trim().split(",").map(|x| x.parse::<i128>().unwrap()).collect::<Vec<_>>();
let mut vm = ic::Icvm::new(prog);
vm.run();
@0e4ef622
0e4ef622 / phase.rs
Created Dec 16, 2019
day 16 phase calculator
View phase.rs
fn next_phase(nums: &[i64], strt: usize) -> Vec<i64> {
let mut pfs = vec![0];
pfs.extend(nums);
for i in 1..pfs.len() {
pfs[i] += pfs[i-1];
}
let mut newl = Vec::with_capacity(nums.len());
for n in strt..nums.len()+strt {
@0e4ef622
0e4ef622 / part2.rs
Last active Dec 16, 2019
aoc 2019 day 16 part 2
View part2.rs
pub fn part2(input: &str) -> i64 {
// parse input
let onums = input
.trim()
.bytes()
.map(|x| (x - b'0') as i64)
.collect::<Vec<_>>();
let offset = input[..7].parse::<usize>().unwrap();
@0e4ef622
0e4ef622 / solution.rs
Created Dec 13, 2019
aoc 2019 day 13
View solution.rs
use std::collections::*;
pub fn part1(input: &str) -> impl std::fmt::Display {
let prog = input.trim().split(",").map(|x| x.parse().unwrap()).collect();
let mut vm = ic::Icvm::new(prog);
vm.run();
let mut map = HashMap::new();
let a = vm.drain_outputs().collect::<Vec<_>>();
for ch in a.chunks(3) {
map.insert((ch[0], ch[1]), ch[2]);
}
@0e4ef622
0e4ef622 / solution.rs
Created Dec 11, 2019
aoc 2019 day 11
View solution.rs
use std::collections::*;
pub fn part1(input: &str) -> impl std::fmt::Display {
let mut botp = (0i128, 0i128);
let mut botd = 0i32; // 0 = up, 1 = right, 2 = down, 3 = left
let mut vm = ic::Icvm::new(input.trim().split(",").map(|x| x.parse::<i128>().unwrap()).collect());
let mut paint = HashMap::new();
while vm.status() != ic::Status::Finished {
vm.run();
View main.rs
use std::io::Read;
mod solution;
// const INPUT: &'static str = include_str!("../in");
fn main() {
let mut input = String::new();
std::io::stdin().read_to_string(&mut input);
let p1 = solution::part1(&input);
println!("part 1: {}", p1);
let p2 = solution::part2(&input);
println!("part 2: {}", p2);
View vm.rs
use std::collections::VecDeque;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Status {
Ready,
WaitingForInput,
Finished,
}
#[derive(Clone, Debug)]
You can’t perform that action at this time.