Skip to content

Instantly share code, notes, and snippets.

/*
Generators are kind of confusing, so here's place to start.
*/
import { strict as assert } from "assert"
import { describe, it } from "mocha"
function run<T>(
@ccorcos
ccorcos / RemoteQueryPlanner.ts
Last active April 1, 2022 23:16
A defunctionalized fluent API for composing and evaluating queries in a remote process.
import { strict as assert } from "assert"
// Using a strategy similar to the Selenium Framework:
// https://gist.github.com/ccorcos/5372e1f946927d5043f070fb9260fcea
// ============================================================================
// Remote API
// ============================================================================
// Types that define the procedures in the remote process.
import { strict as assert } from "assert"
import EventEmitter from "events"
import { describe, it } from "mocha"
import { IPCPeer } from "./IPCPeer"
function setupPeers<
A2B extends AnyFunctionMap = AnyFunctionMap,
B2A extends AnyFunctionMap = AnyFunctionMap
>() {
const aEvents = new EventEmitter()
// This object encapsulates the state and dispatches events.
class Store<T> {
constructor(public state: T) {}
public setState = (nextState: T) => {
this.state = nextState
this.emit()
}
@ccorcos
ccorcos / node.log
Created November 20, 2019 05:36
Garbage Collection Issue.
This file has been truncated, but you can view the full file.
~/C/j/js-avl-tree ❯❯❯ node --trace-gc build/bench/treedb.js
[81445:0x103b26000] 42 ms: Scavenge 2.5 (4.2) -> 2.2 (5.2) MB, 0.8 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
[81445:0x103b26000] 52 ms: Scavenge 2.8 (5.2) -> 2.7 (6.2) MB, 0.9 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
[81445:0x103b26000] 77 ms: Scavenge 4.0 (6.2) -> 3.9 (9.2) MB, 0.5 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
starting
0
[81445:0x103b26000] 176 ms: Scavenge 6.6 (11.2) -> 5.6 (12.2) MB, 0.6 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
[81445:0x103b26000] 184 ms: Scavenge 7.1 (12.2) -> 5.7 (12.7) MB, 0.5 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
[81445:0x103b26000] 191 ms: Scavenge 7.6 (12.7) -> 5.9 (16.7) MB, 0.5 / 0.0 ms (average mu = 1.000, current mu = 1.000) allocation failure
[81445:0x103b26000] 206 ms: Scavenge 9.7 (16.7) -> 6.3 (16.7) MB, 0.5 / 0.0 ms (ave
@ccorcos
ccorcos / selenium-framework.ts
Created September 19, 2019 17:52
Using Selenium for browser testing as an alternative to Cypress.
/* =============================================================================
Selenium Framework
Example:
```
it("browser test", async () => {
await withBrowser(async browser => {
await browser.visit("/login")
await browser.clickText("Login with email")
import * as _ from "lodash"
/** This is how DataTypes are serialized. */
export type DataType =
| { type: "string" }
| { type: "number" }
| { type: "boolean" }
| { type: "literal"; value: string | number | boolean }
| { type: "array"; inner: DataType }
// Tuple types are not quite working yet.
❯❯❯ ios_webkit_debug_proxy -d
ss.add_server_fd(3)
Listing devices on :9221
ss.add_fd(4)
ss.add_server_fd(5)
ss.remove_server_fd(5)
ss.recv fd=4 len=981
ss.add_server_fd(5)
ss.add_fd(9)
wi.send_packet[174]:
❯❯❯ ios_webkit_debug_proxy -d
ss.add_server_fd(3)
Listing devices on :9221
ss.add_fd(4)
ss.add_server_fd(5)
ss.remove_server_fd(5)
ss.recv fd=4 len=981
ss.add_server_fd(5)
ss.add_fd(9)
@ccorcos
ccorcos / com.demo.daemon.plist
Last active November 4, 2023 22:05
Simple launchd template
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.demo.daemon.plist</string>
<key>RunAtLoad</key>
<true/>