Skip to content

Instantly share code, notes, and snippets.

View BruJu's full-sized avatar
🐓

Julian Bruyat BruJu

🐓
View GitHub Profile
@BruJu
BruJu / .block
Last active June 13, 2020 15:44
barchart_letters
license: mit
@BruJu
BruJu / FunctionAsTemplateParameter.cpp
Last active February 22, 2020 21:39
Misc C++ Experiments
// "How to pass a function in a template parameter ?"
// (I wanted to pass a lambda but it is not possible)
// 2019-12-27
#include <iostream>
#include <string>
#include <vector>
#include <array>
@BruJu
BruJu / relaxedbinpacking.cpp
Created January 18, 2020 21:50
Relaxed Bin Packing
// I was bored so I programmed the binpacking relaxed problem
#include <iostream>
#include <array>
#include <algorithm>
#include <functional>
struct Item {
unsigned int number;
unsigned int utility;
double weight;
@BruJu
BruJu / filter.js
Created February 21, 2020 14:53
Random filter experiment in js
// Today I discovered that we can write horrible code in Javascript thanks to the thisArg argument of Array.reduce.filter
function myFilter(e) {
if (e % 2) {
this.val += e;
}
return e % 3 == 0;
}
var arr = [1,2,3,4,5,6,7,8,9,10];
@BruJu
BruJu / synchronize_sophia.sh
Created February 25, 2020 12:33
My bash script to synchronize my clone of the Sophia_rs repository (and use the latest version of Sophia in my project)
#!/bin/bash
cd sophia_rs
git checkout master
git fetch pchampin
git rebase pchampin/master
git push
cd ../PRIWA/wasm_example/
rm Cargo.lock
./run_server.sh reload
@BruJu
BruJu / main.rs
Created March 10, 2020 10:32
Volatile data in Rust
/// Code example of how to have mutable data in an object passed by ref
/// The use case of this snippet is to cache some computed data
use core::cell::RefCell;
struct Cat {
age: RefCell<Option<i32>>
}
@BruJu
BruJu / Observations.md
Last active June 11, 2020 13:34
Exporting numbers from Rust to Wasm

Initial problem : I tried to export to wasm different complex structures. Time benchmarks were strange and in linear time for every structure.

So I tried to export vectors of numbers

Exporting a vector of 6

extern crate wasm_bindgen;
extern crate js_sys;
use wasm_bindgen::prelude::*;
use std::collections::BTreeSet;
#[wasm_bindgen]
pub struct IntVector {
values: Vec<i32>
template <bool try_lock_return>
class DebugMutex {
#ifdef DEBUG
private: std::mutex _mutex;
public:
void lock() { _mutex.lock(); }
void unlock() { _mutex.unlock(); }
bool try_lock() { return _mutex.try_lock(); }
#else
public:
// Some functions I coded to help a friend that was
// enrolled in an Engineering School
// 2019-05-19
#include <stdio.h>
#include <stdlib.h>
char ** reverse(int argc, char * argv[]) {
char ** new_argv = malloc(sizeof(char *) * argc);