Skip to content

Instantly share code, notes, and snippets.

View d6u's full-sized avatar

Daiwei Lu d6u

View GitHub Profile
import { ObserveObjectPath, Keypath } from 'observe-object-path';
import { Observable, CompositeDisposable } from 'rx';
import React, { Component, ComponentClass } from 'react';
import store from '../store.ts';
type KeypathMap = { [key: string]: Keypath };
type ObservableMap = { [key: string]: Observable<any> };
const oop = new ObserveObjectPath(store.getState());
# Get browserstack supported browsers
curl -u "<username>:<automate-key>" https://api.browserstack.com/4/browsers.json
# Open a new Chrome window with a specific user profile
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --profile-directory='Profile 4'
var someProps = {
propA: {
id: 123,
},
// propB: {}, no available now
};
<ObjectExplore explore={someProps}>
<Path lookFor='propA' renderComponent={ComponentA} /> // ComponentA will have access to {id: 123} when instantiated
<Path lookFor='propB' renderComponent={ComponentB} /> // Won't get rendered since 'propB' is not available
@d6u
d6u / apply-classname-with-higher-order-component.js
Created December 22, 2015 21:53
Apply className with Higher Order Component
import { Component } from 'React';
class MyComponent extends Component {
render() {
return (
<div className='container'><div className='box'>the box</div></div>
);
}
}
@d6u
d6u / loop.js
Last active November 18, 2015 18:22
var funcA = Bluebird.coroutine(function *() {
while (true) {
yield someFunction();
}
});
import UIKit
import Async
import RxSwift
class Store {
func get(river: River)(param: Double) -> Observable<Int64> {
let s1 = interval(param, MainScheduler.sharedInstance)
return merge(returnElements(s1, river.action)) >- debug("debug")
}
}
copy(
Array.prototype.slice.call(
$('.repo-list-name')
.map(function (i, el) {
return '- [' +el.children[0].textContent.trim() + '](' +
el.children[0].href + ') - ' +
el.nextElementSibling.textContent.trim();
}),
0)
.join('\n')
@d6u
d6u / cachePrevious.swift
Last active August 29, 2015 14:26
Custom RxSwift operators
func cachePrevious<E>(source: Observable<E>) -> Observable<(E?, E)> {
var previous: E?
return source >- map {
let pre = previous
previous = $0
return (pre, $0)
}
}