Skip to content

Instantly share code, notes, and snippets.

@zoechi
zoechi / index.html
Last active March 10, 2023 18:03
appendHtml doesn't validate HTML
<div id="div1"></div>
<br/>
<div id="div2"></div>
<br/>
<div id="div3"></div>
<br/>
<div id="div4"></div>
@zoechi
zoechi / main.dart
Created April 11, 2015 09:25
setter return type
import 'dart:async' show Future, Stream;
class SomeClass {
int _someValue;
void set someValue(int val) =>
new Future.delayed(new Duration(milliseconds: 500), () => _someValue = val);
Future set someValue(int val) =>
new Future.delayed(new Duration(milliseconds: 500), () => _someValue = val);
@zoechi
zoechi / main.dart
Last active August 29, 2015 14:18
SO 29567236 Enum as default value
// 29567236
class Status {
static const off = const Status._(0);
static const on = const Status._(1);
final int value;
const Status._(this.value);
}
doSomething1([Status status = Status.off]) {
@zoechi
zoechi / main.dart
Last active August 29, 2015 14:18
SO 29565067 Inverse map
// 29565067
Map f = {
0 : 0,
1 : 1,
2 : 0,
3 : 1,
4 : 0,
5 : 1
};
@zoechi
zoechi / main.dart
Last active August 29, 2015 14:18
SO 29320012 Do streams buffer
import 'dart:async';
Stream<int> a() async* {
for (int i = 1; i <= 10; ++i) {
print('yield $i');
yield i;
}
}
main() {
@zoechi
zoechi / main.dart
Created April 10, 2015 10:02
SO 29331079 yield from within a callback
import 'dart:async';
class SqlResultSet {
List rows;
SqlResultSet(this.rows);
}
Future _runInTxn(txn(Transaction x)) {
print('_runInTxn');
return new Future.value(txn(new Transaction()));
// SO 29334843
main() {
var a = new A()..doSomething();
print('`a:` $a');
var b = new B()..doSomething();
print('`b:` $b');
var c = new C()..doSomething();
print('`c:` $c');
}
// SO 29378453
import 'dart:async';
main() {
// fails
// main1();
main2();
main3();
}
// SO 29428637
import 'dart:html' as dom;
const url = 'https://gist.githubusercontent.com/zoechi/a5170ff293b861b3db6b/raw/cf1332926cf9feb9d7463750a66df75571e6ab89/main.dart';
main() async {
try {
final response = await dom.HttpRequest.getString(url);
print(response);
} catch(e) {
// SO 29538557
void main() {
List persons = [];
persons.add({'name': 'jhon', 'lastName': 'Doe'});
print('before: $persons');
persons.removeWhere((p) => p['name'] == 'jhon' && p['lastName'] == 'Doe');
print('after: $persons');
}