Skip to content

Instantly share code, notes, and snippets.

View dherman's full-sized avatar

Dave Herman dherman

View GitHub Profile
{"reason":"compiler-artifact","package_id":"proc-macro2 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)","manifest_path":"/Users/dherman/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.53/Cargo.toml","target":{"kind":["custom-build"],"crate_types":["bin"],"name":"build-script-build","src_path":"/Users/dherman/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.53/build.rs","edition":"2018","doc":false,"doctest":false,"test":false},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":["proc-macro"],"filenames":["/Users/dherman/Sources/neon-prebuild-example/target/debug/build/proc-macro2-7bfb42c5b5753c49/build-script-build"],"executable":null,"fresh":true}
{"reason":"build-script-executed","package_id":"proc-macro2 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)","linked_libs":[],"linked_paths":[],"cfgs":["use_proc_macro","wrap_proc_macro"],"env":[],"out_dir":"/Users/dherman/Sources/neon-prebuil
@dherman
dherman / linkify.rs
Created January 8, 2023 00:38
small example of exposing a Rust crate's functionality through tasks and promises
use neon::prelude::*;
use neon::types::buffer::TypedArray;
use linkify::{LinkFinder, LinkKind, Span};
// Purely indexed version of Span<'t> that removes reference to the original string.
struct IndexSpan {
start: u32,
end: u32,
kind: u32,
}
dherman@dherman-mn2 neon % npm test
> test
> npm run test:rust && npm run test:js
> test:rust
> cargo neon-test
Compiling neon v1.0.0-alpha.1 (/Users/dherman/Sources/neon/crates/neon)
/*
* 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))
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 July 15, 2022 16:51
failed experiment to monkey-patch ArrayBuffer.prototype
"use strict";
{
let abp = ArrayBuffer.prototype;
const VIEW = Symbol('view');
function getView(receiver) {
return receiver[VIEW] ||
(receiver[VIEW] = new Uint8Array(receiver));
}
flowchart TB
    JsValue
    JsValue-->JsObject
    subgraph primitives [Primitive Types]
        JsBoolean
        JsNumber
        JsString
        JsNull
 JsUndefined
@dherman
dherman / combos.js
Created February 11, 2020 18:29
quick n dirty generator of 2^6 combinations
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);
}
.
├── ansi-escapes
│   ├── index.js
│   ├── license
│   ├── package.json
│   └── readme.md
├── ansi-escape-sequences
│   ├── jsdoc2md
│   │   └── README.hbs
│   ├── lib
{
"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,