Skip to content

Instantly share code, notes, and snippets.

// Here is a proposal for minimalist JavaScript classes, humbly offered.
// There are (at least) two different directions in which classes can be steered.
// If we go for a wholly new semantics and implementation, then fancier classical
// inheritance can be supported with parallel prototype chains for true inheritance
// of properties at both the class and instance level.
// If however, we keep current JavaScript prototype semantics, and add a form that
// can desugar to ES3, things must necessarily stay simpler. This is the direction
// I'm assuming here.
@BrendanEich
BrendanEich / minimalist-classes.js
Created November 1, 2011 22:48 — forked from jashkenas/minimalist-classes.js
less minimalism, richer leather
// A response to jashkenas's fine proposal for minimalist JavaScript classes.
// Harmony always stipulated classes as sugar, so indeed we are keeping current
// JavaScript prototype semantics, and classes would only add a syntactic form
// that can desugar to ES5. This is mostly the same assumption that Jeremy
// chose, but I've stipulated ES5 and used a few accepted ES.next extensions.
// Where I part company is on reusing the object literal. It is not the syntax
// most classy programmers expect, coming from other languages. It has annoying
// and alien overhead, namely colons and commas. For JS community members who
@jhusain
jhusain / Response
Created August 19, 2015 18:19
Games JSON Graph
//You shouldn't find your self asking for ids from a Falcor JSON Graph object.
//it seems like you want to build an array of game ids:
{
games: [
{ $type: "ref", value: ["gamesById", 352] },
{ $type: "ref", value: ["gamesById", 428] }
// ...
],
var spec = { enumerable: false }
var x = {};
Object.defineProperty(x, "test", spec);
x.test = "what"
alert(JSON.stringify(x));
var y = {};
Object.defineProperty(y, "test", spec);
@jhusain
jhusain / PEG grammer for pattern match syntax
Created October 29, 2016 03:29
PEG grammer for pattern match syntax. Forked from JSON grammer.
JSON_text
= ws value:value ws { return value; }
begin_array = ws "[" ws
begin_object = ws "{" ws
end_array = ws "]" ws
end_object = ws "}" ws
name_separator = ws ":" ws
value_separator = ws "," ws
@jhusain
jhusain / Simple Observable impl
Created May 4, 2017 00:26
Observable implementation which optimizes very well in prepack
function Observable(subscribe) {
this._subscribe = subscribe;
}
const of = (v) => new Observable(observer => {
return observer.next(v);
});
Observable.prototype = {
map(f) {
@BrendanEich
BrendanEich / ta_vs_nt
Created August 17, 2011 23:20
typed array vs. number type
js> b = new ArrayBuffer(64)
({})
js> a = new Uint32Array(b)
({0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 14:0, 15:0})
js> a[0]
0
js> a[0] = Math.pow(2,32)
4294967296
js> a[0]
0
@BrendanEich
BrendanEich / gist:5753666
Created June 11, 2013 00:36
ES6 version of Peter Norvig's Sudoku solver originally written in Python
// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their iterator.
Array.prototype.contains = String.prototype.contains = function (e) {
@jhusain
jhusain / MyFree.purs
Created January 17, 2018 17:57
MyFree implementation
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Foldable (fold)
import TryPureScript (DOM, h1, h2, p, text, list, indent, link, render, code)
type Video = { name:: String }
@kabili207
kabili207 / Rclone systemd service.md
Last active May 6, 2024 03:20
Rclone systemd user service

rclone systemd service

Preparation

This service will use the same remote name you specified when using rclone config create. If you haven't done that yet, do so now.

Next, create the mountpoint for your remote. The service uses the location ~/mnt/<remote> by default.

mkdir ~/mnt/dropbox