Skip to content

Instantly share code, notes, and snippets.

View Kerollmops's full-sized avatar
🍼
Meilisearch needs care

Clément Renault Kerollmops

🍼
Meilisearch needs care
View GitHub Profile
@Kerollmops
Kerollmops / user-typing.lua
Last active November 26, 2019 20:54
wrk script that simulate user typing queries
full_query = "I love paris and new york with my friends "
length = 1
local char_to_hex = function(c)
return string.format("%%%02X", string.byte(c))
end
local function urlencode(url)
if url == nil then
return
@Kerollmops
Kerollmops / zerocopy-lmdb.rs
Last active October 4, 2019 08:13
This little bit of code could makes the lmdb usage really easy and fast
use std::{io, marker, str};
use std::borrow::Cow;
use zerocopy::{LayoutVerified, AsBytes, FromBytes};
use serde::{Serialize, Deserialize, de::DeserializeOwned};
// Do not forget to patch zerocopy to make it support str
// by using the `trivial_bounds` feature
pub trait EPAsBytes {
fn as_bytes(&self) -> Cow<[u8]>;
@Kerollmops
Kerollmops / easy-memlog.sh
Created September 16, 2019 20:01
Record %CPU and RSS
#!/bin/bash
while true; do
ps -p $1 -o\%cpu,rss | awk 'NR>1 { gsub(",",".",$1); print $1","$2}'
sleep 0.2
done
@Kerollmops
Kerollmops / memlog.sh
Last active July 24, 2021 12:55
Record memory usage of a process
#!/usr/bin/env bash
# usage: memlog.sh $(pidof PROCESS_NAME) [ PATH_FOLDER ]
# on osx pidof can be replaced by pgrep
# usage: memlog.sh $(pgrep PROCESS_NAME) [ PATH_FOLDER ]
set -e
PID=$1
@Kerollmops
Kerollmops / group-by-generic-function.rs
Created January 31, 2019 22:06
Generic function type thta is in fact a function pointer (`fn` != `Fn`)
fn linear_group(&self) -> LinearGroupBy<T, fn(&T, &T) -> bool>
where T: Ord
{
LinearGroupBy::new(self, |a, b| a == b)
}
@Kerollmops
Kerollmops / all-eq.rs
Created August 6, 2018 12:07
A function to test if all values of a slice are equal (to the first element).
fn all_eq<T: Eq>(slice: &[T]) -> bool {
match slice.split_first() {
Some((first, others)) => others.iter().all(|x| x == first),
None => true,
}
}
#[test]
fn all_eq_easy_eq() {
assert!(all_eq(&[1, 1, 1, 1, 1]));
@Kerollmops
Kerollmops / split-first.rs
Created August 6, 2018 12:06
The `split_first` function for any iterator
// prefer using IntoIterator ?
fn split_first<T, I>(mut iter: I) -> Option<(T, I)>
where I: Iterator<Item=T>
{
match iter.next() {
Some(first) => Some((first, iter)),
None => None,
}
}
@Kerollmops
Kerollmops / kero_solution.rs
Created March 22, 2018 09:11
Different solutions to create a KernelBuilder
pub enum Arg {
Int(i32),
Float(f32),
String(String),
Ptr(isize),
}
pub enum KernelError {
KernelInvalid,
}

Core Coding Standard

Coding practices are a source of a lot of arguments among programmers. Coding standards, to some degree, help us to put certain questions to bed and resolve stylistic debates. No coding standard makes everyone happy. (And even their existence is sure to make some unhappy.) What follows are the standards we put together on the Core team, which have become the general coding standard for all programming teams on new code development. We’ve tried to balance the need for creating a common, recognizable and readable code base with not unduly burdening the programmer with minor code formatting concerns.

Table Of Contents

@Kerollmops
Kerollmops / corona-bench.txt
Created February 3, 2018 23:06
Corona benchmark result sorted (thanks to https://stackoverflow.com/a/9471139/1941280)
test async ... bench: 25,129,522 ns/iter (+/- 1,948,456)
test async_cpupool ... bench: 13,895,220 ns/iter (+/- 2,412,441)
test async_cpupool_cpus ... bench: 16,449,300 ns/iter (+/- 7,062,024)
test async_cpupool_many ... bench: 14,118,352 ns/iter (+/- 3,170,100)
test async_cpus ... bench: 11,057,663 ns/iter (+/- 1,546,785)
test async_many ... bench: 14,304,595 ns/iter (+/- 1,966,185)
test corona ... bench: 34,898,721 ns/iter (+/- 204,006,257)
test corona_blocking_wrapper ... bench: 35,851,174 ns/iter (+/- 76,716,240)
test corona_blocking_wrapper_cpus ... bench: 12,601,478 ns/iter (+/- 1,368,466)
test corona_blocking_wrapper_many ... bench: 20,098,071 ns/iter (+/- 84,982,750)