Skip to content

Instantly share code, notes, and snippets.

@achingbrain
achingbrain / index.js
Last active February 5, 2024 14:03
Node A and Node B, both connected to Node C
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { gossipsub } from '@chainsafe/libp2p-gossipsub'
import { webSockets } from '@libp2p/websockets'
import { createLibp2p } from 'libp2p'
import { identify } from '@libp2p/identify'
import * as filters from '@libp2p/websockets/filters'
const TOPIC_NAME = 'test-topic'
@achingbrain
achingbrain / index.js
Created September 20, 2023 06:26
lib-datachannel large byte transfer
const nodeDataChannel = require('node-datachannel')
// Log Level
// nodeDataChannel.initLogger("Debug")
// increase `messagesToSend` until `Peer2` no longer receives all of the messages
const messagesToSend = 5000
// the number of successfully sent messages
let messagesSent = 0
// the number of successfully received messages
@achingbrain
achingbrain / benchmark.js
Last active May 2, 2024 08:38
Streaming benchmark
import { Readable, Writable } from 'node:stream'
import { pipe } from 'it-pipe'
const ITERATIONS = 1000
function createData () {
return new Array(1024).fill(0).map(() => new Uint8Array(1024))
}
async function nodeStreams () {
@achingbrain
achingbrain / index.ts
Last active February 1, 2023 07:05
TS project
// /src/index.ts
import * as multiformats from "multiformats";
console.info(multiformats)

Keybase proof

I hereby claim:

  • I am achingbrain on github.
  • I am achingbrain (https://keybase.io/achingbrain) on keybase.
  • I have a public key ASDBetlw8CDEo5HDwLv-HbOe46GauEHEe6RI-CXxISBWVAo

To claim this, I am signing this object:

@achingbrain
achingbrain / search.js
Last active August 29, 2015 14:25
node-hue-api and LOCATION headers
var hue = require("node-hue-api"),
timeout = 2000; // 2 seconds
var displayBridges = function(bridge) {
console.log("Hue Bridges Found: " + JSON.stringify(bridge));
};
hue.upnpSearch(timeout).then(displayBridges).done();
@achingbrain
achingbrain / gist:c257e68c4ff547d09328
Last active August 29, 2015 14:23
Trying to download a tarball from Nexus with npm

npm pack outputs a .tgz file which we've deployed to Nexus:

$ curl -I http://nexus/path/foo.tgz
HTTP/1.1 200 OK
Date: Mon, 29 Jun 2015 08:40:25 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONID=10ob3uo99m54y;Path=/nexus
Content-Type: application/x-compressed
Last-Modified: Fri, 26 Jun 2015 10:16:45 GMT
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.8.13-bone67 (root@a5-imx6q-wandboard-2gb) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Wed Sep 24 21:30:03 UTC 2014
[ 0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=50c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine: Generic AM33XX (Flattened Device Tree), model: TI AM335x BeagleBone
[ 0.000000] Memory policy: ECC disabled, Data cache writeback
[ 0.000000] On node 0 totalpages: 130816
[ 0.000000] free_area_init_node: node 0, pgdat c08b2780, node_mem_map c092f000
[ 0.000000] Normal zone: 1024 pages used for memmap
kernel_file=zImage
initrd_file=uInitrd
initrd_high=0xffffffff
fdt_high=0xffffffff
#Video: Uncomment to override:
#kms_force_mode=video=HDMI-A-1:1024x768@60
##BeagleBone Cape Overrides
##Note: On the BeagleBone Black, there is also an uEnv.txt in the eMMC, so if these changes do not seem to be makeing a difference...
[ 0.000000] Booting Linux on physical CPU 0x0
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 3.8.13-bone28 (root@imx6q-wandboard-2gb-0) (gcc version 4.6.3 (Debian 4.6.3-14) ) #1 SMP Thu Sep 12 23:22:35 UTC 2013
[ 0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7), cr=10c5387d
[ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
[ 0.000000] Machine: Generic AM33XX (Flattened Device Tree), model: TI AM335x BeagleBone
[ 0.000000] Memory policy: ECC disabled, Data cache writeback
[ 0.000000] On node 0 totalpages: 130816
[ 0.000000] free_area_init_node: node 0, pgdat c09d2540, node_mem_map c0a4d000
[ 0.000000] Normal zone: 1024 pages used for memmap