Skip to content

Instantly share code, notes, and snippets.

View treasonx's full-sized avatar

James Morrin treasonx

  • San Francisco CA
View GitHub Profile
@dherman
dherman / realms-api.md
Last active March 8, 2024 07:04
ES6 Realms API

Notational Conventions

This section describes the conventions used here to describe type signatures.

A [T] is an array-like value (only ever used read-only in this API), i.e., one with an integer length and whose indexed properties from 0 to length - 1 are of type T.

A type T? should be read as T | undefined -- that is, an optional value that may be undefined.

Realms

@dherman
dherman / loader-api.md
Last active January 31, 2019 03:02
Complete ES6 Loader API

Notational Conventions

This section describes the conventions used here to describe type signatures.

A [T] is an array-like value (only ever used read-only in this API), i.e., one with an integer length and whose indexed properties from 0 to length - 1 are of type T.

A type T? should be read as T | undefined -- that is, an optional value that may be undefined.

Loaders

@dherman
dherman / realms.md
Last active December 27, 2015 10:39
Why (hookable) eval/Function, globals, and realms are all necessarily coupled.

Design "theorem".

The (hookable) eval/Function function objects, the global object, and the realm all have to be in 1:1 correspondence.

"Proof".

(a) same realm ==> same Function

Since Function is reachable by function literals, it is tied to a realm.

@dherman
dherman / direct-eval.md
Last active December 21, 2015 17:59
generating direct eval ES6

I struggle with this question from time to time.

Lots of tools compile to JS, not just compilers for other languages but also JS language extensions and instrumentation. In those cases you want to minimally perturb the semantics of JS. Direct eval is the hard part I struggle with.

Let's assume for the moment you have some global variable $RT you can access to get to the compiler's runtime. There are tricky bits to this, but let's just take it as given.

When you see an apparent direct eval in the source program, of the form eval(EXPR), you might translate to something like:

($RT.tmpEval = eval, $RT.tmpArg = EXPR, $RT.directEval((eval) => eval($RT.tmpArg)))
@dougireton
dougireton / chef.vim
Created February 8, 2013 06:25
(Broken) chef Syntastic syntax checker
function! SyntaxCheckers_chef_IsAvailable()
return executable('foodcritic')
endfunction
function! SyntaxCheckers_chef_GetLocList()
" let exe = expand(g:syntastic_ruby_exec)
" if !has('win32')
" let exe = 'RUBYOPT= ' . exe
" endif

Strict Mode: The Summary!

Identifiers (variables, functions) cannot be named any of these: "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield"

OctalLiterals are not allowed.

@jed
jed / rendering_templates_obsolete.md
Created October 19, 2012 05:07
Rendering templates obsolete

(tl;dr DOM builders like [domo][domo] trump HTML templates on the client.)

Like all web developers, I've used a lot of template engines. Like most, I've also written a few of them, some of which even [fit in a tweet][140].

The first open-source code I ever wrote was also one of the the first template engines for node.js, [a port][node-tmpl] of the mother of all JavaScript template engines, [John Resig][jresig]'s [micro-templates][tmpl]. Of course, these days you can't swing a dead cat without hitting a template engine; one in eight packages on npm ([2,220][npm templates] of 16,226 as of 10/19) involve templates.

John's implementation has since evolved and [lives on in Underscore.js][underscore], which means it's the default choice for templating in Backbone.js. And for a while, it's all I would ever use when building a client-side app.

But I can't really see the value in client-side HTML templates anymore.

@domenic
domenic / promises.md
Last active June 24, 2024 03:11
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@twilson63
twilson63 / app.js
Created September 5, 2012 02:17
AngularJS Contact Form Example
function ContactCtrl($scope, $http) {
$scope.success = false;
$scope.httpError = false;
$scope.send = function() {
var job = { job: { klass: 'msg', args: [$scope.msg]}};
$http.post('/contact',job).
success(function(data){
$scope.success = true;
$scope.msg = {};
@enjalot
enjalot / cors_server.py
Created June 10, 2012 06:19
Allow CORS with python simple http server
import SimpleHTTPServer
class CORSHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def send_head(self):
"""Common code for GET and HEAD commands.
This sends the response code and MIME headers.
Return value is either a file object (which has to be copied
to the outputfile by the caller unless the command was HEAD,
and must be closed by the caller under all circumstances), or