Skip to content

Instantly share code, notes, and snippets.

// We introduce two new keywords:
// suspend - Creates "suspended" functions, which will make your asynchronous code "synchronous" while keeping your UI responsive
// next - A "return" keyword for suspended functions
// Exhibit A: sleep function, no return value
external setTimeout;
suspend void sleep(int ms) { // use the 'suspend' modifier
setTimeout(void() {
next; // we do not return a value
abstract class Node {}
abstract class Statement : Node {}
abstract class Expression : Node {}
class Program : Node
{
Statement[] body;
Program() {
this.body = [];
@rogerpoon
rogerpoon / results.txt
Created January 12, 2019 01:41
Typescript OOB
$ ./node_modules/typescript/bin/tsc --version
Version 3.2.2
$ cat test.ts
const xs: number[] = [1,2,3];
let x:number = xs[100] // number, even with strictNullChecks
console.log(x);
$ time ./node_modules/typescript/bin/tsc --strictNullChecks test.ts
real 0m1.084s
@rogerpoon
rogerpoon / sort.jspp
Created October 29, 2017 05:17
JS++ Custom Sorting
import System;
class Employee : IComparable<Employee>
{
private string firstName;
private string lastName;
public Employee(string firstName, string lastName) {
this.firstName = firstName;
this.lastName = lastName;
@rogerpoon
rogerpoon / regexp.cpp
Created August 17, 2017 02:02
We need a new regex standard besides POSIX BRE/ERE and ECMAScript
// ECMAScript regex
std::regex re_param(R"((\S+)\s+([\s\S]+))");
// vs.
// PCRE
pcrecpp::RE re_param(
"(?# Match the annotation name)(\\S+)"
"(?# Skip over whitespace)\\s+"
"(?# Match the annotation description text)([\\s\\S]+)"
@rogerpoon
rogerpoon / hamming.cpp
Created August 6, 2017 05:15
Fast C++ Bitwise Hamming Distance
#include <bitset>
#include <cassert>
#include <cstdint>
int main() {
const uint64_t a = 3, b = 5;
const size_t diff = a ^ b;
std::bitset<64> diff_bits(diff);
assert(diff_bits.count() == 2);
import System;
external Uint8Array;
class ByteArray
{
var stack;
ByteArray(int size) {
this.stack = new Uint8Array(size);