Skip to content

Instantly share code, notes, and snippets.

View preco21's full-sized avatar
☂️
Recovering

Preco Kim preco21

☂️
Recovering
View GitHub Profile
@preco21
preco21 / concat.array.buffers.js
Last active September 7, 2015 14:30 — forked from 72lions/concat.array.buffers.js
Concatenates two ArrayBuffers
/**
* Creates a new Uint8Array based on two different ArrayBuffers
*
* @private
* @param {ArrayBuffers} buffer1 The first buffer.
* @param {ArrayBuffers} buffer2 The second buffer.
* @return {ArrayBuffers} The new ArrayBuffer created out of the two.
*/
var _appendBuffer = function(buffer1, buffer2) {
var tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength);
@preco21
preco21 / InlineWorker.js
Last active May 25, 2016 01:03
Simple InlineWorker
import Promise from 'bluebird';
import EventEmitter from 'eventemitter3';
class InlineWorker {
constructor(source) {
if (typeof source != 'function') {
throw new TypeError('source must be a function');
}
if (this._worker) {
@preco21
preco21 / obj-key-values.js
Created May 25, 2016 01:38
Iterate over object key values
// ES2015
for (const key of Object.keys(obj)) {
console.log(key); // key
console.log(obj[key]); // value
}
// ES2016
for (const value of Object.vaules(obj)) {
console.log(value); // value
}
@preco21
preco21 / FPSCounter.js
Last active June 8, 2016 02:33
A simple fps counter
import getTimeMethod from './getTimeMethod';
class FPSCounter {
constructor() {
this._getTime = getTimeMethod();
this._fps = 0;
this._prevTime = 0;
this._frames = 0;
this.startTick();
@preco21
preco21 / .gitignore
Last active June 8, 2016 02:42
Git dotfile templates for BabelJS environment
.DS_Store
node_modules
npm-debug.log
/bin
@preco21
preco21 / encode-non-bmp.js
Last active July 4, 2016 08:08
Encode a non-bmp string into HTML entities with ES2015 powered
// encode
'foo © bar ≠ baz 𝌆 qux'.replace(/[\u{00A0}-\u{10FFFF}<>\&]/gmiu, (char) => `&#x${char.codePointAt(0).toString(16)};`);
@preco21
preco21 / benchmark-copy-array.js
Last active August 5, 2016 03:22
Benchmark various methods to copy array in ES2015
import {Suite} from 'benchmark';
const suite = new Suite();
suite
.add('Array Spread Operator', () => {
const a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
const b = [...a];
})
.add('Array.from()', () => {
@preco21
preco21 / getYearDays.js
Last active August 5, 2016 03:39
Get leap year days
function getYearDays(year) {
const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
return isLeapYear ? 366 : 365;
}
export {
getYearDays as default,
};
@preco21
preco21 / calcMargin.js
Last active August 21, 2017 08:31
A simple `calcMargin()`
export default function calcMargin(obj = {}) {
if (Number.isInteger(obj)) {
return {
top: obj,
right: obj,
bottom: obj,
left: obj,
};
}
@preco21
preco21 / aqua.alfredappearance
Last active May 23, 2018 05:20
Aqua theme with pastel and blue cocktail
{
"alfredtheme" : {
"result" : {
"textSpacing" : 5,
"subtext" : {
"size" : 12,
"colorSelected" : "#F5F5F5CC",
"font" : "System",
"color" : "#F5F5F566"
},