Skip to content

Instantly share code, notes, and snippets.

View raindev's full-sized avatar

Andrew Barchuk raindev

View GitHub Profile
@raindev
raindev / sleep.py
Last active May 9, 2025 15:23
Deterministic Simulation Testing with Python async/await
import asyncio
async def sweet_sleep(sleep):
print('1:starting sweet sleep')
await sleep(1)
print('5:woke up from sweet sleep')
return 'happy'
# create a new event loop for the current thread
loop = asyncio.new_event_loop()
@raindev
raindev / slope_vs_starting.md
Created April 22, 2025 08:23 — forked from gtallen1187/slope_vs_starting.md
A little bit of slope makes up for a lot of y-intercept

"A little bit of slope makes up for a lot of y-intercept"

01/13/2012. From a lecture by Professor John Ousterhout at Stanford, class CS140

Here's today's thought for the weekend. A little bit of slope makes up for a lot of Y-intercept.

[Laughter]

@raindev
raindev / hyperfine.out
Created November 3, 2024 17:14
Static memory alignment benchmark on M3
# i +=17
$ hyperfine -w2 ./main # aligned(1)
Benchmark 1: ./main
Time (mean ± σ): 52.4 ms ± 3.3 ms [User: 16.9 ms, System: 31.7 ms]
Range (min … max): 48.5 ms … 65.0 ms 47 runs
$ hyperfine -w2 ./main # aligned(4), ~+10%
Benchmark 1: ./main
Time (mean ± σ): 57.6 ms ± 3.0 ms [User: 18.8 ms, System: 34.5 ms]
@raindev
raindev / main.c
Last active November 3, 2024 17:07
Static memory alignment benchmark on Pi 4 (Arm 64)
#include <stdint.h>
#include <stdio.h>
#include <stdalign.h>
#include <assert.h>
#include <sys/mman.h>
//#include <x86intrin.h>
#define COUNT 4096
struct __attribute__((packed)) {
@raindev
raindev / cpuid.out
Created November 2, 2024 12:45
Netcup VM cpuid
$ cpuid
CPU 0:
vendor_id = "GenuineIntel"
version information (1/eax):
processor type = primary processor (0)
family = 0xf (15)
model = 0xb (11)
stepping id = 0x1 (1)
extended family = 0x0 (0)
extended model = 0x6 (6)
@raindev
raindev / aligned-bench.zig
Last active October 31, 2024 20:12
Struct alignment in Zig
const std = @import("std");
const math = std.math;
const AlignedStruct = struct {
a: u16,
b: u16,
c: u8,
};
pub fn main() !void {
@raindev
raindev / getthread.js
Last active February 18, 2021 16:26
A JS bookmarklet to get URLs of Google Chat threads
javascript:(function() {
Array.from(document.getElementsByTagName('c-wiz'))
.map(tag => ({
threadId: tag.getAttribute('data-topic-id'),
firstMessage: tag.children[0].getAttribute('aria-label')
}))
.filter(thread => thread.threadId != null && thread.firstMessage != null)
.forEach(thread => console.log(window.location.href + '/' + thread.threadId
+ " : " + thread.firstMessage))
}())
@raindev
raindev / main.rs
Created May 30, 2018 07:00
Rust generic constraints
trait Wrap {
fn pass<F>(&self, consumer: F) where F: Fn(&Self) {
consumer(self)
}
}
struct Stringy(String);
impl Wrap for Stringy {
}
@raindev
raindev / checkout-retry.sh
Created May 26, 2017 08:26
Buildkite checkout hook with retry (to mitigate "reference is not a tree" Git error)
#!/bin/bash
set -ex
if [ -d .git/ ]; then
git remote set-url origin "$BUILDKITE_REPO"
else
git clone "$BUILDKITE_REPO" .
fi
git clean -fdqx
@raindev
raindev / ClintBot.java
Created December 5, 2016 08:52
Tinkoween Robocode competition
package clinteastwood;
import java.awt.Color;
import java.util.Random;
import robocode.AdvancedRobot;
import robocode.ScannedRobotEvent;
public class ClintBot extends AdvancedRobot {
private final Random random = new Random();