Skip to content

Instantly share code, notes, and snippets.

@cdleary
cdleary / mp_demo.py
Last active February 16, 2021 02:50
Simple demo of processes with queues to drive control.
import multiprocessing as mp
def do_run(i: int, q: mp.Queue):
while True:
item = q.get()
if item is None: # Sentinel.
return
print(i, item)
@cdleary
cdleary / float_helpers.py
Last active June 9, 2020 05:26
Some simple Python float/int helpers
# Apache2 Licensed: https://www.apache.org/licenses/LICENSE-2.0
import struct
float2int = lambda f: struct.unpack('i', struct.pack('f', f))[0]
float2hex = lambda f: hex(float2int(f))
MASK_23B = (1 << 23) - 1
assert float2hex(1.0) == '0x3f800000'
@cdleary
cdleary / changeplot.py
Last active August 5, 2017 06:13
Hacked up script for matplotting change in TF compiler dir.
# git log --format='%ad %H %s' --no-merges --date=short tensorflow/compiler/ | python2.7 ~/changeplot.py
import fileinput
import matplotlib.pyplot as plt
from datetime import date, timedelta
START_DATE = date(2017, 1, 1)
dates = [(START_DATE, START_DATE + timedelta(days=7))]
struct Cake {
static Cake Fail;
bool burned();
};
Cake Cake::Fail;
struct Ingredients { bool spoiled(); };
struct BatterAndWhatnot {};
@cdleary
cdleary / tmux-show-args.diff
Created June 10, 2013 07:47
Add a "show args" command to tmux 1.8.
diff --git a/Makefile.in b/Makefile.in
index 98c0e13..ed537a4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -151,6 +151,7 @@ dist_tmux_OBJECTS = arguments.$(OBJEXT) attributes.$(OBJEXT) \
cmd-set-buffer.$(OBJEXT) cmd-set-environment.$(OBJEXT) \
cmd-set-option.$(OBJEXT) cmd-show-environment.$(OBJEXT) \
cmd-show-messages.$(OBJEXT) cmd-show-options.$(OBJEXT) \
+ cmd-show-args.$(OBJEXT) \
cmd-source-file.$(OBJEXT) cmd-split-window.$(OBJEXT) \
@cdleary
cdleary / test.rs
Created April 9, 2013 02:16
Example of Rust making me happy.
use core::task::task;
use core::comm::{stream, Port};
enum MyDataType {
CoolVariant(int),
CoolerVariant(~str)
}
fn spewer(port: Port<MyDataType>) {
loop {
@cdleary
cdleary / longdiv.py
Created October 25, 2012 07:00
Hacky GF(2) polynomial long division impl
"""Hacky polynomial long division implementation for testing fun.
Polynomials in GF(2) have the simple arithmetic properties:
all polynomial coefficients are 1 or 0
addition is subtraction is XOR on the polynomial coefficients
polynomial powers add under multiplication
"""
import re
let text_token = scan "1234" 0 in
match text_token with
| {pos_start=0; pos_end=4; token=Integer 1234} -> print_endline "Pass"
| _ -> print_endline "Fail"
@cdleary
cdleary / rebind.js
Created August 11, 2011 06:18
Rebinding proposal for JS
Function.prototype.bind = function(thisVal) {
var func = this.__orig__ || this;
var bound = function() {
return func.apply(thisVal, arguments);
};
bound.__orig__ = func;
return bound;
};
@cdleary
cdleary / rebinding.py
Created August 11, 2011 05:01
Rebinding in Python3
import types
from collections import namedtuple
class Oven:
def __init__(self):
self.pie = 'apple'
def easy_bake(self):