Skip to content

Instantly share code, notes, and snippets.

View kinnison's full-sized avatar
🦀
Generally tired, confused, and unhelpful.

Daniel Silverstone kinnison

🦀
Generally tired, confused, and unhelpful.
View GitHub Profile
@kinnison
kinnison / shonky-queens.py
Last active December 15, 2022 15:54
Shonky attempt at queens problem
def queens(n, i, a, b, c):
if i < n:
for j in range(n):
if j not in a and i+j not in b and i-j not in c:
yield from queens(n, i+1, a+[j], b+[i+j], c+[i-j])
else:
yield a
def sudoku_ok(solution):
Command Mean [ms] Min [ms] Max [ms] Relative
../target/release/2020day1 24.1 ± 3.8 20.2 40.4 25.88 ± 7.99
../target/release/2020day2 2.5 ± 0.9 1.8 14.4 2.67 ± 1.18
../target/release/2020day3 1.2 ± 1.1 0.7 25.8 1.33 ± 1.21
../target/release/2020day4 2.2 ± 0.7 1.5 12.5 2.34 ± 1.00
../target/release/2020day5 1.2 ± 0.6 0.8 16.5 1.30 ± 0.69
../target/release/2020day6 2.2 ± 0.6 1.6 6.6 2.38 ± 0.87
../target/release/2020day7 14.7 ± 3.8 12.1 43.6 15.84 ± 5.88
../target/release/2020day8 4.8 ± 0.9 4.0 9.2 5.14 ± 1.67
@kinnison
kinnison / hash-borrow.rs
Last active May 30, 2019 07:31
A mechanism to think about hash and borrow implementations
// Related to a comment from @nrc regarding Hash<Ty> and Borrow<Ty> interactions...
// I wonder if a generic hash implementation of:
impl<Outer: Borrow<Inner>, Inner: Hash> Hash for Outer {
fn hash<H: Hasher>(self: &Outer, state: &mut H) {
self.borrow().hash(state);
}
}
// Might solve the issue? Or at least mean that there's a generic way to deal with it?
@kinnison
kinnison / iter-snippet.rs
Last active April 10, 2018 12:23
Iterator stream snippet
trace!("Preparing an Interval to run the requests");
let always_defs = futures::stream::iter_ok(raw_defs.iter().cycle());
let every_100ms = Interval::new(Instant::now(), Duration::from_millis(100));
let zipped = every_100ms.zip(always_defs);
tokio::spawn(zipped.map_err(|_| ()).for_each(move |(_, def)| {
let req = def.request();
let dest = req.sendto();
let packet = req.packet().to_vec();
let targ = sender.clone();
@kinnison
kinnison / socketcan-stream.rs
Created March 27, 2018 20:47
Join the socketcan and tokio crates together!
extern crate socketcan;
extern crate tokio;
extern crate futures;
extern crate mio;
use mio::{Ready, Poll, PollOpt, Token};
use mio::event::Evented;
use mio::unix::EventedFd;
use tokio::reactor::PollEvented2;

Keybase proof

I hereby claim:

  • I am kinnison on github.
  • I am kinnison (https://keybase.io/kinnison) on keybase.
  • I have a public key whose fingerprint is 1956 8523 759E 2A28 58F4 606B 3CCE BABE 206C 3B69

To claim this, I am signing this object: