Skip to content

Instantly share code, notes, and snippets.

@nikhilm
nikhilm / main.rkt
Created August 7, 2023 02:17
experimenting with continuations in racket
#lang racket/base
(define kont #f)
(define my-prompt (make-continuation-prompt-tag))
(begin
(call-with-continuation-prompt
(λ ()
(printf "Before everything~n")
(printf "The call current/composable returned ~v~n"
(call/cc
{
inputStream: {
name: "Live",
type: "LiveStream",
constraints: {
width: {min:640},
height: {min:480},
facingMode: "environment",
aspectRatio: {min:1,max:2},
},
@nikhilm
nikhilm / confine.sh
Created October 27, 2022 15:58
Run a process in a cgroupv1 to limit CPU and memory usage. Useful for Ubuntu Bionic
#!/bin/bash
# All credit for figuring out these incantations goes to https://utcc.utoronto.ca/~cks/space/blog/linux/CgroupsForMemoryLimiting
#
# Script to run a command in a v1 cgroup limiting CPU and memory.
# Use as `./confine.sh command <other args>`.
# This is tested on Ubuntu Bionic.
# You will need to install the `cgroup-tools` package from `apt` first.
# Remember to tweak the limits based on your machine.
# `sudo` is required to create the cgroup, but the build itself is run as a normal user.
@nikhilm
nikhilm / code.py
Created October 24, 2021 22:13
Adafruit Bluefruit BLE bluetooth proximity bike light
import time
import adafruit_ble
from adafruit_ble import BLERadio
from adafruit_ble.advertising import Advertisement
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.standard.device_info import DeviceInfoService
# from adafruit_ble.services.standard.hid import HIDService
from adafruit_circuitplayground import cp
@nikhilm
nikhilm / Cargo.toml
Created September 4, 2019 19:50
rustc staticlib bug
[package]
edition = "2018"
name = "hello_world"
version = "0.1.0"
[lib]
crate-type = ["staticlib"]
name = "hello_world"
[dependencies]
@nikhilm
nikhilm / Cargo.toml
Created July 5, 2019 22:38
test case for https://github.com/softprops/atty/issues/34 - after building main.rs as a binary crate called testatty, run notty.py
[package]
name = "testatty"
version = "0.1.0"
authors = ["vagrant"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
atty = { path= "../atty"}
@nikhilm
nikhilm / post.md
Last active February 15, 2019 16:14
Retrieving function arguments while unwinding the stack

When a debugger, profiler or crash reporter is unwinding the call stack, can it reliably retrieve the function arguments of every function in the stack?

I originally intended for this to be a later part of the [Sampling Profilers]({{< ref "/post/2018/sampling-profiler-internals-introduction" >}}) series, but a recent discussion with Ben Frederickson, and his [subsequent py-spy implementation][] helped crystallize my thoughts and I figured I'd write it down separately.

@nikhilm
nikhilm / opencloseunlinksnoop
Created August 4, 2017 01:58
opencloseunlinksnoop - modified from opensnoop on OSX to also track unlink() and close()
#!/bin/sh
# #!/usr/bin/sh
#
# opensnoop - snoop file opens as they occur.
# Written using DTrace (Solaris 10 3/05).
#
# 12-Jan-2006, ver 1.60
#
# USAGE: opensnoop [-a|-A|-ceghstvxZ] [-f pathname] [-n name] [-p PID]
#
2016/11/12 00:29:20 Pinged successfully
&{d4d32563d909d603a6b1d604d6902b942c922e10d838ca5683ca48f4f5c23234 [treeder/hello:latest] 94f30c9c34c2234448f1f8abf62b256fdbde30542b526fa2ee9cdba3ecba28b5 2016-10-06 00:00:00.264 +0000 UTC {4c573a7cf4a3 0 0 0 0 0 [] map[] [PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin] [/bin/sh -c #(nop) ENTRYPOINT ["sh" "hello.sh"]] <nil> [] sha256:a52e7dd7e1b87c43a90db766ebe79563a38cff39a0d14ccfdad0069e741d612e map[] /app [sh hello.sh] [] [] [] map[] false false false false false false false false } 1.9.0 0xc420348000 amd64 0 0 [] <nil>} <nil>
pull <nil>
Create <nil> API error (500): (InternalError) Internal error (0f9925f0-a86f-11e6-a25b-37d5ab1798cf)
// This is a reduced test case for https://github.com/go-mgo/mgo/issues/254
//
// What it does is to overload DialServer() and return a custom net.Conn.
// Some of these custom connections timeout _once_ after the first 1000 bytes are read.
// It seems like DialServer() is called more times than the PoolLimit, which is
// set to 5, and not all these sockets are used, so for convenience, we pick
// every third connection to automatically time out once.
// It is still possible for this test to be slightly flaky, you may have to run it more than once.
//
// Remember to edit the Dial URL and the database name in insert to something valid.