Skip to content

Instantly share code, notes, and snippets.

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

François Bernier fbernier

👷‍♂️
View GitHub Profile
@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
@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 / 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 / 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 / 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 / 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)
(ns phrase
(:require [clojure.string :as str]))
(defn- strip-punctuation [phrase]
(str/replace phrase #"[^\w\s]" "")
)
(defn word-count [phrase]
(frequencies (str/split(str/lower-case (strip-punctuation phrase)) #"\s+"))
)
@fbernier
fbernier / gist:5319833
Last active December 15, 2015 20:40
Single quote vs double quote in ruby
require "benchmark/ips"
Benchmark.ips do |x|
x.report("double quote assignment:") {a = "yo man"}
x.report("double quote +:") {|i| a = "yo man" + i.to_s}
x.report("double quote <<:") {|i| a = "yo man" << i.to_s}
x.report("double quote interpolation:") {|i| a = "yo man #{i}"}
x.report("single quote assignment:") {a = 'yo man'}
x.report("single quote +:") {|i| a = 'yo man' + i.to_s}
@fbernier
fbernier / meta.rb
Last active December 12, 2015 04:38
# Any difference between:
[:db_create, :db_drop, :db_list].each do |cmd|
#THIS:
define_method(cmd) do |*args|
NoBrainer.run { RethinkDB::RQL.send(cmd, *args) }
end
# OR THIS
let(:date) do
Time.now
end
it "converts the elements properly" do
p date.zone
mongoized.first.should eq(date)
p date.zone
end