Skip to content

Instantly share code, notes, and snippets.

View jorendorff's full-sized avatar

Jason Orendorff jorendorff

View GitHub Profile

Proof that I am not as good at computers as I think I am

Or, a conversation between a doofus and rustc.

Yehuda Katz gave a talk about Rust to Ruby people, and he had this on a slide:

fn main() {
    let v = vec![String::from("rails")]
        .tap(|v| v.extend(std::env::args()))

.tap(|v| v.push(String::from("-h")));

// SIZE is the maximum size of List nodes.
//
// A List is made of nodes. Each node stores some slice of the List,
// a contiguous range of elements. Nodes are automatically shared
// among Lists that have a lot of elements in common. A node's data
// is stored either as a flat array of values or as a trie,
// an array of nodes.
//
// SIZE is the maximum size of all these arrays.
// So it controls the granularity of sharing between Lists.
— mrrrgn pretty sure she has destructuring with shorthand defaults in the bag https://www.youtube.com/watch?v=cyWWf1Zo28g
4:35 PM <mrrrgn> https://irccloud.mozilla.com/pastebin/PzoPzVgu
4:35 PM — mrrrgn lolz
4:37 PM <sfink> you can't have everything
4:38 PM <mrrrgn> haha
4:41 PM → ricotz joined (rico@moz-o0q9ha.dip0.t-ipconnect.de)
4:42 PM <mrrrgn> It's not hopeless. This patch gives us a way to stash errors and continue parsing, and if any slip past there's a nice segfault waiting ^ courtesy MOZ_ASSERT
4:42 PM <shu> you should stash segfaults
4:42 PM <shu> and continue parsing
4:42 PM <mrrrgn> lmao
// how I would implement https://github.com/kripken/lua.vm.js/blob/master/src/lua.js#L6-L27
var cached_constructors = [];
// applying arguments to new isn't easy with js.....
function new_(a, b, c, d, e, f, g, h, i) {
switch (arguments.length) {
case 0: return new this();
case 1: return new this(a);
case 2: return new this(a, b);
(function () {
var real_fetch = window.fetch;
window.fetch = function () {
console.log("calling fetch:", arguments)
return real_fetch.apply(this, arguments).then(function (value) {
console.log("fetch succeeded:", value);
return value;
});
};
})();
(function () {
var XHREventTargetPrototype = Object.getPrototypeOf(XMLHttpRequest.prototype);
var desc = Object.getOwnPropertyDescriptor(XHREventTargetPrototype, "onload");
var real_set_onload = desc.set;
Object.defineProperty(XHREventTargetPrototype, "onload", {
set: function onload(real_callback) {
real_set_onload.call(this, function fake_callback() {
console.log("loaded:", arguments);
return real_callback.apply(this, arguments);
});
<!doctype html>
<html>
<head>
<title>js speed test</title>
</head>
<body>
<script>
{
let a = [];
function wetA() {};
function wetB() {};
wetB.prototype = new wetA();
var wet_b = new wetB();
// Reflect.get(wetB, "prototype") === Reflect.getPrototypeOf(wet_b);
// boilerplate, not really that important
function valueType(value) {
if (value === null)

Anomalies in mainstream programming language grammar: an incomplete freak show

Parser generators have existed forever. Why don't any serious compilers use them?

Well, Python uses one... written from scratch to parse Python, unsuitable for any other project.

One reason is that programming languages are such amazing trash. The more widely used a language is, the more likely it is