Skip to content

Instantly share code, notes, and snippets.

View jimblandy's full-sized avatar

Jim Blandy jimblandy

View GitHub Profile
@jimblandy
jimblandy / intersection.rs
Last active January 27, 2019 19:57
An extremely generic `Range`... intersection operation.
#![cfg_attr(test, feature(range_is_empty))]
use std::cmp::{min, max};
use std::ops::{Range, RangeInclusive, RangeFrom, RangeTo, RangeToInclusive, RangeFull};
pub trait Intersection<Right> {
type Output;
fn intersection(self, right: Right) -> Self::Output;
}
@jimblandy
jimblandy / generator-gc.md
Created October 27, 2018 22:40
Notes on the SpiderMonkey Debugger API, its hooks, generators, and garbage collection

One principle of Debugger's design is that its behavior should not be affected by the garbage collector. Like the rest of JavaScript, the programmer should be able to assume that objects have infinite lifetimes, and that the garbage collector recycles objects only when doing so would have no visible effect on the execution of the program. (Methods like findScripts and findObjects that scan the heap are exceptions; their behavior is sensitive to the garbage collector's activity—and cause plenty of trouble because of it.)

There is also a complementary principle, which is that Debugger should not impede the garbage collector's work more than necessary. For example, if the

@jimblandy
jimblandy / shapes.css
Created September 27, 2018 17:49
Files for reproducing Firefox shape editor bug
body {
font: 1.2em/1.3 Helvetica, arial, sans-serif;
}
.content {
max-width: 700px;
margin: 20px auto;
}
.content::before {
@jimblandy
jimblandy / lambda.lalrpop
Last active September 24, 2018 06:08
Working LALRPOP grammar for the lambda calculus
use ::Expr;
use ::app_chain;
grammar;
pub Expr = {
<Fun>,
<App>,
<Prim>,
};
use std::cmp::min;
use std::iter::FromIterator;
#[derive(Debug)]
enum Edit {
Delete,
Insert(char),
Replace(char),
Keep,
}
@jimblandy
jimblandy / moz-pause-on-crash.patch
Created June 27, 2018 20:13
Patch to make Firefox pause and wait to be debugged when it crashes
MOZ_PAUSE_ON_CRASH(6W ago) changes to: Bug 1421062: Enable production nightly balrog update on comm-c...
diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3426,6 +3426,13 @@
mAppData->flags |= NS_XRE_ENABLE_CRASH_REPORTER;
}
+ if (EnvHasValue("MOZ_PAUSE_ON_CRASH")) {
@jimblandy
jimblandy / unfold.rs
Created June 13, 2018 04:47
A Rust `unfold` function, to build an iterator by repeatedly applying a closure.
fn main() {
//let i = (0i32..).scan((0,1), |s,_| { *s = (s.1, s.0 + s.1); Some(s.0) });
let i = unfold((0, 1), |(a, b)| Some(((b, a+b), b)));
let v: Vec<i32> = i.take(20).collect();
println!("{:?}", v);
}
struct Unfolder<F, T>(F, Option<T>);
@jimblandy
jimblandy / main.rs
Last active May 28, 2018 19:44 — forked from c0gent/main.rs
Glium - instancing over a vertex buffer slice
//! An example demonstrating that glium has a problem using instancing when
//! the vertex buffer is a slice with a non-zero starting index.
//!
#[macro_use] extern crate glium;
use glium::{glutin, Surface};
// Vertex Shader:
static VERTEX_SHADER_SRC: &'static str = r#"
#version 140
@jimblandy
jimblandy / enable-api.md
Last active April 12, 2018 05:27
API styles for enabling and disabling things

Minutiae: API styles for enabling and disabling things

So there are two API styles for enabling and disabling something: you can have a boolean that you turn on and off (call this "flag style"); and you can have calls that increment and decrement a counter, and the thing is enabled depending on whether the count is zero (call this "semaphore style").

Semaphore style is essential in some cases. If there are many different influences who all have to come to consensus in order to enter a certain state, the counter is sort of a reference count: the number of people holding us in the lack-of-consensus state. In situations like this, flag style is a pain in the neck: you'd have to implement the counter someplace else just to decide when to flip the bit.

But if you need the thing to be enabled/disabled depending on a predicate on some state, and you're calling the API whenever the state changes, then the flag API is much better: evaluate the predicate, and set the flag. If a bug causes you to miss a transitio

@jimblandy
jimblandy / dumpFunctionSkeleton.patch
Created February 14, 2018 16:47
Patch implementing dumpFunctionSkeleton testing JS function in SpiderMonkey
diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -4948,24 +4948,184 @@ IsConstructor(JSContext* cx, unsigned ar
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() < 1)
args.rval().setBoolean(false);
else
args.rval().setBoolean(IsConstructor(args[0]));
return true;