Skip to content

Instantly share code, notes, and snippets.

View Mathspy's full-sized avatar
💭
Working on few big surprises! 🌸

Mathspy

💭
Working on few big surprises! 🌸
View GitHub Profile
@Mathspy
Mathspy / comparison.md
Last active November 4, 2022 09:52
Visual diffing algorithms comparison

Thanks to Awesome Visual Regression Testing and Screenster.io for compiling lists of the things in the space. The research into what each uses was done by me through digging their code or their READMEs.

  • OSnap: ReasonML. Uses ODiff, the main contender I am looking at.
  • basset: Python. Uses a handrolled algorithm, looks fairly naive, only 63 lines of code
  • AyeSpy: JavaScript. Uses looks-same
  • Wraith: Ruby. Uses ImageMagick (shells out to it). Made by BBC lol
  • BackstopJS: JavaScript. Uses hash comparison then @mirzazeyrek/node-resemble-js a fork of Resemble.js.
  • Galen: Java. Uses a handrolled algorithm named rainbow4j. Think they might be looking for a new name now.
  • Creevey: JavaScript. Uses pixelmatch.
@Mathspy
Mathspy / cloudflare-workers-deno.ts
Created December 25, 2021 15:00
Deno types for CloudFlare Workers
interface ExecutionContext {
waitUntil(promise: Promise<any>): void;
passThroughOnException(): void;
}
interface ExportedHandler<Env = unknown> {
fetch?: ExportedHandlerFetchHandler<Env>;
scheduled?: ExportedHandlerScheduledHandler<Env>;
}
@Mathspy
Mathspy / zero_alloc_html_rendere.rs
Last active November 19, 2021 09:10
Zero allocation HTML renderer with escaping
#![no_std]
extern crate alloc;
use alloc::borrow::Cow;
use core::iter;
enum Tag {
/// A non-HTML tag that renders into nothing for wrapping text
Fragment,
@Mathspy
Mathspy / dir_entry_test_util.rs
Created October 19, 2021 15:58
Get a breakdown of a directory
use std::{
collections::HashSet,
ffi::OsString,
fs,
hash::{Hash, Hasher},
path::Path,
};
#[derive(Debug, PartialEq, Eq)]
pub enum DirEntry {
@Mathspy
Mathspy / is_reader_ready.rs
Created May 10, 2020 12:48
Detect if a reader is ready to be read from
async fn is_reader_ready<R>(reader: &mut R) -> bool where R: AsyncRead + Unpin {
let mut me = &mut *reader;
poll_fn(|cx| {
let mut v = [];
Poll::Ready(Pin::new(&mut me).poll_read(cx, &mut v[..]).is_ready())
}).await
}
@Mathspy
Mathspy / i_can_write_unsafe_ma.rs
Last active April 24, 2020 11:52
My first sound unsafe code lol
use std::{
pin::Pin,
task::{Context, Poll},
};
use tokio::io::AsyncRead;
enum Either<T, U> {
A(T),
B(U),
}
@Mathspy
Mathspy / example_custom_serde_derive.rs
Created April 4, 2020 18:09
Example of how to derive a custom `serde` Deserialize
use serde::{Deserialize, de::{self, Deserializer, Visitor}};
use std::fmt;
#[derive(Debug)]
enum Shape {
Triangle = 3,
Rectangle = 4,
Pentagon = 5,
}
@Mathspy
Mathspy / debugging_timer.js
Created December 24, 2019 23:20
A utility for debugging JS timeouts
require('log-timestamp');
const timers = [];
function setTimeout(fn, time) {
const ret = global.setTimeout(() => {
console.log(`Finished timer ${timers.indexOf(ret)} after ${time}`);
fn();
}, time);
console.log(`Started timer ${timers.push(ret) - 1} with ${time}`);
@Mathspy
Mathspy / tuple_combinations_while.rs
Last active August 22, 2019 22:57
A Tuple Combination iterator like the one in Itertools but with short-circuiting
// This is the trait that has .tuple_combinations_while()
trait HasTupleCombinationWhile: Iterator {
/// Return an iterator adaptor that iterates over the combinations of the elements from an iterator.
/// With the added beneift of being able to short-circuit
fn tuple_combinations_while<P>(
mut self,
predicate: P,
) -> TupleCombinationsWhile<Self, Self::Item, P>
where
Self: Clone,
@Mathspy
Mathspy / all_primes_iter.rs
Last active August 21, 2019 21:48
All the prime numbers your heart desires in Rust!
// Use this if you want [2, 3, 5.....]
use std::collections::HashMap;
/// This is a prime number generator based on [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)
/// that can be _trivially_ improved by switching to [Sieve of Atkin](https://en.wikipedia.org/wiki/Sieve_of_Atkin) for extra speed
struct PrimeIterator {
current: u64,
composite_to_primes: HashMap<u64, Vec<u64>>,
}