This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::mem; | |
use std::slice; | |
pub struct Pool { | |
uncommited: usize, | |
ptr: *mut u8 | |
} | |
impl Pool { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pageSize = 10 | |
const getPage = page => { | |
const pageContent = _.range(0, pageSize).map(v => v + (page * pageSize)) | |
if(page == 9) { | |
return Rx.Observable.just({ | |
nextPage: null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const combineObject = config => { | |
const streams = _.values(config) | |
const keys = _.keys(config) | |
return Rx.Observable.combineLatest( | |
...streams, | |
(...values) => _.zip(values, keys).reduce((acc, [value, key]) => { | |
acc[key] = value | |
return acc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var toObservable = request => Rx.Observable.create(observer => { | |
var req = request.end((err, res) => { | |
if(err) { | |
observer.onError(err) | |
} else { | |
observer.onNext(res) | |
observer.onComplete() | |
} | |
}) | |
return Rx.Disposable.create(() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var groupTransform = (stream$, f, keySelector, selector) => { | |
return Rx.Observable.create(observer => { | |
var disposable = new Rx.CompositeDisposable() | |
disposable.add(stream$.groupBy(keySelector, selector) | |
.subscribe(groupObservable => { | |
disposable.add(f(groupObservable, groupObservable.key).subscribe(observer)) | |
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var initialData = [] | |
// These can be converted from other events | |
var add_ = new Rx.Subject() | |
var remove_ = new Rx.Subject() | |
var addF_ = add_.map(R.unary(R.curry(R.union))) | |
var removeF_ = remove_.map(R.unary(R.flip(R.difference))) | |
var update = (data, updateF) => updateF(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// is it a monad? | |
var x = 1, | |
fn = x => x + 1, | |
gn = x => x * 2 | |
var law1 = new Maybe(x).bind(fn).return() == new Maybe(fn(x)).return() | |
console.log(law1) | |
var law2 = new Maybe(x).bind(x => x).return() == new Maybe(x).return() | |
console.log(law2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function split(arr) { | |
var l = arr.length, | |
m = Math.round(l / 2); | |
return { | |
left: arr.slice(0, m), | |
right: arr.slice(m, l) | |
} | |
} | |
function find(arr, el) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Recursivelly find the first object with the given key | |
* @param {object} obj Object to search for key | |
* @param {string} key Key to find | |
* @return {object} Value if found, undefined if not found | |
*/ | |
findValueForKey: function(obj, key) { | |
var value = undefined; | |
function find(obj, key) { | |
for(var k in obj) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AED": { | |
"code": "AED", | |
"number": "784", | |
"symbol": "AED", | |
"decimals": "2" | |
}, | |
"AFN": { | |
"code": "AFN", | |
"number": "971", |
NewerOlder