Skip to content

Instantly share code, notes, and snippets.

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

Yasutaka Kawamoto kwmt

🏠
Working from home
View GitHub Profile
fun main() {
val list = 0..<20
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/windowed.html
println(list.windowed(4,4))
// [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19]]
}
@kwmt
kwmt / connpass.kt
Created January 6, 2024 10:12
connpassからイベントに参加したリストを取得する
import org.json.JSONObject
import java.net.HttpURLConnection
import java.net.URL
import java.text.SimpleDateFormat
import java.util.*
fun main() {
fetchConnpassEventList().sortedBy { it.startedAt }.forEach {
val output = "${it.startedAt.format()}\t=HYPERLINK(\"${it.eventUrl}\",\"${it.title}\")"
println(output)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.apps.gddquiz"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application
android:icon="@drawable/icon"
android:label="@string/app_name">
// import は省略
public class MainActivity extends Activity {
TextView mTextView;
Button mButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mTextView = (TextView) findViewById(R.id.hello);
package com.google.android.apps.gddquiz;
interface IQuizService {
String getCode();
}
@kwmt
kwmt / QrHistoryScreen.kt
Last active May 15, 2021 04:18
Jetpack Compose 1.0.0-beta04 SearchBar Sample
@ExperimentalComposeUiApi
@Composable
fun QrHistoryScreen(
viewModel: QrHistoryViewModel,
) {
val list by viewModel.qrHistoryFlow.collectAsState()
val query by viewModel.query.collectAsState()
viewModel.onLoad()
@kwmt
kwmt / callbackFlow.kt
Last active December 15, 2023 03:41
callbackFlow example
package coroutine.flow
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.sendBlocking
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collect
@ExperimentalCoroutinesApi
@kwmt
kwmt / get-versionName-from-aab.sh
Created December 7, 2020 01:57
AndroidのaabファイルからversionNameを取得する
#!/bin/bash
set -ex
aapt2=`$ANDROID_HOME/build-tools/30.0.2/aapt2`
# aabからversionNameを得る
# https://www.nuomiphp.com/eplan/ja/5f10e6a5ac168365ea739083.html
#unzip -p app/build/outputs/bundle/release/app-release.aab base/manifest/AndroidManifest.xml > AndroidManifest.xml
unzip -p app/build/outputs/bundle/debug/app-debug.aab base/manifest/AndroidManifest.xml > AndroidManifest.xml
zip proto_version.apk AndroidManifest.xml
@kwmt
kwmt / rotate_rect.kt
Created July 27, 2020 06:22
android.graphic.Rectを回転させるサンプル
private fun Rect.rotateRect(degree:Float): Rect {
val rectF = this.toRectF()
val matrix = Matrix()
matrix.setRotate(degree, rectF.centerX(), rectF.centerY())
matrix.mapRect(rectF)
return rectF.toRect()
}
// kotlin 1.3.31
// MyClass.java
package inline;
import kotlin.Metadata;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@Metadata(