Skip to content

Instantly share code, notes, and snippets.

tateisu / Test.kt
Created Aug 5, 2022
Bundle.getParcelableCompat と View.onRestoreInstanceState の組み合わせを試す
View Test.kt
package jp.juggler.testparcelablecompat
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
import android.view.View
import android.view.ViewGroup
View JsonInstrumentedTest.kt
package jp.juggler.myapplication
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Test
class JsonInstrumentedTest {
View activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
<!-- ImageButton はデフォルトの背景(とパディング) があるが、この例はパディングを上書きする -->
tateisu / gist:cbda451135d2b5c9b69f7ac4599f9833
Last active Oct 27, 2021
can't invoke `size` on some class that derived from ArrayList
View gist:cbda451135d2b5c9b69f7ac4599f9833
package jp.juggler.subwaytooter
import org.junit.Assert.assertEquals
import org.junit.Test
class TestArrayListSort {
fun testArrayListSize() {
val list = ArrayList(arrayOf("c", "b", "a").toList())
View ViewModelProvider.kt
// ViewModelのfactoryを毎回書くのが面倒
fun <T : ViewModel> viewModelFactory(creator: () -> T) =
object : ViewModelProvider.NewInstanceFactory() {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val viewModel = creator()
if (!modelClass.isAssignableFrom( {
error("unexpected modelClass. ${modelClass.simpleName}")
return viewModel as T
View mapNotNullToIterable.kt
// variations of filterNotNull that returns Iterable.
// it proxies iteration to avoid cost of create/update a list.
fun <T> Iterable<T?>.filterNotNullToIterable() =
object : Iterable<T> {
override fun iterator() = object : Iterator<T> {
val source = this@filterNotNullToIterable.iterator()
var item: T? = null
private fun read() {
while (source.hasNext()) {
item = ?: continue
View collectToChannel
// parser with recursive call
suspend fun simpleParser(ch: Channel<Char>, nest: Int=0 ) {
while (true) {
when (val a = ch.receiveOrNull()) {
null, ']' -> break
'[' -> simpleParser(ch, nest + 1 )
else -> println("$nest $a")
View gist:4f554f5bab049ec8a488fa66bb1ee372
tateisu /
Created May 26, 2020
remove deliveries to purged domain.
use strict;
use warnings;
use JSON::XS;
use Data::Dump qw(dump);
use DBI;
use Redis;
my $r = `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mastodon1_db_backend_1`;
$r =~ /(\S+)/ or die "can't find db address. $r\n";
tateisu /
Created May 18, 2020
#!/usr/bin/perl --
# usage: perl (room_url)
use strict;
use warnings;
use LWP::UserAgent;
use JSON::XS;
use File::Path;
use MIME::Base64;