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
/** | |
* You are an actor. | |
* | |
* You are presented with different job opportunities that each takes a specific time to | |
* complete. You can only work on one job opportunity at a time. After accepting a job, | |
* you have to finish it. Every job is defined by an 2-element-array, which defines | |
* when it starts and when it ends. | |
* | |
* For example, if you take job [2, 4], you can't take job [4, 5] or [1, 3]. | |
* |
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
<html> | |
<video id="video" autoplay></video> | |
<!-- the javascript bindings --> | |
<script src="qr_rust.js"></script> | |
<script> | |
wasm_bindgen("qr_rust_bg.wasm") | |
.then(() => { | |
console.log('it is loaded!'); | |
// initialize the media stream |
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
function captureImage() { | |
const { decode_qr } = wasm_bindgen; | |
const video = document.getElementById('video'); | |
const canvas = document.createElement('canvas'); | |
const scale = 0.25; // we scale the image down to improve performance | |
canvas.width = video.videoWidth * scale; | |
canvas.height = video.videoHeight * scale; | |
canvas | |
.getContext("2d") |
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
__exports.decode_qr = function(bytes) { | |
const retptr = 8; | |
const ret = wasm.decode_qr(retptr, passArray8ToWasm(bytes), WASM_VECTOR_LEN); | |
const memi32 = getInt32Memory(); | |
const v0 = getStringFromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice(); | |
wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1); | |
return v0; | |
}; |
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
function init(module) { | |
let result; | |
const imports = {}; | |
if (module instanceof URL || typeof module === 'string' || module instanceof Request) { | |
const response = fetch(module); | |
if (typeof WebAssembly.instantiateStreaming === 'function') { | |
result = WebAssembly.instantiateStreaming(response, imports) | |
.catch(e => { | |
console.warn("`WebAssembly.instantiateStreaming` failed. Assuming this is because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); |
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
extern crate wasm_bindgen; | |
use wasm_bindgen::prelude::*; | |
use image; | |
use rqrr; | |
#[wasm_bindgen] | |
pub fn decode_qr(bytes: &[u8]) -> String { | |
let img = match image::load_from_memory(&bytes) { | |
Ok(v) => v, |
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
[package] | |
name = "qr-rust" | |
version = "0.1.0" | |
authors = ["Jacky Efendi <jacky.efendi1@gmail.com>"] | |
edition = "2018" | |
[lib] | |
crate-type = ["cdylib"] | |
[dependencies] |
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
!(function(e) { | |
function t(t) { | |
for (var n, l, i = t[0], a = t[1], f = t[2], d = 0, p = []; d < i.length; d++) | |
(l = i[d]), u[l] && p.push(u[l][0]), (u[l] = 0); | |
for (n in a) Object.prototype.hasOwnProperty.call(a, n) && (e[n] = a[n]); | |
for (c && c(t); p.length; ) p.shift()(); | |
return o.push.apply(o, f || []), r(); | |
} | |
function r() { | |
for (var e, t = 0; t < o.length; t++) { |
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
!(function(e) { | |
function t(t) { | |
for (var r, a, c = t[0], l = t[1], i = t[2], s = 0, p = []; s < c.length; s++) | |
(a = c[s]), o[a] && p.push(o[a][0]), (o[a] = 0); | |
for (r in l) Object.prototype.hasOwnProperty.call(l, r) && (e[r] = l[r]); | |
for (f && f(t); p.length; ) p.shift()(); | |
return u.push.apply(u, i || []), n(); | |
} | |
function n() { | |
for (var e, t = 0; t < u.length; t++) { |
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
import React, { useState, useEffect } from 'react'; | |
import ReactDOM from 'react-dom'; | |
const usePerformance = initialTimestamp => { | |
const [timings, updateTimings] = useState([]); | |
let prev = initialTimestamp; | |
useEffect(() => { | |
const newTimestamp = new Date().getTime(); |