Skip to content

Instantly share code, notes, and snippets.

View yongjhih's full-sized avatar
🏠
Working from home

Andrew Chen yongjhih

🏠
Working from home
View GitHub Profile
@chartsai
chartsai / gist:d359faf8ab065b4d7b291ce2d59e15c8
Created April 6, 2018 20:43
sealed doesn't work with reified QQ
package ninenine
sealed class NineNine {
abstract fun print99(formatter: String)
}
class Table(internal val width: Int, internal val height: Int, private val sections: Int = if (width >= 6) 2 else 1) : NineNine() {
private val lists = IntRange(1, width).map { Sheet(it, height) }.toList()
override fun print99(formatter: String) {
@chartsai
chartsai / NineNine.kt
Last active April 6, 2018 23:13
OO NineNine
package ninenine
interface NineNine {
fun print99(formatter: String)
}
class Table(internal val width: Int, internal val height: Int, private val sections: Int = if (width >= 6) 2 else 1) : NineNine {
private val lists = IntRange(1, width).map { Sheet(it, height) }.toList()
override fun print99(formatter: String) {
@ilikerobots
ilikerobots / intl_locale_override.dart
Last active December 19, 2019 13:34
Example of overriding default locale for use with intl
import 'dart:async';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:intl_translate_example/l10n/messages_all.dart';
void main() => runApp(new MyApp());
class Translations {
static Future<Translations> load(Locale locale) {
@evxn
evxn / do-on-subscribe.rxjs.operator.ts
Last active March 5, 2021 17:26
rxjs on subscribe hook, callback on subscribe, doOnSubscribe operator, doOnSubscribe pipe, rxjs onSubscribe
import {defer} from 'rxjs/observable/defer';
import {Observable} from 'rxjs/Observable';
/** Example
import {from} from 'rxjs/observable/from';
from([1, 2, 3])
.pipe(doOnSubscribe(() => console.log('subscribed to stream')))
.subscribe(x => console.log(x), null, () => console.log('completed'));
*/
@slightfoot
slightfoot / main.dart
Last active September 11, 2024 11:38
Flutter Drop List Example with TextField
import 'package:flutter/material.dart';
void main()
{
final TextEditingController _controller = new TextEditingController();
var items = ['Working a lot harder', 'Being a lot smarter', 'Being a self-starter', 'Placed in charge of trading charter'];
runApp(
new MaterialApp(
title: 'Drop List Example',
home: new Scaffold(
import types
import typing
import ast
import inspect
class TypeViolationError(TypeError):
def __init__(self, variable_name, expected_type, actual_type):
super().__init__()
self.variable_name = variable_name
@Audhil
Audhil / AppExtensionFuncs.kt
Last active January 27, 2024 09:48
XML generation with Kotlin extension functions
// XML generation by code
// based on https://www.schibsted.pl/blog/back-end/readable-xml-kotlin-extensions/
fun XmlSerializer.document(docName: String = "UTF-8",
xmlStringWriter: StringWriter = StringWriter(),
init: XmlSerializer.() -> Unit): String {
startDocument(docName, true)
xmlStringWriter.buffer.setLength(0) // refreshing string writer due to reuse
setOutput(xmlStringWriter)
init()
endDocument()
@LouisCAD
LouisCAD / Lol.kt
Last active February 14, 2019 06:21 — forked from npryce/layout.kt
Kotlin layout hack, up to the right margin (100 chars)
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
@collinjackson
collinjackson / nested_scroll_view.dart
Last active September 25, 2022 05:29
nestedscrollview example
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() {
runApp(new TestApp());
}
import com.google.api.core.ApiFutures;
import com.google.firebase.tasks.Tasks;
String value = "value";
Exception error = new Exception("custom error");
// Wrap in Tasks
Task<String> valueTask = Tasks.forResult(value);
Task<String> exceptionTask = Tasks.forException(error);