Skip to content

Instantly share code, notes, and snippets.

💭
(╯°□°)╯︵ ┻━┻

Ingvar Stepanyan RReverser

💭
(╯°□°)╯︵ ┻━┻
View GitHub Profile
@RReverser
RReverser / embind-asyncify.sh
Last active Jun 24, 2020
Embind + Asyncify
View embind-asyncify.sh
# Install tip-of-tree Emscripten
$ emsdk install tot
$ emsdk activate tot
# Build with Embind and Asyncify enabled
$ emcc --bind -s ASYNCIFY mylib.cpp -o mylib.html
View wasm-memory-from-js.js
// Create a Worker we want to share memory with:
let w = new Worker(`data:text/javascript,
onmessage = ({data: memory}) => {
// Got WebAssembly.Memory once, log same instance forever with no further postMessages:
setInterval(() => console.log('Current buffer in worker:', memory.buffer), 5_000);
}
`);
// Create a shared growable memory:
let m = new WebAssembly.Memory({ initial:1, maximum: 65536, shared: true });
// Send memory to the worker:
View encode-string-to-resizable-buffer.js
const TEXT_ENCODER = new TextEncoder();
const WASM_PAGE_SIZE = 1 << 16;
function encodeStringToBinary(str) {
// Initially allocate enough space for the case where 1 char requires 1 byte (ASCII-only).
let dest = new WebAssembly.Memory({ initial: Math.ceil(str.length / WASM_PAGE_SIZE) });
let writePos = 0;
for (;;) {
// Write starting from the last written position.
@RReverser
RReverser / better-console-log.js
Last active May 9, 2019
Better console.log in Node
View better-console-log.js
// UPD:
// Now available as npm module!
// Check out https://github.com/RReverser/better-log for details.
console.log = (function (log, inspect) {
return function () {
return log.apply(this, Array.prototype.map.call(arguments, function (arg) {
return inspect(arg, { depth: 1, colors: true });
}));
};
View cargo-test-junit.py
#!/usr/bin/env python
# Use with
# > cargo test --no-run # print compilation failures if any
# > RUST_TEST_THREADS=1 cargo test -q -- --logfile tests.log 2>failures.log; ../convert-test-log.py
import xml.etree.cElementTree as ET
import re
failure_re = re.compile(r"""thread '(.*?)' panicked at '(.*?)', tests/test\.rs:\d+:\d+
View cidr-repr.rs
extern crate bincode;
extern crate cidr;
extern crate hex_slice;
extern crate rmp_serde;
extern crate serde;
extern crate serde_bytes;
extern crate serde_cbor;
#[macro_use]
extern crate serde_derive;
View serde-cidr.rs
pub struct IpCidr(::cidr::IpCidr);
impl Debug for IpCidr {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
Debug::fmt(&self.0, f)
}
}
impl Deref for IpCidr {
type Target = ::cidr::IpCidr;
@RReverser
RReverser / userChrome.css
Last active Dec 2, 2017
Firefox CSS for nice vertical tabs with TabCenter Redux
View userChrome.css
/* Hide horizontal tab strip */
#TabsToolbar {
visibility: collapse;
}
/* Reduce width of the navigation panel so that it doesn't conflict with macOS window controls */
#nav-bar:not([inFullscreen]) {
padding-left: 70px;
}
View alt_switch.rs
macro_rules! err {
($i:expr, $kind: expr) => {
IResult::Error(error_position!($kind, $i))
};
}
macro_rules! alt_switch {
($i:expr, $($lhs_mac:ident ! ( $($lhs_arg:tt)* ) $(as $lhs_binding:pat)* => $rhs_mac:ident ! ( $($rhs_arg:tt)* ) |)+ _ => $def_mac:ident ! ( $($def_arg:tt)* )) => {{
$(if let IResult::Done(i, $($lhs_binding,)* ..) = $lhs_mac ! ( $i, $($lhs_arg)* ) {
$rhs_mac ! ( i, $($rhs_arg)* )
View rust-sample.json
{
"module": {
"inner": {
"lo": 0,
"hi": 69
},
"items": [{
"ident": "",
"attrs": [{
"id": {
You can’t perform that action at this time.