Skip to content

Instantly share code, notes, and snippets.

@ebresafegaga
ebresafegaga / main.ml
Created October 24, 2023 18:02
Trying out Domainslib
let long_computation () =
for i = 0 to 1_000_000_000 do
()
done
(* No parallelism *)
(*
________________________________________________________
Executed in 36.09 secs fish external
usr time 36.08 secs 1.27 millis 36.08 secs
type stack = int array
type machine = { ip : int; sp : int; mutable stack : stack }
(* Machine stack *)
module type S = sig
type t
type index
type elem
@ebresafegaga
ebresafegaga / camel_to_kebab.ml
Last active March 28, 2023 16:00
Camel to Kebab
(* camel_to_kebab('CamelCaseString') == 'camel-case-string'
camel_to_kebab('CamelCaseStringWithABREV') == 'camel-case-string-with-abrev'
camel_to_kebab('CamelCaseStringWithABREVInCenter') == 'camel-case-string-with-abrev-in-center' *)
(* words = re.findall('([A-Z][a-z]+)|([A-Z]+(?=[A-Z][a-z]+))', s) *)
type state =
| Start
| InsideCamel
| InsideAbrev
let (next, _) = linearization.get_items_adjacent(parent.id);
let next = next.and_then(|item| match item.kind {
TermKind::RecordField {
ident,
record,
value: ValueState::Known(value),
..
} if value == parent.id => Some((ident, record)),
_ => None,
});
@ebresafegaga
ebresafegaga / path.rs
Last active December 23, 2022 09:57
Path
let path: String = path.chars().skip_while(|ch| !(ch.is_alphanumeric() || *ch == '-' || *ch == '_')).collect();
//
// ("Paren before ident", "(record", vec!["record"])
@ebresafegaga
ebresafegaga / trash.rs
Created December 5, 2022 21:31
Trash code
fn parse_crate<'a, I>(chs: &'a mut I) -> Option<char>
where
I: Iterator<Item = char>,
{
fn is_for_crate<'a, I>(c: char, chs: &'a mut I) -> bool
where
I: Iterator<Item = char>,
{
if c == '[' || c == ']' {
true
let mut file = std::fs::OpenOptions::new()
.write(true)
.append(false)
.create(true)
.open("/home/ebresafegaga/server.log")
.unwrap();
let data = format!("{:?}", linearization.linearization);
std::io::Write::write(&mut file, data.as_ref()).unwrap();
fn calculate_offset(c: u32, l: u32, t: &String) -> usize {
let (c, l) = (c as usize, l as usize);
// Line is 0 indexed so we don't need to skip the
// line that the cursor is currently on.
// It will be done automatically during the `take`, because
// of the 0 index.
let count = t
.split('\n')
.take(l)
.collect::<Vec<_>>()
@ebresafegaga
ebresafegaga / count.rs
Last active August 4, 2022 08:35
Counting sort
fn sort<const N: usize>(arr: [i32; N]) -> Vec<i32> {
let mut max = arr[0];
// Find the max of the array
for i in 0..arr.len() {
if arr[i] > max {
max = arr[i]
}
}
@ebresafegaga
ebresafegaga / git.sh
Last active July 27, 2022 10:52
another little script
git status | tail -n +5 | head -n -8 | awk '{print $2}' | grep -v snarkyjs | xargs git add