Skip to content

Instantly share code, notes, and snippets.

@nikhilm
nikhilm / js
Created November 13, 2012 17:57
fire event
nsresult
XHRSampleListener::FireOnResultEvent(const nsAString &response)
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
nsresult rv;
nsCOMPtr<nsIDOMEvent> event;
rv = NS_NewDOMEvent(getter_AddRefs(event), nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
@nikhilm
nikhilm / tryjsil.cs
Created April 11, 2013 21:20 — forked from TryJSIL/tryjsil.cs
Simple Unsafe Structs
using System;
using System.Runtime.InteropServices;
public static class Program {
public static unsafe void Main (string[] args) {
var bytes = new byte[8];
fixed (byte* pBytes = bytes) {
var pStruct = (MyStruct*)pBytes;
*pStruct = new MyStruct {
@nikhilm
nikhilm / index.js
Last active April 7, 2016 05:34
Iron.io Lambda support example.
var im = require('imagemagick');
var fs = require('fs');
var postProcessResource = function(resource, fn) {
var ret = null;
if (resource) {
if (fn) {
ret = fn(resource);
}
// 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.
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)
@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]
#
@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 / 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 / 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 / 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