Skip to content

Instantly share code, notes, and snippets.

Avatar

Dave Herman dherman

View GitHub Profile
@dherman
dherman / linkify.rs
Created January 8, 2023 00:38
small example of exposing a Rust crate's functionality through tasks and promises
View linkify.rs
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,
}
View neon-test-failure.txt
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)
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 July 15, 2022 16:51
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 February 11, 2020 18:29
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 ;