Skip to content

Instantly share code, notes, and snippets.

@alkhe
alkhe / README.md
Last active August 29, 2015 14:19
SymbiosisMixin is a mixin for React components that have a strong relationship with their respective Flux stores (Alt).

Usage

React.createClass({
	mixins: [Symbiosis(Store)],
	render() {
		...
	}
});
@alkhe
alkhe / webpack.config.js
Created May 2, 2015 18:31
Vendor Webpack Config
var path = require('path'),
w = require('webpack');
module.exports = {
entry: {
app: path.resolve(__dirname, 'client/js/index.js'),
vendors: ['react', 'socket.io', 'react-router', 'alt']
},
output: {
path: path.resolve(__dirname, 'public/js'),
@alkhe
alkhe / port.json
Last active August 29, 2015 14:22
Kancolle API /kcsapi/api_port/port
svdata = {
"api_result": 1,
"api_result_msg": "\u6210\u529f",
"api_data": {
"api_material": [{
"api_member_id": 15139027,
"api_id": 1,
"api_value": 1000
}, {
"api_member_id": 15139027,
@alkhe
alkhe / example.js
Created June 19, 2015 04:54
Five-Minute Promise Implementation
let a = new Prom((reject, resolve) => {
setTimeout(() => resolve('Promise A'), 1000);
}).then(result => {
console.log(result);
});
let b = new Prom((reject, resolve) => {
resolve('Promise B');
}).then(result => {
console.log(result);
@alkhe
alkhe / sort.js
Last active August 29, 2015 14:24
Short script to sort du -h output by size.
let sizemap = {
'': 0,
K: 1,
M: 2,
G: 3
};
let data = '`du -h --maxdepth 1` output';
let files = data
@alkhe
alkhe / index.js
Last active August 29, 2015 14:24
fluxette
import React from 'react';
import Store from './store';
import { deriveState, normalizeArray, callAll, callAllObj, listenerKey } from './util';
export { Store };
export default class {
constructor(stores = {}) {
// Top-level Stores
this.stores = stores;
// Dispatcher
@alkhe
alkhe / curry.js
Created July 20, 2015 23:37
Simple function currying.
let curry = fn => {
let total = fn.length;
let len = 0;
let argarr = [];
let recur = (...args) => {
len += args.length;
argarr = argarr.concat(args);
return len >= total ? fn(...argarr) : recur;
}
return recur;
@alkhe
alkhe / methods.js
Created August 26, 2015 23:26
Reflect all prototype-inherited instance methods. (ES6 classes)
let writeMethods = (o, arr) => {
// skip constructor
for (let i = 1; i < arr.length; i++) {
o[arr[i]] = 0;
}
};
// Get object mirroring all instance methods of Class
export let methods = Class => {
@alkhe
alkhe / index.js
Last active September 4, 2015 03:45
fluxette data dependencies
let fork = function(sideEffect) {
this.then(sideEffect);
return this;
}
let mangaIndexUrl = 'https://www.mangaeden.com/api/list/0';
let findManga = (index, id) =>
index.find(manga => manga.id === id);
@alkhe
alkhe / pi.js
Last active December 9, 2015 16:25
calculate pi with arctan series
let summation = (start, end, a) => {
let sum = 0;
for (let n = start; n <= end; n++) sum += a(n);
return sum;
}
console.log(4 * summation(0, 100000000, n => (n & 1 === 1 ? -1 : 1) / (2 * n + 1))); // 3.141592663589326