Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Herman dherman

View GitHub Profile
View notes-on-buffer-api.rs
/*
* https://users.rust-lang.org/t/how-to-implement-index-range-usize-for-a-custom-slice-type-with-additional-data/66201
*
* buffer.region(4, 16).into::<JsUint32Array>
* buffer.from(4).to(16).into::<JsUint32Array>
* buffer[4..16].to_typed_array::<u32, _>(&mut cx)
* JsUint32Array::from_region(&mut cx, buffer[4..16])
* buffer.region(4..16).to_typed_array::<u32, _>(&mut cx)
* JsUint32Array::from_region(&mut cx, buffer.region(4..16))
* JsUint32Array::from_buffer_region(&mut cx, buffer, 4, 16))
View TypedArrayExt.rs
trait TypedArrayExt {
fn set_info<'cx, C: Context<'cx>>(&self, cx: &mut C, info: Handle<'cx, JsObject>) -> NeonResult<()>;
fn get_info<'cx, C: Context<'cx>>(&self, cx: &mut C) -> JsResult<'cx, JsObject> {
let info = cx.empty_object();
self.set_info(cx, info)?;
Ok(info)
}
}
@dherman
dherman / ab.js
Created Jul 15, 2022
failed experiment to monkey-patch ArrayBuffer.prototype
View ab.js
"use strict";
{
let abp = ArrayBuffer.prototype;
const VIEW = Symbol('view');
function getView(receiver) {
return receiver[VIEW] ||
(receiver[VIEW] = new Uint8Array(receiver));
}
View neon-types.md
flowchart TB
    JsValue
    JsValue-->JsObject
    subgraph primitives [Primitive Types]
        JsBoolean
        JsNumber
        JsString
        JsNull
 JsUndefined
@dherman
dherman / combos.js
Created Feb 11, 2020
quick n dirty generator of 2^6 combinations
View combos.js
const ATTRIBUTES = ['A', 'B', 'C', 'D', 'E', 'F'];
// type attribute = 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
// type value = "x" | ""
// type combo = [value]
function combos() {
return combosFrom(ATTRIBUTES, 0);
}
View tree.txt
.
├── ansi-escapes
│   ├── index.js
│   ├── license
│   ├── package.json
│   └── readme.md
├── ansi-escape-sequences
│   ├── jsdoc2md
│   │   └── README.hbs
│   ├── lib
View artifacts.json
{
"active": "release",
"targets": {
"release": {
"rustc": "rustc 1.26.0 (a77568041 2018-05-07)",
"env": {
"npm_config_target": null,
"npm_config_arch": null,
"npm_config_target_arch": null,
"npm_config_disturl": null,
View tree-flatten-macro.rs
macro_rules! const1 {
($id:ident, $depth:expr, [$($prefix:tt)*])
=>
{
const $id: [&'static str; $depth] = [$($prefix),*];
};
}
macro_rules! const_tree_at {
($depth:tt ;
View local-overrides.md

Env vars

Sandboxing

  • NOTION_HOME

Tool overrides

Possible environment variables

View unpack-fetch-progress.md
  • We want to provide good quality progress meters at console for fetch+unpack operation
  • Measuring progress smoothly requires knowing not just how many compressed bytes you have read but how many decompressed bytes you have written
  • Knowing the percentage complete of decompressed bytes written requires knowing the total decompressed size
  • Knowing the total decompressed size requires reading the field of the gzip layout that indicates decompressed size
  • That field is at a fixed offset from the end of the gzip file
  • In order to still get benefit of streaming we have to make a separate HTTP HEAD request to find the content length of the file and then a subsequent GET request to fetch just that tiny byte range to read that one field
  • (This does have overhead of a couple extra HTTP requests — anecdotally this seems cheap enough not to matter but maybe could matter in some environments?)
  • Unfortunately for GitHub releases, the files redirect to S3 URLs which seem to reject HEAD requests with a 403
  • We c