Skip to content

Instantly share code, notes, and snippets.

View andrei-cacio's full-sized avatar
👀
🤔 👀

Andrei Cacio andrei-cacio

👀
🤔 👀
View GitHub Profile
import React, { Component } from 'React';
import PropTypes from 'prop-types';
class ClickOutside extends Component {
static propTypes = {
onClick: PropTypes.func
}
constructor(props) {
super(props);
import React, { Component } from 'React';
import PropTypes from 'prop-types';
class ClickOutside extends Component {
static propTypes = {
onClick: PropTypes.func
}
constructor(props) {
super(props);
@andrei-cacio
andrei-cacio / clickoutside.jsx
Created March 2, 2019 08:37
ClickOutside structure
import React, { Component } from 'react';
class ClickOutside extends Component {
handleClick = e => {
console.log('clicking everywhere!');
};
componentDidMount() {
document.addEventListener("click", this.handleClick);
}
@andrei-cacio
andrei-cacio / clickoutside.jsx
Created March 2, 2019 08:37
ClickOutside structure
import React, { Component } from 'react';
class ClickOutside extends Component {
handleClick = e => {
console.log('clicking everywhere!');
};
componentDidMount() {
document.addEventListener("click", this.handleClick);
}
<ClickOutside onClick=() => 'Close tooltip'>
<span>
A helpful tooltip!
</span>
</ClickOutside>
@andrei-cacio
andrei-cacio / wasm2.js
Created November 24, 2018 10:02
wasm2
import * as fuzzySearch from "fuzzy-search";
import books from './books-db';
import lorem from './lorem';
const loremOpts = {
isHardcore: false
};
renderLorem();
renderBooks(books);
@andrei-cacio
andrei-cacio / wasm1.rs
Created November 24, 2018 10:01
wasm1
extern crate cfg_if;
extern crate wasm_bindgen;
extern crate regex;
#[macro_use]
extern crate serde_derive;
use wasm_bindgen::prelude::*;
use regex::Regex;
#[wasm_bindgen]
@andrei-cacio
andrei-cacio / args.js
Created July 14, 2018 08:17
Sum of args refactored with map, filter and reduce
process.argv
.filter(function(item){ return !Number.isNaN(Number(item)); })
.map(function(item){ return Number(item); })
.reduce(function(acc, item){ return acc + item }, 0);
fetch('memory-access.gc.wasm')
.then(r => r.arrayBuffer())
.then(arrayBuff => WebAssembly.instantiate(arrBuff, {}))
.then(rustWasm => {
const vecLocation = wasmRust.instance.exports.simple_arr();
const vecTyped = new Uint32Array(wasmRust.instance.exports.memory.buffer, vecLocation, 4);
const simpleVec = [...vecTyped]
console.log(simpleVec)
// [ 100, 200, 300, 400 ]
$ rustc +nightly --target wasm32-unknown-unknown -O vector.rs
$ wasm-gc vector.wasm vector.wasm
$ python -m SimpleHTTPServer # Power up an inline HTTP server on port 80