Skip to content

Instantly share code, notes, and snippets.

@nikhilm
nikhilm / jscrush-compress-pseudo.js
Created April 15, 2012 17:00
JSCrush 'reverse engineering'
segmentLengthBound = ... // B, originally set to s.length/2
counter = {} // o
bestSavings = 0 // M
maxRepetitions = 0 // N
bestSegment = 0 // e
longestSegmentLength = 0 // Z
segmentLength = 0 // t
while (segmentLength <= segmentLengthBound) {
start = 1;
@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 / 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},
},
/*
* Mclarens Bar: Redis based Instant Messaging
* Nikhil Marathe - 22/04/2010
* A simple example of an IM client implemented using
* Redis PUB/SUB commands so that all the communication
* is offloaded to Redis, and the node.js code only
* handles command interpretation,presentation and subscribing.
*
* Requires redis-node-client and a recent version of Redis
@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]
#