This is a port of this blog post to javascript. The one annoying issue with it is that you need to install node-fetch somehow (or put this script somewhere that has access to node-fetch). I could adapt this to use no deps, but it'd be longer and uglier.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {strPosToUni, uniToStrPos} = require('unicount') | |
// The cursor position (input and output) are specified in JS string | |
// offsets here. | |
function transformJSPosition(cursor /*: number*/, doc /*: string*/, op /*: TextOp*/) { | |
let prePos = 0, postPos = 0 // string index in doc. | |
for (let i = 0; i < op.length && cursor > postPos; i++) { | |
const c = op[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main.rs b/src/main.rs | |
index 19c571c..3cf9380 100644 | |
--- a/src/main.rs | |
+++ b/src/main.rs | |
@@ -3,10 +3,7 @@ | |
#[macro_use] | |
extern crate serde_json; | |
-use sodiumoxide::crypto::{box_, sign, auth, scalarmult, secretbox}; | |
-use sodiumoxide::crypto::hash::sha256; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is an example of making a c-style struct ending in a dynamically sized array in stable rust. | |
use std::alloc::{GlobalAlloc, Layout, System}; | |
struct Blah { | |
height: usize, | |
arr: [u8; 0], | |
} | |
impl Blah { | |
fn get_layout_at(height: usize) -> Layout { |
In case anyone else wants to play with Zig on webassembly, here's what you need to do to make it work on a mac today.
You'll need LLVM to output to the WASM target. This has just been added by default in trunk, so if LLVM >7 is available, you might be able to just brew install llvm
.
If you have wasm support already you should see:
$ llc --version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## foundationdb.conf | |
## | |
## Configuration file for FoundationDB server processes | |
## Full documentation is available at | |
## https://www.foundationdb.org/documentation/configuration.html#foundationdb-conf | |
[general] | |
restart_delay = 60 | |
## by default, restart_backoff = restart_delay_reset_interval = restart_delay | |
# initial_restart_delay = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 2 entities, George and Phil will meet on this fateful night | |
const e1 = { | |
name: 'George', | |
health: 400, | |
target: null, | |
} | |
const e2 = { | |
name: 'Phil', | |
health: 400, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const e1 = { | |
name: 'George', | |
health: 1000, | |
target: null, | |
} | |
const e2 = { | |
name: 'Phil', | |
health: 1000, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Some example behaviours | |
// Helper to wait X frames | |
function *wait(framecount) { | |
while(--framecount) yield // Each call to yield will wait 1 frame | |
} | |
// Dance function will | |
function *dance() { | |
console.log('\\_o_\\') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request') | |
const crypto = require('crypto') | |
const API_KEY = 'API KEY GOES HERE' | |
const API_SECRET = Buffer.from('SECRET GOES HERE', 'base64') | |
const md5 = str => crypto.createHash('md5').update(str).digest().toString('base64') | |
const hmac = str => crypto.createHmac('sha256', API_SECRET).update(str).digest().toString('base64') | |
const getBalance = (currency) => { |