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 / 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/>
@ccorcos
ccorcos / symmetric_crypto.coffee
Created November 6, 2014 02:29
AES symmetric encryption crypto node.js
crypto = require "crypto"
key = "this is my password. Make it as long as you want. But its hashed into 512 bytes."
text = "This is the text. as long as you want it"
hash = (utf8String)->
hasher = crypto.createHash('sha512')
hasher.update(utf8String, 'utf8')
hexString = hasher.digest('hex')
return hexString
@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")
@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
This file has been truncated, but you can view the full file.
{"objects":{"id76q4bmj0blvfhe0":{"editingElement":{"__ref":"id7cwk5ej0bmw03v1u8"},"selectedParticularElement":null,"createPanelElements":[{"__ref":"Rectangle"},{"__ref":"Circle"},{"__ref":"Text"},{"__ref":"Image"},{"__ref":"idikabraj0blvfhe1"},{"__ref":"iddguqtej0bm17osdh"},{"__ref":"id23c44rj0bmdxmau0"},{"__ref":"idcbtfhxj0bmgqpg122"},{"__ref":"id0jctv6j0bmhhqg19r"},{"__ref":"id7cwk5ej0bmw03v1u8"},{"__ref":"iduy6mu2j0bofh8e77"},{"__ref":"idnma7i7j0bsiada86"}],"id":"id76q4bmj0blvfhe0","__proto":{"__ref":"Project"}},"id7cwk5ej0bmw03v1u8":{"_master":{"__ref":"Group"},"_head":{"__ref":"id7cwk5ej0bmw03v1u8"},"_variants":[{"__ref":"idskxudlj0bsihcz94"}],"_parent":null,"_children":[{"__ref":"idli3je4j0bmw05t1uf"},{"__ref":"id13ea62j0bmw05q1u9"},{"__ref":"idki6iwcj0bmw05r1uc"},{"__ref":"idcjkgjyj0bmwd2o1v6"},{"__ref":"id1ze4mzj0bmwht21v7"},{"__ref":"idejv7w8j0bmy9de1w3"},{"__ref":"idp0aacpj0bmyw5f1x8"},{"__ref":"id018i3ij0bn27kp1yv"},{"__ref":"ids49flwj0bncpo722d"},{"__ref":"idq0jznbj0bne4py2ns"},{"__ref":"idsw1e57j
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.