Skip to content

Instantly share code, notes, and snippets.

View mafintosh's full-sized avatar

Mathias Buus mafintosh

View GitHub Profile
const speedometer = require('speedometer')
const speed = speedometer()
setInterval(function () {
console.log(speed())
}, 1000)
const udp = chrome.sockets.udp
udp.create({}, function (res) {
const stream = require('stream')
const r = new stream.Readable({
read () {
this.push('hello')
this.push('world')
this.push(null)
}
})
/usr/bin/python2.7 tools/gyp_node.py -f make
File "<string>", line 1
import sys; print sys.byteorder
^
SyntaxError: invalid syntax
gyp: Call to 'python -c "import sys; print sys.byteorder"' returned exit status 1 while in /home/maf/dev/node/deps/v8/gypfiles/v8.gyp.
make: *** [Makefile:130: out/Makefile] Error 1
@mafintosh
mafintosh / README.md
Last active August 21, 2022 21:12
Using shared-structs with workers <3

Using shared-structs with Workers <3

This showcases how you can use shared-structs over an SharedArrayBuffer, to share complex data structures between worker_threads in Node.js

The main.js example starts a worker and passes a shared struct to it.

The worker will periodically update the struct with an incrementing tick and a random number

function injectEvent (e, name, fn) {
if (!e._events[name]) e._events[name] = []
e._events[name].push(fn)
e._eventsCount++
}
const toString = require('tree-to-string')
const util = require('util')
module.exports = BTree
function BTree () {
this.feed = []
}
BTree.prototype.put = function (key, value) {
[ 1 ]─┐
├─[ 2 ]─┐
[ 3 ]─┘ │
├─[ 3.1 ]─┐
[ 3.2 ]─┐ │ │
├─[ 3.3 ]─┘ │
[ 3.4 ]─┘ │
├─[ 3.5 ]─┐
[ 3.6 ]─┐ │ │
(module
(memory (export "memory") 10 10000)
(func (export "index_of") (param $start i32) (param $end i32) (param $needle i32) (result i32)
(block $end_loop
(br_if $end_loop (i32.eq (get_local $start) (get_local $end)))
(if (i32.eq (i32.load8_u (get_local $start)) (get_local $needle))
(then (return (get_local $start)))
)
(set_local $start (i32.add (i32.const 1) (get_local $start)))
@mafintosh
mafintosh / streams-workshop-notes.md
Last active May 31, 2018 14:17
Stream notes from the collab summit
  • Streams cookbook.
  • How do we scale the dev?
  • Document the userland modules.
  • Add tests for the event ordering.
  • Use readable-stream as the issue tracker / call to action for streams.
  • We need mini streams summit.
// by @noffle
autoinstall () {
local MODULES=$(cat $1 | grep "require('.*')" | sed "s/.*require('\(.*\)')/\1/" | grep -v '^\.' | tr '\n' ' ')
shift
shift
npm install $MODULES $@
}