Skip to content

Instantly share code, notes, and snippets.

View jorendorff's full-sized avatar

Jason Orendorff jorendorff

View GitHub Profile
diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -366,17 +366,17 @@ enum DefineType { GetterAccessor, Setter
template<DefineType Type>
static bool
DefineAccessor(JSContext *cx, unsigned argc, Value *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (!BoxNonStrictThis(cx, args))
@jorendorff
jorendorff / gist:9979131
Created April 4, 2014 17:25
sometimes it is even more than usually clear that i have no idea what the hell i am doing
$ sudo dd if=/Users/jorendorff/Downloads/fedora.dmg of=/dev/rdisk1 bs=1m
Password:
dd: /dev/rdisk1: Resource busy
$ umount /dev/disk1
umount: /dev/disk1: not currently mounted
$ umount /dev/rdisk1
umount: /dev/rdisk1: not a directory or special device
umount: /dev/rdisk1: not currently mounted
$ sudo dd if=/Users/jorendorff/Downloads/fedora.dmg of=/dev/rdisk1 bs=1m
dd: /dev/rdisk1: Resource busy

JS:

var three = 1 + 1;

HTML:

This month, Jason Orendorff presents ES6 Generators and the Prisoner's Dilemma.

Generators are a crazy new language feature coming soon to browsers everywhere. They're hard to explain. In short they're useful for turning your inside-out code inside-in. (Because that's where the inside of your code should be. On the inside. It's too messy the other way.)

The Prisoner's Dilemma is a very simple game of cooperation, calculation, and betrayal for two players... or many.

This one the most ambitious things we've done for NashJS. If it all goes according to plan, you'll get a tutorial and hands-on experience with both topics.

You should show up for this one if:

// Here is an example of a plain old function that returns a promise.
// Nothing magic about that.
function sleep(sec) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve(undefined);
}, sec * 1000);
});
}
computeMove: function (game_id, opponentPreviousMove) {
// console.log("It is our turn in game " + game_id);
var gen = Dilemma.Games[game_id];
var result;
try {
result = gen.next(opponentPreviousMove);
} catch (exc) {
reportError(game_id, "Exception calling the .next method of your generator: " + exc.name + ": " + exc.message);
console.error(exc);
return;

Junior Developer: What's this Symbol.new thing in this class?

Senior Developer: Whenever you see new X in JS code, that's just shorthand for the Symbol.new method.

Junior Developer: Oh, OK, that makes sense.

... 15 minutes later ...

Junior Developer: I wonder why they have a new keyword at all. It seems like it could just be a method.

I love the ES6 class spec. I particularly like that it mainly provides good-looking syntax for longstanding ES1-5 idioms. But the ES1-5 idiom for instantiation of user-defined subclasses is really pretty weird, and unifying that with subclassing builtins has proved messy.

This proposal deprecates that particular idiom, the one where you use BaseClass.call(obj) to initialize a subclass object. Several simplifications are possible as a result.

(The following was not written by me.)

Today the kids and I separated DNA in the kitchen.

  1. Put bottle of ~90% rubbing alcohol in freezer for an hour. Don't let it totally freeze, but let it get cold.

  2. Mix .25 cup water with .25 tsp salt. Swish saltwater in mouth for 1 min, spit back into glass cup, which will now include cheek cells.

  3. Add a teensy mini-drop of dish soap and stir, which will lyse the cell walls.

function readOnlyArrayView(arr) {
return new Proxy({}, {
get: function (target, id) { return arr[id]; },
has: function (target, id) { return id in arr; }
});
}