Skip to content

Instantly share code, notes, and snippets.

View NicolasT's full-sized avatar

Nicolas Trangez NicolasT

View GitHub Profile
@NicolasT
NicolasT / nonblocking.py
Last active May 27, 2024 17:03
Using the 'splice' syscall from Python, in this demonstration to transfer the output of some process to a client through a socket, using zero-copy transfers. See 'splice.py'. Usage: 'python splice.py' in one console, then e.g. 'nc localhost 9009' in another. 'nonblocking.py' is a demonstration of using 'splice' with non-blocking IO.
'''
Demonstration of using `splice` with non-blocking IO
Lots of code is similar to 'splice.py', take a look at that module for more
documentation.
'''
import os
import os.path
import errno
@NicolasT
NicolasT / punch.py
Created September 5, 2011 13:09
Using FALLOC_FL_PUNCH_HOLE from Python
import ctypes
import ctypes.util
c_off_t = ctypes.c_int64
def make_fallocate():
libc_name = ctypes.util.find_library('c')
libc = ctypes.CDLL(libc_name)
_fallocate = libc.fallocate
@NicolasT
NicolasT / star.ml
Last active February 7, 2024 00:09
module Functor = struct
module type S = sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
end
module type API = sig
include S
@NicolasT
NicolasT / .gitignore
Last active December 16, 2023 14:02
Testing Python scripts using pytest
__pycache__/
.pytest_cache/
@NicolasT
NicolasT / .gitignore
Last active March 23, 2023 15:05
Non-failing test with DejaFu
dist-newstyle/
@NicolasT
NicolasT / paxos.rst.lhs
Created December 7, 2012 22:29
Basic Paxos in Haskell
> module Paxos.Basic where
> import Data.List (maximumBy)
> import Data.Maybe (catMaybes)
Phase 1a: Prepare
=================
A Proposer (the leader) creates a proposal identified with a number N. This
number must be greater than any previous proposal number used by this Proposer.
Then, it sends a Prepare message containing this proposal to a Quorum o
@NicolasT
NicolasT / Raadsel.hs
Created January 26, 2023 20:58
Raadsel oplossen met een SMT solver via SBV
module Main (main) where
import Data.SBV
raadsel :: Symbolic SBool
raadsel = do
vars@[s, e, n, d, m, o, r, y] <- sIntegers ["s", "e", "n", "d", "m", "o", "r", "y"]
-- Helper, maakt bvb. (100 * a + 10 * b + c) uit [a, b, c]
let woord w = sum (zipWith (*) (reverse w) (iterate (* 10) 1))
# Some code to retrieve CPUID information in pure Python
#
# Copyright (C) 2009 Nicolas Trangez <eikke eikke com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, version 2.1
# of the License.
#
# This library is distributed in the hope that it will be useful,
# <License type="Sun Cloud BSD" version="2.2">
#
# Copyright (c) 2005-2009, Sun Microsystems, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
@NicolasT
NicolasT / binsec.ml
Created June 21, 2011 18:45
Monadic binary (de)serialization API for OCaml
type 'a writer = Buffer.t -> 'a -> unit;;
type 'a reader = string -> int -> ('a * int);;
let ($) a b = a b;;
let id x = x;;
let lift_llio_writer (l: Buffer.t -> 'b -> unit): ('a -> 'b) -> 'a writer =
fun f -> fun b a ->
let v = f a in
l b v;;