Skip to content

Instantly share code, notes, and snippets.

@mocheng
mocheng / gist:ac1304e61380de22045105520e6007d6
Created Jun 13, 2017
Implement Redux Store with Rx.js
View gist:ac1304e61380de22045105520e6007d6
'use strict';
const Rx = require('rxjs');
const createStore = (reducer, initialState = {}) => {
const action$ = new Rx.Subject();
let currentState = initialState;
const store$ = action$.startWith(initialState).scan(reducer).do(
state => {
View gist:2b8e30ef03fb69f26f9a038e6199b71c
const Rx = require('../../');
const fs = require('fs');
const t = require('transducers-js');
const R = require('ramda');
const _ = require('lodash');
const mappingReducer = f => reducer => (result, input) => {
//console.log('enter mappingReducer', result, input);
return reducer(result, f(input));
};
View gist:39a10055509fd3e7b193f72b03b831dd
const Rx = require('../../');
const fs = require('fs');
const t = require('transducers-js');
const source = Rx.Observable.range(1, 10000);
const increment = x => x + 1;
const isEven = x => (x % 2 === 0);
const startTime = new Date();
const transducer = t.comp(t.map(increment), t.filter(isEven));
View gist:29af75aeca49b88b7ce866c83eb3c481
Array.prototype.flatMap = function(lambda) {
return [].concat.apply([], this.map(lambda));
};
const r = [1, 2, 3].flatMap(x => {
var arr = new Array(x);
for (var i=0; i<arr.length; ++i) {
arr[i] = x;
}
return arr;
@mocheng
mocheng / applicative
Created Sep 23, 2016
Applicative in JavaScript
View applicative
Array.prototype.ap = function(wrappedVals) {
var results = [];
this.map( (f)=> {
const mr = wrappedVals.map(f);
results = results.concat(mr);
});
return results;
}
@mocheng
mocheng / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View gist:aa87a28adfb00220f169
mkdir -p ~/Downloads
cd ~/Downloads
sudo yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
wget -O v1.8.1.2.tar.gz https://github.com/git/git/archive/v1.8.1.2.tar.gz
tar -xzvf ./v1.8.1.2.tar.gz
cd git-1.8.1.2/
@mocheng
mocheng / storm with publish
Last active Aug 29, 2015
storm mosca server
View storm with publish
var mqtt = require('mqtt');
var port = 1883;
var host = 'localhost';
var options = {
username: 'my_username',
password: 'my_password',
clientId: 'my_client_id'
};
var client = mqtt.createClient(port, host, options);
@mocheng
mocheng / dev.conf
Created Feb 16, 2012
Setup of dev/test/prod environment
View dev.conf
<VirtualHost *>
ServerName xxx.xxx.com
DocumentRoot "/var/www/html"
DirectoryIndex index.php
SetEnv XXX_ENV "development"
</VirtualHost>
@mocheng
mocheng / .htaccess
Created Feb 13, 2012
.htaccess for CodeIgniter
View .htaccess
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|img|style|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]