Skip to content

Instantly share code, notes, and snippets.

View jimblandy's full-sized avatar

Jim Blandy jimblandy

View GitHub Profile
@jimblandy
jimblandy / devtools-mochitest-toy.patch
Created January 11, 2018 20:20
Sample patch for a really lightweight devtools mochitest
diff --git a/devtools/server/tests/mochitest/chrome.ini b/devtools/server/tests/mochitest/chrome.ini
--- a/devtools/server/tests/mochitest/chrome.ini
+++ b/devtools/server/tests/mochitest/chrome.ini
@@ -18,16 +18,17 @@ support-files =
inspector-helpers.js
inspector-search-data.html
inspector-styles-data.css
inspector-styles-data.html
inspector-traversal-data.html
large-image.jpg
@jimblandy
jimblandy / math.el
Last active January 3, 2018 17:54
Simple differentiation in elisp
(require 'ert)
(defun derivative (v e)
(pcase e
((pred symbolp) (if (eq e v) 1 e))
((pred numberp) 0)
(`(+) 0)
(`(+ ,x . ,ys) (expr+ (derivative v x)
(derivative v (apply #'expr+ ys))))
(`(*) 0)
@jimblandy
jimblandy / foo.html
Last active December 7, 2017 18:50
Top-level `let` versus `var`
<body>
<script src="foo1.js"></script>
<script src="foo2.js"></script>
<script>
console.log('var1: ', var1);
console.log('var2: ', var2);
console.log('window.var1: ', window.var1);
console.log('window.var2: ', window.var2);
</script>
@jimblandy
jimblandy / playground.rs
Created November 27, 2017 00:54 — forked from anonymous/playground.rs
Rust code shared from the playground
#![allow(unused_variables)]
/// Given an array of `true` or `false` values (the type `bool`),
/// return a new array whose `i`'th element is true iff `array[i]`
/// and `array[i+1]` are different.
///
/// Rust numbers array elements starting with zero. Since `array` has 80
/// elements, its first element is `array[0]`, and its last element is
/// `array[79]`. The function's return value is similar.
///
@jimblandy
jimblandy / playground.rs
Created November 27, 2017 00:29 — forked from anonymous/playground.rs
Rust code shared from the playground
#![allow(unused_variables)]
fn show_line(array: [bool; 80]) {
for i in 0..80 {
if array[i] {
print!("+");
} else {
print!(" ");
}
@jimblandy
jimblandy / foo.diff
Last active November 1, 2017 20:48 — forked from jasonLaster/foo.diff
modified src/utils/scopes.js
@@ -70,13 +70,14 @@ function getSourceBindingVariables(
return bound.concat(unused);
}
-export function getSpecialVariables(pauseInfo: Pause, path: string) {
- const thrown = get(pauseInfo, "why.frameFinished.throw", undefined);
-
- const returned = get(pauseInfo, "why.frameFinished.return", undefined);
+export function getFramePopVariables(pauseInfo: Pause, path: string) {
@jimblandy
jimblandy / Attributes.h.patch
Last active October 30, 2017 17:28
Doc fix for `MOZ_NON_PARAM`
diff --git a/mfbt/Attributes.h b/mfbt/Attributes.h
--- a/mfbt/Attributes.h
+++ b/mfbt/Attributes.h
@@ -571,17 +571,22 @@
* or via functions called from the constructor body.
* MOZ_IS_CLASS_INIT: Applies to class method declarations. Occasionally the
* constructor doesn't initialize all of the member variables and another function
* is used to initialize the rest. This marker is used to make the static analysis
* tool aware that the marked function is part of the initialization process
* and to include the marked function in the scan mechanism that determines witch
@jimblandy
jimblandy / cast.patch
Last active October 30, 2017 16:59
Bug 1277377: Don't permit `.append((float*) ptr)` to a `Vector<int*>` 😟 (patch from Luke)
diff --git a/mfbt/Vector.h b/mfbt/Vector.h
--- a/mfbt/Vector.h
+++ b/mfbt/Vector.h
@@ -158,17 +158,22 @@ struct VectorImpl
*/
template<typename T, size_t N, class AP>
struct VectorImpl<T, N, AP, true>
{
template<typename... Args>
MOZ_NONNULL(1)
@jimblandy
jimblandy / SICM
Created September 22, 2017 03:39
SICM 2nd ed. 1.2
/// https://en.wikipedia.org/wiki/Euler_angles
struct EulerAngle3<R> { α: R, β: R, γ: R }
struct Point<R> { x: R, y: R, z: R }
struct Pin<R> {
/// The location of the pin's center of gravity.
center: Point<R>,
/// The angle with the positive Z axis of some distinguished point
/// on the pin that is off the pin's axis of symmetry.
orientation: EulerAngle3<R>
@jimblandy
jimblandy / with-this.js
Created September 6, 2017 22:01
Demonstration of `this` value for functions found on `with` operands
let obj = { f: function() { console.log(this === obj); } };
with (obj) f();
// output: true