Skip to content

Instantly share code, notes, and snippets.

View fbernier's full-sized avatar
👷‍♂️

François Bernier fbernier

👷‍♂️
View GitHub Profile
@fbernier
fbernier / gist:7237370
Last active December 27, 2015 00:19
a ranged hash implementation in ruby
class RangedHash
def initialize(hash={})
@ranged_hash = hash
end
def []=(key, value)
@ranged_hash[key] = value
end
def [](key)
@fbernier
fbernier / which.rb
Last active August 29, 2015 13:56
Which do you prefer?
# Obviously the second solution is faster or a large collection, but some said the first solution is more readable.
# Which would you use?
result = []
collection.each do |c|
result << some_method(c)
end
result.reject!(&:nil?)
@fbernier
fbernier / lazy.rb
Last active August 29, 2015 13:56
Enumerator#lazy benchmarking
# Enumerator#lazy is very slow and should only be used when iterating over large/infinite collections
# where you know you are going to get your results quite early in the iteration.
# This benchmark is purposely made to advantage the lazy version, without much success.
require 'benchmark/ips'
class Enumerator::Lazy
def filter_map
Lazy.new(self) do |yielder, *values|
@fbernier
fbernier / fitz.rs
Last active August 29, 2015 14:12
fitz.rs
/* automatically generated by rust-bindgen */
pub type size_t = ::libc::c_ulong;
pub type __u_char = ::libc::c_uchar;
pub type __u_short = ::libc::c_ushort;
pub type __u_int = ::libc::c_uint;
pub type __u_long = ::libc::c_ulong;
pub type __int8_t = ::libc::c_char;
pub type __uint8_t = ::libc::c_uchar;
pub type __int16_t = ::libc::c_short;
@fbernier
fbernier / wat.rs
Last active September 6, 2018 01:23
use std::process::{Command};
fn main() {
let output = Command::new("curl").arg("-s").arg("http://ovh.net/files/100Mio.dat").output();
println!("{:?}", output.unwrap().stdout.len());
}
~/stuff ❯❯❯ time ./dwl
104857600
./dwl 16.22s user 1.80s system 23% cpu 1:15.24 total
@fbernier
fbernier / affinitize.py
Created December 3, 2020 19:34 — forked from SaveTheRbtz/affinitize.py
affinitization scripts, originally written by @behebot
#!/usr/bin/env python
# mypy: allow-untyped-defs
"""
This script is used for applying affinity settings for various hardware devices.
Script originally based on Intel's [set_irq_affinity.sh](https://gist.github.com/SaveTheRbtz/8875474).
Over the years it was updated with heuristics based on the shape of Dropbox infrastructure.
Currently, this script can manage IRQ affinities, RPS, XPS, and RXQS. For the description of