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 / 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
@pinyin
pinyin / gist:c90e17a11a11b34725ac
Last active August 29, 2015 14:17
Add OrientDB Java Hook in JRuby
[20] pry(main)> d = com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.new 'plocal:db/pacer'
=> #<Java::ComOrientechnologiesOrientCoreDbDocument::ODatabaseDocumentTx:0x6dccc34c>
[21] pry(main)> d.registerHook H.new
=> #<Java::ComOrientechnologiesOrientCoreDbDocument::ODatabaseDocumentTx:0x6dccc34c>
[22] pry(main)> dd = d.open 'admin', 'admin'
=> #<Java::ComOrientechnologiesOrientCoreDbDocument::ODatabaseDocumentTx:0x6dccc34c>
[23] pry(main)> g = com.tinkerpop.blueprints.impls.orient.OrientGraph.new dd
=> #<Java::ComTinkerpopBlueprintsImplsOrient::OrientGraph:0x1d6ed6d9>
[24] pry(main)> gg = Pacer.orient g
=> #<PacerGraph orientgraph[plocal:db/pacer]