Skip to content

Instantly share code, notes, and snippets.

View jimblandy's full-sized avatar

Jim Blandy jimblandy

View GitHub Profile
@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
@jimblandy
jimblandy / foo.html
Created September 6, 2017 21:58
Example page illustrating element object properties visible as variables
<body>
<form id='myform' x="form's attr x">
<input id='mybutton' type='button' y="button's attr y"
onclick='console.log("hi, " + x + ", " + y); log_this(); log_that();'>
</input>
</form>
<script>
var form = window.document.getElementById('myform');
form.x = "form's property x";
@jimblandy
jimblandy / heads.py
Created August 4, 2017 03:51
There must be a better way to compute this...
import random
random.seed()
def flip():
return random.choice([True, False])
def run():
b = flip()
n = 1
@jimblandy
jimblandy / js-fn-edit.el
Last active July 18, 2017 00:24
Emacs major mode for editing SpiderMonkey JS_FN_HELP entries.
;;; edit-js-fn.el --- Edit JS_FN_HELP sections in SpiderMonkey shell files
;; See js-fn-edit-documentation.
(defvar js-fn-edit-original-buffer nil
"The buffer to which a js-fn-edit-mode buffer will store the edited text.")
(defvar js-fn-edit-original-region nil
"The region of js-fn-edit-original-buffer the original definition occupies.")
@jimblandy
jimblandy / co-contra-variance.md
Last active July 26, 2020 14:24
A simple explanation of covariance and contravariance

If you say "T is a subtype of U", that means that whenever someone wants a U, a T will do: every T works as a U. It follows from this phrasing that U is a subtype of U: certainly if someone wants a U, a U will do.

So if you imagine a type as denoting a set of values, you can write: T ⊆ U.

If every T works as a U, then a function that accepts any U is certainly also a function that accepts any T: fn(U) works as a fn(T). So fn(U) is a subtype of fn(T): fn(U)fn(T).

This is interesting, because the subtypedness gets reversed: T ⊆ U implies fn(U)fn(T).

@jimblandy
jimblandy / reborrows.md
Created January 4, 2017 23:00
Generic functions and implicit reborrows

Consider the following code:

#![allow(dead_code)]

fn f    (x: &mut i32) -> &mut i32 { x }
fn id<T>(x: T       ) -> T        { x }

fn main() {
    let mut x = 10;

let m = &mut x;