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
const {2: serializedGlob = "['**']", 3: command} = process.argv;
console.log(serializedGlob, command)
const {promisify} = require('util');
const exec = promisify(require('child_process').exec);
exec('git diff --name-only origin/master').then(({stdout}) => console.log(stdout))
var url = 'https://ronreiter-meme-generator.p.mashape.com/meme?meme=Baby+Godfather&font_size=50&font=Impact&top=Thanks+m&bottom=Later';
var headers = new Headers({'X-Mashape-Key': 'API_KEY'});
var options = {
method: 'GET',
headers: headers,
mode: 'cors',
cache: 'default'
};
var request = new Request(url);
import runWhen from 'run-when';
runWhen([
{
glob: ['app/components/index.js', 'app/__tests__/**'],
task(paths) {
console.log('This will be called!');
}
},
{
class ImgDimensions extends React.Component {
state = {width: 0, height: 0, errored: false};
constructor() {
this.onLoad = this.onLoad.bind(this);
this.onError = this.onError.bind(this);
}
onLoad({target: {height, width}}) {
this.setState({width, height});
@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;
}
}
@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');
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({