Skip to content

Instantly share code, notes, and snippets.

View zzarcon's full-sized avatar
🦍
Generating legacy code

Hector Zarco zzarcon

🦍
Generating legacy code
View GitHub Profile
@zzarcon
zzarcon / foo.js
Created September 10, 2017 03:04
Bind call to class property
// FROM:
class Foo {
constructor() {
this.bar = this.bar.bind(this);
}
bar() {
return 1;
}
}
int fibonacci(int n) {
int a = 1;
int b = 1;
while (n-- > 1) {
int t = a;
a = b;
b += t;
}
function fiboJs(num){
var a = 1, b = 0, temp;
while (num >= 0){
temp = a;
a = a + b;
b = temp;
num--;
}
@zzarcon
zzarcon / loader.js
Created January 9, 2017 22:16
WebAssembly loader
module.exports = (filename) => {
return fetch(filename)
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.compile(buffer))
.then(module => {
const imports = {
env: {
memoryBase: 0,
tableBase: 0,
memory: new WebAssembly.Memory({
@zzarcon
zzarcon / benchmark.js
Last active January 10, 2017 23:50
Fibo benchmark
const Benchmark = require('benchmark');
const loadModule = require('./loader');
const {fiboJs, fiboJsRec, fiboJsMemo} = require('./fibo.js');
const suite = new Benchmark.Suite;
const numToFibo = 40;
window.Benchmark = Benchmark; //Benchmark.js uses the global object internally
console.info('Benchmark started');
(function($0) {var stack = Runtime.stackSave();var str = $0;var ret = 0;
if (str !== null && str !== undefined && str !== 0) { // null string
// at most 4 bytes per UTF-8 code point, +1 for the trailing '\0'
var len = (str.length << 2) + 1;
ret = Runtime.stackAlloc(len);
stringToUTF8(str, ret, len);
};$0=(ret);var ret = cfunc($0);if (typeof EmterpreterAsync === 'object') { assert(!EmterpreterAsync.state, 'cannot start async op with normal JS calling cwrap') }Runtime.stackRestore(stack);return ret})
cwrap = function cwrap(ident, returnType, argTypes) {
argTypes = argTypes || [];
var cfunc = getCFunc(ident);
// When the function takes numbers and returns a number, we can just return
// the original function
var numericArgs = argTypes.every(function(type){ return type === 'number'});
var numericRet = (returnType !== 'string');
if ( numericRet && numericArgs) {
return cfunc;
}
#include <string.h>
#include <stdint.h>
#include <limits.h>
#define ALIGN (sizeof(size_t))
#define ONES ((size_t)-1/UCHAR_MAX)
#define HIGHS (ONES * (UCHAR_MAX/2+1))
#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
size_t strlen(const char *s)
@zzarcon
zzarcon / foo.sh
Created January 7, 2017 16:50
webassembly paths
source /Users/zzarcon/emsdk_portable/emsdk_env.sh
export LLVM_ROOT=/Users/zzarcon/emsdk_portable/clang/fastcomp/build_incoming_64/bin
export NODE_JS=/Users/zzarcon/.nvm/versions/node/v7.4.0/bin/node
export EMSCRIPTEN_ROOT=/Users/zzarcon/emsdk_portable/emscripten/incoming
export EMSCRIPTEN_NATIVE_OPTIMIZER=/Users/zzarcon/emsdk_portable/emscripten/incoming_64bit_optimizer/optimizer
@zzarcon
zzarcon / index.jsx
Last active January 4, 2017 22:19
Webcomponent custom styles example
/** @jsx h */
/*
Component A passing custom styles to sk-tags
*/
import { Component, h } from 'skatejs';
class A extends Component {
renderCallback() {
const tagStyles = `