Skip to content

Instantly share code, notes, and snippets.

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

Andrei Cacio andrei-cacio

👀
🤔 👀
View GitHub Profile
@andrei-cacio
andrei-cacio / wwl.js
Last active January 13, 2017 11:40
What will log? Part I
var people = (function() {
var people = [];
render();
function render() {
var people = people;
console.log(people);
}
}())
@andrei-cacio
andrei-cacio / wwl2.js
Created January 13, 2017 14:16
What will log? Part II
console.log(1..toString());
@andrei-cacio
andrei-cacio / fetch-with-cookies.js
Last active December 30, 2017 17:38
Fetch credentials example
fetch('/api/v1/logout', {
credentials: 'same-origin'
});
@andrei-cacio
andrei-cacio / fetch-request-cookies.js
Last active December 30, 2017 17:39
Fetch with cookies sample
const someRequest = new Request('/api/v1/logout');
someRequest.credentials = 'same-origin';
fetch(someRequest)
.then(response => console.log(response));
import eventEmiter, { EVENTS } from './core/bus';
eventEmitter.on(EVENTS.AUTH.SUCCESS, () => {});
eventEmitter.on(EVENTS.AUTH.FAILED, () => {});
eventEmitter.trigger(EVENTS.AUTH.ATTEMPT, { user, pass });
import EventEmitter2 from 'eventemitter2';
const appBus = new eventEmitter();
const EVENTS = {
AUTH: {
SUCCESS: 'AUTH.SUCCESS',
FAILED: 'AUTH.FAILED',
ATTEMPT: 'AUTH.ATTEMPT',
};
import eventEmiter, { EVENTS } from './core/bus';
function authenticate(user, password) {
return new Promise((resolve, reject) => {
eventEmitter.on(EVENTS.AUTH.SUCCESS, resolve);
eventEmitter.on(EVENTS.AUTH.FAILED, reject);
eventEmitter.trigger(EVENTS.AUTH.ATTEMPT, { user, pass });
});
}
import eventEmiter, { EVENTS } from './core/bus';
function authenticate(user, password) {
return new Promise((resolve, reject) => {
eventEmitter.once(EVENTS.AUTH.SUCCESS, resolve);
eventEmitter.once(EVENTS.AUTH.FAILED, reject);
eventEmitter.trigger(EVENTS.AUTH.ATTEMPT, { user, pass });
});
}
@andrei-cacio
andrei-cacio / distil.js
Created May 16, 2018 14:28
The desired output of distil-wasm
async function distil(imgPath, nrOfPalettes = 2) {
const wasmModule = await compile('distil.wasm');
const { imgBufferLocation, length } = await readImgIntoMemory(imgPath);
const paletteBuffer = wasmModule.exports.distil(imgBufferLocation, length);
console.log(bufferToHex(paletteBuffer, nrOfPalettes));
}
// -> ['#ff1122', '#jjkkll']
@andrei-cacio
andrei-cacio / rust-wasm.sh
Created May 17, 2018 11:11
Rust + Wasm setup
rustup default nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
cargo install wasm-gc