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
data class Person(val age:Int, val name:String) {
val greet
get() = "年齢は${age}です"
fun testPrint() {
println("testPrint ${age}" )
}
}
@kwmt
kwmt / isContinueReduce.kt
Created October 15, 2019 05:28
条件にあてはあまるところで止める
var isContinue:Boolean = true
val list = arrayOf("hello", "good", "text", "hello2", "text2")
val result = list.asSequence().takeWhile{isContinue}.reduce {s1, s2->
if(s1.length == 4 && s2.length == 4) {
isContinue = false
return@reduce s1+s2
}
s2
}
val amari = 8.rem(3)
println(amari)
// Output
// 2
@kwmt
kwmt / ascii.kt
Last active October 15, 2019 05:22
val num = 'a'.toValue()
println(num)
// Output
// 42
private fun Char.toValue() : Int{
// 仕様: https://www.icao.int/publications/Documents/9303_p3_cons_en.pdf の 20ページの最後から21ページの最初
val num = this.toInt() - '0'.toInt()
if(num < 10) {
File().outputStream().use { out ->
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, out)
out.flush()
}
@kwmt
kwmt / how-to-remove-back-button-of-toolbar-with-navigation-component.kt
Last active April 5, 2021 00:40
How to remove the back button of Toolbar with Navigation Architecture Component
val appBarConfiguration = AppBarConfiguration(setOf(R.id.titleScreen, R.id.aboutScreen))
setupActionBarWithNavController(navController, appBarConfiguration)
@kwmt
kwmt / AppDelegate.swift
Created October 5, 2019 17:13
how to googlemaps view on swiftui
import UIKit
import GoogleMaps
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// https://developers.google.com/maps/documentation/ios-sdk/get-api-key#add_key
GMSServices.provideAPIKey("YOUR_API_KEY")
return true
}
@kwmt
kwmt / deleteDuplicates.kt
Created October 4, 2019 15:48
delete duplicate objects of list / 重複したリストのオブジェクトを削除したい
data class User(val name : String, val latLng: LatLng)
data class LatLng(val lat: Int, val lng: Int)
fun deleteDuplicates() {
// create data
val results = (1..10).map {User("$it", LatLng(it % 4, it%4))}
results.forEach {
println(it)
}
enum FromNagative: Int {
case a = -1
case b
case c
}
print(FromNagative.a.rawValue) // -1
print(FromNagative.b.rawValue) // 0
print(FromNagative.c.rawValue) // 1
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let url = URL(string: "https://jsonplaceholder.typicode.com/posts/1")!
func fetch(callback:( (String) -> Void)? = nil) {
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
guard error == nil else {
callback?(error?.localizedDescription ?? "エラーです")