Skip to content

Instantly share code, notes, and snippets.

View jorendorff's full-sized avatar

Jason Orendorff jorendorff

View GitHub Profile
@jorendorff
jorendorff / incr_json.py
Last active April 16, 2025 17:55
incremental json parser in Python
import unicodedata
# Unique value meaning "not finished parsing"
class TimedOut:
def __repr__(self): return "TimedOut"
TimedOut = TimedOut()
BASIC_ESCAPES = {
function SaferHTML(templateData) {
var s = templateData[0];
for (var i = 1; i < arguments.length; i++) {
var arg = String(arguments[i]);
// Escape special characters in the substitution.
s += arg.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;");

Writing template strings in Markdown

With template strings coming to ES6, the backtick (`) means something in Markdown and in JavaScript. If you write this:

To display a message, write `alert(`hello world!`)`.

it'll render like this:

To display a message, write alert(hello world!).

@jorendorff
jorendorff / main.rs
Created July 4, 2024 19:55
Working actix-gcd source code for Programming Rust (build with `actix-web = "4"`)
use serde::Deserialize;
use actix_web::{web, App, HttpResponse, HttpServer};
fn gcd(mut n: u64, mut m: u64) -> u64 {
assert!(n != 0 && m != 0);
while m != 0 {
if m < n {
let t = m;
m = n;
n = t;
// Taken from http://dxr.mozilla.org/mozilla-central/source/js/xpconnect/tests/chrome/test_xrayToJS.xul
...
// Test constructors that can be instantiated with zero arguments.
for (var c of simpleConstructors) {
ok(iwin[c], "Constructors appear: " + c);
is(iwin[c], Cu.unwaiveXrays(iwin.wrappedJSObject[c]),
"we end up with the appropriate constructor: " + c);
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin[c]).constructor), iwin[c],
Before:
// Test constructors that can be instantiated with zero arguments.
for (var c of simpleConstructors) {
ok(iwin[c], "Constructors appear: " + c);
is(iwin[c], Cu.unwaiveXrays(iwin.wrappedJSObject[c]),
"we end up with the appropriate constructor: " + c);
is(Cu.unwaiveXrays(Cu.waiveXrays(new iwin[c]).constructor), iwin[c],
"constructor property is set up right: " + c);
let expectedProto = /Opaque/.test(new iwin[c]) ? iwin['Object'].prototype
On Tue, Apr 7, 2015 at 4:54 PM, Brendan Eich <brendan@mozilla.org> wrote:
> BT: we found several sites that are broken by the new function.name
> algorithm. [...]
>
> [...]
>
> ARB: which is one of these webpages?
>
> BT: cheezburger.com, the comments won't load.
>
for (VAR of ITERABLE)
STATEMENT
----
var $iterator = (ITERABLE)[Symbol.iterator]();
var $skipReturn;
try {
while (true) {
$skipReturn = true;
// *** Before *****************************************************************
// The program operated on a large document tree (DOM-like, but not exactly DOM).
// It had several functions that needed to walk the entire tree,
// which was done with recursion, like this:
function stripGrammar(doc) {
...
function visit(parent) {
for (var [i, child] of parent.content.entries()) {
if (typeof child === "object") {
if (getJitCompilerOptions()["ion.warmup.trigger"] <= 90)
setJitCompilerOption("ion.warmup.trigger", 90);
function notSoEmpty2(i) {
var a = { v: i, notunboxed: undefined };
assertRecoveredOnBailout(a, true);
}
for (var i = 0; i < 100; i++) {
print(i);