Skip to content

Instantly share code, notes, and snippets.

View ovangle's full-sized avatar

Thomas Stephenson ovangle

  • Mebourne, Australia
View GitHub Profile
@ovangle
ovangle / app.state.ts
Last active July 21, 2017 09:13
Modularised application state
import {Set, Map} from 'immutable';
import {Action, Reducer} from "@ngrx/store";
import {Type} from "@angular/core";
type TypeToken = Type<any>;
export interface StatefulModule<T> {
ngModule: Type<T>;
reducer<TState>(state: TState, action: Action<any>): TState;
@ovangle
ovangle / @ngrx-effects.ts
Last active August 31, 2017 04:06
Generic `Action` type in @ngrx/store
/**
* The Actions observable can now be typechecked.
*/
export class Actions<T> extends Observable<Action<T>> {
constructor(@Inject(Dispatcher) source: Observable<Action<T>>) {
super();
this.source = source;
}
@Component({
selector: 'map-options-form'
template: `
<input type="number" [ngModel]="options.zoom" (ngModelChange)="valueChanged({zoom: $event})">
<latlng-input [ngModel]="options.position" (ngModelChange)="valueChanged({position: $event})">
</latlng-input>
<button type="submit" (click)="commit.emit(this.options)">
`
service UserService {
rpc createUser(CreateUserRequest) returns CreateUserResponse;
rpc queryUser(QueryUserRequest) returns QueryUserResponse;
rpc deleteUser(DeleteUserRequest) returns DeleteUserResponse;
}
message User {
optional String username = 1;
@ovangle
ovangle / alt_groupby.dart
Created January 23, 2014 15:12
An alternate implementation of groupby using a multimap which delegates to the iterable
library alt_groupby;
import 'package:quiver/collections.dart';
Multimap groupBy(Iterable iterable, {key(var element)}) =>
new _GroupMap(iterable, key);
typedef K _KeyFunc<K>(V value);
class _GroupMap<K,V> implements Multimap<K,V> {
@ovangle
ovangle / generator.dart
Last active January 4, 2016 05:18
generators for dart
class _BreakSentinel {
const _BreakSentinel();
}
const _BreakSentinel yieldBreak = const _BreakSentinel();
/**
* Create a lazy iterable from the results of the function `f`.
*
* Each time the generator is iterated, the function will be called
@ovangle
ovangle / sandbox.dart
Last active January 3, 2016 23:19
The following should be reproducible on the dart vm version `Dart VM version: 1.1.1 (Wed Jan 15 04:11:49 2014) on "linux_x64"` I'd expect the following to be printed after running the code: "abcd" "abcdefgh" "efghijkl" "ijklmnop" "mnopqrst" "qrstuvwx" "uvwx" But due to an optimisation in the stable version of the VM, which assumes that `startPos…
Iterable<String> overlappingChunks(String str, Iterable<int> chunks) {
Iterable<int> runes = str.runes;
int startPos = 0;
Iterable<int> overlap;
StringBuffer sbuf = new StringBuffer();
String nextChunk(int endPos) {
sbuf.clear();
if (startPos != 0) {
overlap.forEach(sbuf.writeCharCode);
@ovangle
ovangle / itertools.dart
Created January 9, 2014 00:55
A generator library using continuations
/**
* Useful utility functions for dealing with iterators, which have not been exposed
* via the `'dart:collection`' interface.
*/
library itertools;
import 'lazy.dart';
//An id function
@ovangle
ovangle / sandbox.css
Created December 16, 2013 04:06
Demonstration of why Element.classes.add should return a future or block until completion. Instructions: Load the following into an editor and load it. If 'ctrl' is held while clicking the text, the text will rotate from a 90deg rotated position back to the original position through a 250ms css transition. If 'ctrl' is not held, then: * If a bre…
.transformable {
font-size: 24pt;
text-align: center;
margin-top: 140px;
display:block;
}
.sample_text_rotated {
-webkit-transform: rotate(90deg);
}