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 / chatgpt.py
Created August 19, 2024 06:30
Evaluate the output of Large Language Models based on how helpful the results are from Not Helpful to Highly helpful on a likert scale
import logging
import os
import pathlib
import re
import time
from typing import Any
import jsonlines
import openai
import torch
@victor-iyi
victor-iyi / gcd.rs
Created November 8, 2020 21:42
Greatest common divisor in Rust
/// Computes the greatest common divisor of two integers using Euclid's algorithm
/// (https://en.wikipedia.org/wiki/Euclidean_algorithm).
///
/// # Example
///
/// ```rust
/// assert_eq!(gcd(3, 5), 1);
///
/// assert_eq!(gcd(2 * 3 * 5 * 11 * 17, 3 * 7 * 11 * 13 * 19), 3 * 11);
/// ```
@victor-iyi
victor-iyi / simple-audio-recognition.ipynb
Created November 22, 2022 17:26
simple-audio-recognition.ipynb
Loading
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
Loading
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 / vector.py
Last active November 15, 2021 12:46
A light weight vector utility class
from typing import Generic
from typing import Iterable
from typing import TypeVar
# Generic type.
T = TypeVar('T')
class Vector(Generic[T]):
"""A light-weight Vector utility class, used to perform various operations
@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>()
}
}