View Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
import androidx.appcompat.app.AppCompatActivity |
View JsonInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.juggler.myapplication | |
import org.json.JSONArray | |
import org.json.JSONObject | |
import org.junit.Assert.assertEquals | |
import org.junit.Test | |
class JsonInstrumentedTest { | |
@Test |
View activity_main.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context=".MainActivity"> | |
<!-- ImageButton はデフォルトの背景(とパディング) があるが、この例はパディングを上書きする --> |
View gist:cbda451135d2b5c9b69f7ac4599f9833
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package jp.juggler.subwaytooter | |
import org.junit.Assert.assertEquals | |
import org.junit.Test | |
class TestArrayListSort { | |
@Test | |
fun testArrayListSize() { | |
val list = ArrayList(arrayOf("c", "b", "a").toList()) |
View ViewModelProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ViewModelのfactoryを毎回書くのが面倒 | |
fun <T : ViewModel> viewModelFactory(creator: () -> T) = | |
object : ViewModelProvider.NewInstanceFactory() { | |
@Suppress("UNCHECKED_CAST") | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
val viewModel = creator() | |
if (!modelClass.isAssignableFrom(viewModel::class.java)) { | |
error("unexpected modelClass. ${modelClass.simpleName}") | |
} | |
return viewModel as T |
View mapNotNullToIterable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = source.next() ?: continue |
View collectToChannel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(u,asin,m){asin=(m=u.match(/gp\/product(?:-details)?\/([^\/\?]+)/))?m[1]:(m=u.match(/dp(?:\/product-details)?\/([^\/\?]+)/))?m[1]:null;if(asin)location.href=('https://www.amazon.co.jp/dp/'+asin+'/')})(location.href);void(0); |
View removePurgedDelivery.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
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"; |
View recordHls.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -- | |
# usage: perl recordHls.pl (room_url) | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use JSON::XS; | |
use File::Path; | |
use MIME::Base64; |
NewerOlder