Skip to content

Instantly share code, notes, and snippets.

View rnewman's full-sized avatar

Richard Newman rnewman

  • AWS
View GitHub Profile
@rnewman
rnewman / aw.html
Last active March 4, 2021 23:49
Loopback worklet example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Audio Worklet loopback test</title>
</head>
<body>
<h1>Loopback test</h1>
<ol>
@rnewman
rnewman / expiration.md
Created April 23, 2018 17:23
Expiration of data in Mentat

Some classes of applications, including browsers, generate an ever-growing set of data: visits to pages, plays of songs and videos, purchases, messages.

It's routine for these applications to have approaches to scaling by minimizing the 'working' data set: expiration of old data, archiving of subsets of the data, or similar.

The simplest approach to scale is to more carefully constrain queries, doing most of the work on only a subset of the candidates — e.g., evaluating, ranking, and extracting only history entries with any visit within the last year, rather than ranking all history entries and applying a limit after ranking. Sometimes this kind of bounding is sufficient.

When it isn't, we need other mechanisms for reducing the working set.

Data in Mentat lives in these four places:

@rnewman
rnewman / gist:c76e3e9fe223260b5fa0c8b794abf442
Created February 1, 2018 19:51
Fragment of about:memory
│ ├───1,269,208 B (00.16%) -- @testpilot-addon
│ │ ├──1,102,472 B (00.14%) -- window-objects/top(moz-extension://8358893d-3bff-784c-9e3b-d2dd235a93c2/_generated_background_page.html, id=91)
│ │ │ ├────701,496 B (00.09%) -- js-zone(0x162f0c000)
│ │ │ │ ├──362,432 B (00.05%) ── unused-gc-things
│ │ │ │ ├──127,904 B (00.02%) -- shapes
│ │ │ │ │ ├──112,704 B (00.01%) -- gc-heap
│ │ │ │ │ │ ├───87,064 B (00.01%) ── tree
│ │ │ │ │ │ ├───21,832 B (00.00%) ── dict
│ │ │ │ │ │ └────3,808 B (00.00%) ── base
│ │ │ │ │ └───15,200 B (00.00%) -- malloc-heap
@rnewman
rnewman / query_test.rs
Created January 23, 2018 19:05
Example test for prepared query
#[test]
fn test_simple_prepared_query() {
let mut c = new_connection("").expect("Couldn't open conn.");
let mut conn = Conn::connect(&mut c).expect("Couldn't open DB.");
conn.transact(&mut c, r#"[
[:db/add "s" :db/ident :foo/boolean]
[:db/add "s" :db/valueType :db.type/boolean]
[:db/add "s" :db/cardinality :db.cardinality/one]
]"#).expect("successful transaction");
@rnewman
rnewman / Video example.clj
Created September 19, 2017 18:20
Example attribute definitions and data for video
;; Vocabulary:
[
;; Devices.
{:db/ident :device/name
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db/doc "The name of the FxA device."}
{:db/ident :device/platform
:db/valueType :db.type/keyword
objc[9628]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x1110dbcc0) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x110e516f0). One of the two will be used. Which one is undefined.
2017-07-26 14:10:39.297 [Debug] [AppDelegate.swift:55] application(_:willFinishLaunchingWithOptions:) > Configuring window…
2017-07-26 14:10:39.301 [Debug] [AppDelegate.swift:71] startApplication(_:withLaunchOptions:) > Initializing Sentry…
2017-07-26 14:10:39.305 [Error] [SentryIntegration.swift:23] setup(sendUsageData:) > Not enabling Sentry; Running in Simulator
2017-07-26 14:10:39.305 [Debug] [AppDelegate.swift:77] startApplication(_:withLaunchOptions:) > Setting UA…
2017-07-
trait FromValue<T> {
fn from_value(edn::Value) -> Option<T>;
}
impl FromValue<PatternNonValuePlace> for PatternNonValuePlace {
fn from_value(v: edn::Value) -> Option<PatternNonValuePlace> {
match v {
edn::Value::Integer(x) => if x >= 0 {
Some(PatternNonValuePlace::Entid(x as u64))
@rnewman
rnewman / gist:fe3051d309ef5abd68e890ed13b38acd
Created January 12, 2017 23:51
Datomic client wire spec
;; From com/datomic/client.wire-specs/0.1.21/
;; Copyright (c) Cognitect, Inc.
;; All rights reserved.
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
@rnewman
rnewman / cljify.cljs
Created September 21, 2016 20:58
js->clj that works across contexts
(defn cljify
"Does what `(js->clj o :keywordize-keys true) is supposed to do, but works
in environments with more than one context (e.g., web browsers).
See <http://dev.clojure.org/jira/browse/CLJS-439?focusedCommentId=43909>.
Note that Date instances are passed through."
[o]
(cond
(nil? o)
@rnewman
rnewman / gist:9cf59439b0fccc6f60be
Created February 4, 2016 03:18
Tests that pass!
// This test describes a scenario like this:
//
// [] [] []
// [M] [T] [M] [T] [M] [T]
// | | | | | |
// [C] [A] [C] [A] [C] [A]
// | | | |
// [D] [D] [B] [B]
// | |
// F E