Skip to content

Instantly share code, notes, and snippets.


Pierre Jambet pjambet

View GitHub Profile
View stateful.go
package main
import (
// "sync/atomic"
// "strconv"
View bench-large.rb
require 'benchmark/ips'
require 'set'
def bench(size)
Benchmark.ips do |x|
set =
array = []
hash = {}
size.times do |i|
View bench-large.js
var Benchmark = require('benchmark');
function getRandomInt(max) {
return Math.floor(Math.random() * max);
var set = new Set();
var array = [];
View overflow.c
#include <stdio.h>
#include <stdint.h>
int main() {
long long l = -2;
printf("%lld\n", l);
printf("%llu\n", (unsigned long long) l);
printf("%llu\n", (uint64_t) l);
return 0;
pjambet / mermaid
Created Dec 8, 2020
A sequence diagram
View mermaid
participant Frontend
participant Backend
Frontend->>+Frontend: Persist intent record
Frontend->>+Backend: Create resource request
Backend-->>-Frontend: Newly created resource
Note right of Backend: Resource must include a unique identifier
Frontend->>+Frontend: Update intent record with the unique identifier
pjambet /
Created Nov 22, 2020
select/pselect in Rust
extern crate libc;
use std::{io,mem,ptr,time};
use std::os::unix::io::RawFd;
use std::net::TcpStream;
use std::os::unix::io::AsRawFd;
// use std::io::Read;
pub struct FdSet(libc::fd_set);
pjambet /
Last active Nov 17, 2020
String commands, without bit stuff
  • DECR
  • GET
  • INCR
  • MGET
pjambet / popcount.c
Created Nov 12, 2020
Playing with the C code from Redis in bitops.c
View popcount.c
#include <stdio.h>
#include <inttypes.h>
size_t redisPopcount(void *s, long count) {
size_t bits = 0;
unsigned char *p = s;
uint32_t *p4;
static const unsigned char bitsinbyte[256] = {0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8};
/* Count initial bytes not aligned to 32 bit. */
pjambet / sorted_array.rb
Created Nov 11, 2020
A contrived sorted array
View sorted_array.rb
require 'forwardable'
module BYORedis
class SortedArray
extend Forwardable
def_delegators :@underlying, :[], :delete_if, :size, :each, :delete_at, :shift,
:bsearch_index, :map, :each_with_index, :pop
def initialize(*fields)
View skiplist.rb
module BYORedis
class SkipList
MAX_LEVEL = 32 # 32 is what Redis uses
P = 0.25
Node =, :score, :backward, :levels, keyword_init: true)
Level =, :span, keyword_init: true)
attr_reader :length