Skip to content

Instantly share code, notes, and snippets.

@nikhilm
nikhilm / apprenticeship.md
Created August 24, 2012 10:46
Paraphrased from "Why nerds are unpopular" by Paul Graham - http://www.paulgraham.com/nerds.html

I'm suspicious of this theory that thirteen-year-old kids are intrinsically messed up. If it's physiological, it should be universal. Are Mongol nomads all nihilists at thirteen? I've read a lot of history, and I have not seen a single reference to this supposedly universal fact before the twentieth century. Teenage apprentices in the Renaissance seem to have been cheerful and eager. They got in fights and played tricks on one another of course (Michelangelo had his nose broken by a bully), but they weren't crazy.

As far as I can tell, the concept of the hormone-crazed teenager is coeval with suburbia. I don't think this is a coincidence. I think teenagers are driven crazy by the life they're made to lead. Teenage apprentices in the Renaissance were working dogs. Teenagers now are neurotic lapdogs. Their craziness is the craziness of the idle everywhere.

When I was in school, suicide was a constant topic among the smarter kids. No one I knew did it, but several planned to, and some may have tried. Mostly

@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.html
Created May 19, 2015 20:02
fetch crash
// Does not handle fetch event.
@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"}