Skip to content

Instantly share code, notes, and snippets.

@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)
})
@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>
}
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 / 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) {
@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);