Skip to content

Instantly share code, notes, and snippets.

View victor-iyi's full-sized avatar
🎯
Focusing

Victor I. Afolabi victor-iyi

🎯
Focusing
View GitHub Profile
@victor-iyi
victor-iyi / simple-audio-recognition.ipynb
Created November 22, 2022 17:26
simple-audio-recognition.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@victor-iyi
victor-iyi / text-to-image.ipynb
Created November 18, 2022 23:30
text-to-image.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@victor-iyi
victor-iyi / flatten.rs
Created August 25, 2022 19:29
Implementation of flattening nested iterators
/// Returns an [`Flatten`] - an object that flattens a given iterable.
///
/// [`Flatten`]: struct.Flatten
pub fn flatten<I>(iter: I) -> Flatten<I::IntoIter>
where
I: IntoIterator,
I::Item: IntoIterator,
{
Flatten::new(iter.into_iter())
}
@victor-iyi
victor-iyi / max_value.rs
Created August 23, 2022 18:12
Handy use of Rust's declarative macro
trait MaxValue {
fn max_value() -> Self;
}
macro_rules! max_impl {
($t:ty) => {
impl crate::MaxValue for $t {
fn max_value() -> Self {
<$t>::max_value()
}
@victor-iyi
victor-iyi / vecmac.rs
Created August 23, 2022 18:10
Rust's vec![...] macro re-implementation
#[macro_export]
macro_rules! avec {
($($element:expr),*) => {{
const COUNT: usize = crate::count![@COUNT; $($element),*];
#[allow(unused_mut)]
let mut vs = Vec::with_capacity(COUNT);
$(vs.push($element);)*
vs
}};
@victor-iyi
victor-iyi / strsplit.rs
Created August 20, 2022 18:55
String split in Rust
#[derive(Debug)]
pub struct StrSplit<'haystack, D> {
remainder: Option<&'haystack str>,
delimiter: D,
}
impl<'haystack, D> StrSplit<'haystack, D> {
pub fn new(haystack: &'haystack str, delimiter: D) -> Self {
Self {
remainder: Some(haystack),
@victor-iyi
victor-iyi / instance-of.rs
Last active November 15, 2021 07:57
Implement InstanceOf trait in Rust
use std::any::{Any, TypeId};
trait InstanceOf
where
Self: Any
{
fn instance_of<U: ?Sized + Any>(&self) -> bool {
TypeId::of::<Self>() == TypeId::of::<U>()
}
}
@victor-iyi
victor-iyi / swap_without_if.py
Created March 31, 2021 06:50
A function that takes 4 or 7 as input and returns 7 or 4 [f(4) = 7 OR f(7) = 4] WITHOUT USING if-statement
"""Implement a function which takes an integer which does the following:
- if input is 4: it returns 7
- if input is 7: it returns 4
Otherwise (unspecified).
However:
CANNOT USE `if-statement`.
To Run:
@victor-iyi
victor-iyi / quantum-hello-world.py
Created March 22, 2021 05:38
Hello World Quantum computing using Google's cirq library
import cirq
# print(cirq.google.Sycamore)
a = cirq.NamedQubit('a')
b = cirq.NamedQubit('b')
# Create Circuit (logic-gate like)
circuit = cirq.Circuit(
cirq.H(a),
@victor-iyi
victor-iyi / anagram.py
Last active March 12, 2021 06:22
Check if two words are anagram
"""Classic interview question to check if two words are anagram."""
import collections
import itertools
import pytest
def is_anagram(first: str, second: str) -> bool:
"""Implementation of anagram checker with 3 different methods.
Note: