Skip to content

Instantly share code, notes, and snippets.

package jp.juggler.myapplication
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Test
class JsonInstrumentedTest {
@Test
<?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 はデフォルトの背景(とパディング) があるが、この例はパディングを上書きする -->
@tateisu
tateisu / gist:cbda451135d2b5c9b69f7ac4599f9833
Last active October 27, 2021 22:38
can't invoke `size` on some class that derived from ArrayList
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())
// 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
const util = require('util')
const crypto = require('crypto')
function decodeBase64(src){
return new Buffer(src,'base64')
}
// https://developers.google.com/web/updates/2016/03/web-push-encryption
//
@tateisu
tateisu / mapNotNullToIterable.kt
Created December 5, 2020 20:02
mapNotNullToIterable
// 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
// 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")
}
}
}
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);
@tateisu
tateisu / gist:026dfb95a029484aed07d149743a6a63
Last active May 28, 2020 05:38
docker環境でのpostgreSQL 9.6 => 11 へのアップグレード
# docker環境でのpostgreSQL 9.6 => 11 へのアップグレード
# https://github.com/tianon/docker-postgres-upgrade を利用する
# リポジトリに (OLD)-to-(NEW) のフォルダがあるか事前に確認しておく
# (今回の場合は 9.6-to-11 )
#################################
# 作業フォルダの作成
mkdir postgres-upgrade-2 && cd postgres-upgrade-2
mkdir -p postgresql/9.6/data postgresql/11/data
@tateisu
tateisu / removePurgedDelivery.pl
Created May 26, 2020 15:04
remove deliveries to purged domain.
#!/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";