Skip to content

Instantly share code, notes, and snippets.

@rcls
rcls / ltc6811_pec.c
Last active May 6, 2022 07:18
LTC6811pec
// This is a 15 bit CRC used by the LTC6811.
//
// The CRC modulus polynomial is x¹⁵ + x¹⁴ + x¹⁰ + x⁸ + x⁷ + x⁴ + x³ + 1.
//
// I.e., 0xc599 or 0x4599 depending on whether you include the leading
// coefficient.
//
// Natural bit order is used (high bit of first byte has highest order; for SPI,
// first bit on the wire has highest order), both for the data and PEC.
//
# .bashrc
# Source global definitions
#if [ -f /etc/bashrc ]; then
# . /etc/bashrc
#fi
# export SYSTEMD_PAGER=
# User specific aliases and functions
(global-set-key "\eg" 'goto-line)
(global-set-key "\C-x\\" 'save-buffers-kill-terminal)
(global-unset-key "\C-x\C-c")
(add-to-list 'load-path "/home/mirror/rust-mode/")
(autoload 'rust-mode "rust-mode" nil t)
;;(remove-hook 'write-file-functions 'makefile-warn-suspicious-lines)
(rassq-delete-all #'doc-view-mode auto-mode-alist)
#!/usr/bin/python3
import rpm
#from rpmUtils import miscutils
ts = rpm.TransactionSet('/')
def U(b):
return str(b)
@rcls
rcls / primes.rs
Created April 11, 2021 17:58
Layout prime (powers) into fixed-size blocks.
// use std::fmt;
// use std::iter::Iterator;
use std::collections::BinaryHeap;
use std::cmp::Ordering;
const BITS : u32 = 50;
const MAX_PRIME : u32 = 1 << 25;
const MAX_NUM : u64 = 1 << 50;
@rcls
rcls / jessie-build.ini
Last active March 29, 2020 01:14
Meson build for debian obsolete.
########################################################################
# Using up-to-date meson to build for obsolete Debian as a cross-build.
########################################################################
#
# This got me building C & C++ code for Debian Jessie using current
# meson & ninja on Fedora 31.
#
# 1. Install a Debian Jessie (or whatever) system image into a
# subdirectory using debootstrap e.g.,
# sudo debootstrap jessie /opt/debian-8
@rcls
rcls / clock-gran.c
Created April 1, 2015 03:04
Check the actual granularity of a clock, specifically CLOCK_MONOTONIC_COARSE.
#include <time.h>
#include <stdio.h>
#define CLOCK CLOCK_MONOTONIC_COARSE
int main() {
struct timespec t;
clock_getres(CLOCK, &t);
fprintf(stderr, "Res: %lu %06lu\n", t.tv_sec, t.tv_nsec);
@rcls
rcls / atomic_v_memory.c
Last active August 29, 2015 14:11
Looking at how x86 atomic increment timings change depend on surrounding memory usage.
// On my Haswell 2.9GHz plus boost.
// With the atomic increment, the 2**29 iterations take just under 30 seconds.
// Without, about 11 seconds.
//
// I.e., the overhead for 0.5e9 atomic increments is approx 15 seconds, or
// 30nanosecs each.
//
// If we take the movntps operations out, the 2**29 atomic increments take
// approx 2.6 seconds, or 5ns each.
// Program to compare pthread locking v. x86 weakly ordered stores.
//
// One thread does writes protected by a lock, the main thread does
// reads protected by the lock and checks that it sees consistent
// values.
// Invoke with the command line parameter "normal" to use normal
// memory writes, or with the parameter "weak" to use SSE2
// weakly-ordered memory writes.