Skip to content

Instantly share code, notes, and snippets.

View pinyin's full-sized avatar
🎯
Focusing

Bao Bo pinyin

🎯
Focusing
View GitHub Profile
@pinyin
pinyin / ember_guides_combined
Created March 19, 2014 09:42
ember_guides_combined
# Guides and Tutorials
Welcome to the Ember.js guides! This documentation will take you from
total beginner to Ember expert. It is designed to start from the basics,
and slowly increase to more sophisticated concepts until you know
everything there is to know about building awesome web applications.
@pinyin
pinyin / main.dart
Created September 17, 2019 07:39
Get point position from Flutter's Path
Path p = Path();
p.addOval(Rect.fromPoints(Offset(0, 0), Offset(100, 100)));
final m = p.computeMetrics().first.getTangentForOffset(75 * pi);
print(m.position);
@pinyin
pinyin / callingNoSuchMethod.dart
Created August 16, 2019 07:26
Dart call & noSuchMethod
void main() {
final func = Callable((a)=> print(a));
func('a');
}
class Callable {
Function func;
@override
noSuchMethod(invocation) {
class NodeTree {
insert(node: Node): void {
if (this.has(node)) {
throw new UnexpectedStructure() // TODO
}
const getParent = (): Node | undefined => {
const filter: TravelFilter = candidate => candidate.contains(node) ? Travel.ACCEPT : Travel.REJECT
const ancestorPaths = this.DFS(document.body, filter)
@pinyin
pinyin / Component.tsx
Last active March 30, 2018 03:34
Tiny React Starter
import * as ReactDOM from 'react-dom'
import * as React from 'react'
export class Component extends React.Component {
render() {
return <div style={{cursor: 'pointer', userSelect: 'none'}}
onClick={()=> this.clicked()}>
This text is clicked {this.state.count} times.
</div>
}
@pinyin
pinyin / Maybe.spec.ts
Last active December 9, 2017 01:22
A Typescript Maybe implementation with Mocha and Chai tests
import {Maybe} from './Maybe'
describe('Maybe', ()=> {
const nothing = Maybe.Nothing
const just = Maybe.Just(1)
describe('Nothing', ()=> {
it('should not be exist', ()=> {
expect(nothing.exists).to.equal(false)
})
import * as React from 'react'
import {Observable} from 'rxjs/Observable'
import {Subject} from 'rxjs/Subject'
import {ISubscription} from 'rxjs/Subscription'
import {Observables} from '../rxjs/Observables'
import {Pipes} from '../rxjs/Pipes'
import {Subjects} from '../rxjs/Subjects'
import {EventHandlers} from '../utils/EventHandler'
export abstract class ReactiveReactComponent<Props, State, Events> extends React.Component<Props, State> {
@pinyin
pinyin / AbstractComponent.ts
Created December 6, 2016 05:28
Reactive React component with TypeScript
import * as React from 'react'
import {Subject, Observable, Scheduler} from 'rxjs'
import {ISubscription} from 'rxjs/Subscription'
import {createSubjects} from '../../../lib/rxjs-helpers/createSubjects'
import {Subjects} from '../../../lib/rxjs-helpers/Subjects'
import {Mapper} from "../../../lib/mapobject";
export abstract class AbstractComponent<Props, State, Interactions> extends React.Component<Props, State> implements React.ComponentLifecycle<Props, State> {
protected abstract readonly interactionFilters: InteractionFilters<Interactions>
protected abstract viewLogic(): ISubscription[]
@pinyin
pinyin / command.coffee
Last active August 29, 2015 14:17
micro-framework for reactive react with actors
# actions handlers are actors running in dedicated web workers
# send_event is their only way to return result
emit = (params...) -> this.postMessage params
handler = (func)->
this.onmessage = (e)->
try
func.apply this, e.data
finally
@pinyin
pinyin / router.coffee
Created March 18, 2015 23:51
Tiny router for html5 apps
class Route
init: (root)->
@root_url = root
window.addEventListener 'popstate', (=> @app.forceUpdate())
conflict: (conflict_sets)->
@conflict_sets = conflict_sets
resources: (resource_names)->
@resource_names = resource_names