Skip to content

Instantly share code, notes, and snippets.

View tommykw's full-sized avatar
🌞

Kenji Tomita tommykw

🌞
View GitHub Profile
@amaembo
amaembo / Circle.java
Created July 19, 2021 09:28
Bresenham circle algorithm
public class Circle {
public static void main(String[] args) {
// Preparation
int radius = Integer.parseInt(args[0]);
int rasterSize = radius * 2 + 1;
boolean[][] raster = new boolean[rasterSize][rasterSize];
// Bresenham algorithm
int y = radius;
int err = radius;
@DevSrSouza
DevSrSouza / GtkTheme.kt
Created July 4, 2021 19:00
Compose for Desktop get and listen to Gtk Dark/Light Theme changes
// implementation("org.zeroturnaround:zt-exec:1.12") LIBRARY USAGED
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import kotlin.coroutines.resume
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
package com.handstandsam.mutablestateflow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runBlockingTest
import org.junit.Test
class UseImmutableDataWithMutableStateFlow {
data class SomePojo(var name: String = "placeholder")
@kazemihabib
kazemihabib / DrawLayerSolarSystem.kt
Last active January 10, 2024 14:06
Jetpack compose Solar system animation inside Interactive drawLayer based on https://gist.github.com/zach-klippenstein/e2c8e6edf0d950d8ba527cd0681c5b60
//image earth: https://media.prod.mdn.mozit.cloud/attachments/2012/07/09/1429/e2d55b8d5c9efd75a12112264d4ac091/Canvas_earth.png
//image sun: https://www.extremetech.com/wp-content/uploads/2020/01/NASA-Sun-640x611.jpg (scaled down to 20%)
//image sky: https://unblast.com/wp-content/uploads/2018/10/Sky-Stars-Pattern-1600x1190.jpg
import androidx.animation.*
import androidx.animation.Spring.DampingRatioHighBouncy
import androidx.animation.Spring.StiffnessLow
import androidx.compose.Composable
import androidx.compose.Model
import androidx.compose.remember
import androidx.ui.animation.Transition
@cortinico
cortinico / Kotlin.xml
Created April 6, 2020 15:00
.debug -> .also(::println) Live Template
<templateSet group="Kotlin">
<template name="debug" value="also(::println)" description="Print a debug log" toReformat="false" toShortenFQNames="true">
<context>
<option name="KOTLIN" value="true" />
<option name="KOTLIN_COMMENT" value="false" />
<option name="KOTLIN_TOPLEVEL" value="false" />
</context>
</template>
</templateSet>
@zach-klippenstein
zach-klippenstein / DrawLayerDemo.kt
Last active October 21, 2021 10:59
Interactive demo of the drawLayer composable function. (screencap in comments)
import androidx.animation.PhysicsBuilder
import androidx.animation.Spring.DampingRatioHighBouncy
import androidx.animation.Spring.StiffnessLow
import androidx.compose.Composable
import androidx.compose.Model
import androidx.compose.remember
import androidx.ui.animation.animate
import androidx.ui.core.DrawClipToBounds
import androidx.ui.core.Text
import androidx.ui.core.drawLayer
@pt2121
pt2121 / ExpandCollapseButton.kt
Last active December 22, 2023 11:28
Android Jetpack Compose caret animation
/*
* Copyright 2020 Prat Tana. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
@seratch
seratch / Application.kt
Last active January 28, 2023 00:40
Building Slack apps with Ktor framework
package com.example
import com.slack.api.bolt.App
import com.slack.api.bolt.AppConfig
import com.slack.api.bolt.request.Request
import com.slack.api.bolt.request.RequestHeaders
import com.slack.api.bolt.response.Response
import com.slack.api.bolt.util.QueryStringParser
import com.slack.api.bolt.util.SlackRequestParser
import com.slack.api.model.block.Blocks.asBlocks
@LouisCAD
LouisCAD / FusedLocationFlow.kt
Last active January 31, 2024 20:56
Create a Flow of location updates on Android (using kotlinx.coroutines), backed by Fused Location Provider from Google Play Services.
/*
* Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license.
*/
import android.location.Location
import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationResult
import com.google.android.gms.location.LocationServices
import kotlinx.coroutines.CancellationException