Skip to content

Instantly share code, notes, and snippets.

@preveen-stack
preveen-stack / sharedarraybuffer_in_nodejs.md
Last active May 10, 2024 09:27
SharedArrayBuffer in nodejs

SharedArrayBuffer is a feature in JavaScript that allows multiple JavaScript processes to share the same memory space. This can be particularly useful in scenarios where you need to communicate and synchronize data between different threads or processes efficiently.

In Node.js, SharedArrayBuffer is supported starting from version 12. It provides a way to share raw binary data across different JavaScript contexts, such as web workers, or in the case of Node.js, across different worker threads using the worker_threads module.

Here's a basic overview of how you can use SharedArrayBuffer in Node.js:

  1. Creating a SharedArrayBuffer: You can create a SharedArrayBuffer using the new SharedArrayBuffer() constructor. For example:

const sab = new SharedArrayBuffer(1024); // Creates a SharedArrayBuffer with 1024 bytes

[dependencies]
quote = "1.0"
use quote::quote;

fn main() {
	let field1 = quote! { x: u32 };
@preveen-stack
preveen-stack / get_window_size_rust.md
Created May 7, 2023 16:18
get the size of the terminal in rust
[dependencies]
libc = "0.2"
extern crate libc;

use std::mem;
use std::os::unix::io::AsRawFd;
@preveen-stack
preveen-stack / rust macro_expand.md
Last active May 6, 2023 11:48
macro expansion in rust

In rust the in order to see the expansion of the macros like println! we can use the rust-expand crate

First install the crate

cargo install cargo-expand

then use cargo expand command

@preveen-stack
preveen-stack / wifi
Created December 3, 2021 12:59 — forked from mdaffin/wifi
A script to make connecting with wpa_cli easier (Work in progress)
#!/bin/bash
# Wraps aursync command to mount an amazon s3 bucket which contains a repository
set -uo pipefail
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
INTERFACE=wlp58s0
wpa() {
wpa_cli -i "${INTERFACE}" "$@"
}