Skip to content

Instantly share code, notes, and snippets.

@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 / 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]
@pinyin
pinyin / intention.coffee
Last active August 29, 2015 14:14
intention.coffee
# WIP
# License: Mozilla Public License, version 2.0
xhr = require 'xhr'
stringify = require 'json-stable-stringify'
status_codes = require './status_codes.coffee'
# TODO do we need GC ?
@pinyin
pinyin / initial.cjsx
Created January 14, 2015 13:50
React component port for the initial js module https://github.com/judesfernando/initial.js. Create Gmail-alike text avatars
React = require 'react'
module.exports = React.createClass
render: ->
colors = ["#1abc9c", "#16a085", "#f1c40f", "#f39c12", "#2ecc71", "#27ae60",
"#e67e22", "#d35400", "#3498db", "#2980b9", "#e74c3c", "#c0392b", "#9b59b6",
"#8e44ad", "#bdc3c7", "#34495e", "#2c3e50", "#95a5a6", "#7f8c8d", "#ec87bf",
"#d870ad", "#f69785", "#9ba37e", "#b49255", "#b49255", "#a94136"]
size = @props.size