Skip to content

Instantly share code, notes, and snippets.

Avatar

Conrad Ludgate conradludgate

View GitHub Profile
View async_stream.rs
#![feature(generators, generator_trait)]
use std::ops::Generator;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::Duration;
use futures_core::stream::Stream;
use futures_core::{FusedStream, Future};
use futures_util::{pin_mut, StreamExt};
View improve-build-times.debug
❯ cargo +nightly rustc --bin atuin -- -Z time-passes
*** SNIP EXTERNAL CRATES ***
Compiling atuin-common v0.7.1 (/home/oon/code/rust/atuin/atuin-common)
Compiling atuin-client v0.7.1 (/home/oon/code/rust/atuin/atuin-client)
Compiling atuin-server v0.7.1 (/home/oon/code/rust/atuin/atuin-server)
Compiling atuin v0.7.1 (/home/oon/code/rust/atuin)
time: 0.000; rss: 48MB -> 48MB ( +0MB) parse_crate
time: 0.000; rss: 48MB -> 48MB ( +0MB) attributes_injection
time: 0.000; rss: 51MB -> 51MB ( +0MB) incr_comp_prepare_session_directory
time: 0.000; rss: 51MB -> 51MB ( +0MB) incr_comp_garbage_collect_session_directories
View keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@conradludgate
conradludgate / combi4.rs
Last active May 23, 2021
Works with const generics
View combi4.rs
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_write_slice)]
#![feature(maybe_uninit_array_assume_init)]
use std::{mem::MaybeUninit};
fn main() {
let v = vec![1, 2, 3, 4, 5, 6];
for [a, b, c] in CombiIterator::new(v) {
println!("{:?} {:?} {:?}", a, b, c);
@conradludgate
conradludgate / combi3.rs
Last active May 23, 2021
Seems to work for any r and any n
View combi3.rs
fn main() {
let v = vec![1, 2, 3, 4, 5, 6];
let r = 3;
for x in CombiIterator::new(v, r) {
println!("{:?}", x);
}
}
#[derive(Debug, Clone)]
@conradludgate
conradludgate / combi2.rs
Created May 22, 2021
Works for r = 3, almost works for other r
View combi2.rs
use std::{fmt::Debug, ops::Range};
fn main() {
let mut v = vec![1, 2, 3, 4, 5, 6];
let r = 3;
for x in CombiIterator::new(&mut v, r) {
println!("{:?}", x);
}
}
@conradludgate
conradludgate / combi.rs
Last active May 21, 2021
Combinations Iterator
View combi.rs
// Outputs:
// [1, 2, 3], ([4, 5, 6])
// [1, 2, 4], ([5, 6, 3])
// [1, 2, 5], ([6, 3, 4])
// [1, 2, 6], ([3, 4, 5])
// [1, 3, 4], ([5, 6, 2])
// [1, 3, 5], ([6, 4, 2])
// [1, 3, 6], ([4, 5, 2])
// [1, 4, 5], ([6, 3, 2])
// [1, 4, 6], ([5, 3, 2])
View OOPExample1.py
fluffy = Labrador("fluffy")
scruffy = GoldenRetriever("scruffy")
cat = Cat(fluffy)
cat.say() # Meow, I am a cat and my enemy says: 'Bark, I am a Labrador'
cat.move() # I am running away from fluffy
scruffy.say() # Bark, I am a Golden Retriever
scruffy.move() # I am chasing cats
View training.py
# Imports for word2vec
from gensim.test.utils import common_texts, get_tmpfile
from gensim.models import Word2Vec, KeyedVectors
# imports for tensorflow
import tensorflow as tf
# Numpy
import numpy as np
@conradludgate
conradludgate / euclidian.py
Created Sep 26, 2018
Euclidian Algorithm
View euclidian.py
import sys
# Example usage
# $ python euclidian.py 1745 1485
# gcd(1745, 1485) = (1 + 297n) * 1745 - (0 + 349n) * 1485 = 5
# The euclidian algorithm took 6 steps
a = int(sys.argv[1]) # 1745
b = int(sys.argv[2]) # 1485