Skip to content

Instantly share code, notes, and snippets.

View samueljarosinski's full-sized avatar

Samuel Jarosiński samueljarosinski

View GitHub Profile
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.ui.graphics.Color
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlin.math.pow
import kotlin.math.sqrt
@Stable
suspend fun findNearestColor(color: Int): PaletteColor = withContext(Dispatchers.Default) {
import androidx.compose.material.icons.Icons
import androidx.compose.ui.graphics.vector.ImageVector
fun getIconByName(icon: String, set: IconsSet = IconsSet.Filled): ImageVector =
Class.forName("androidx.compose.material.icons.${set.name.lowercase()}.${icon}Kt")
.getMethod("get$icon", set.toIcons().javaClass)
.invoke(set.toIcons(), set.toIcons()) as ImageVector
enum class IconsSet {
Filled, Outlined, Rounded, TwoTone;
@samueljarosinski
samueljarosinski / RainbowSlider.kt
Created October 11, 2023 17:41
Rainbow Slider
import android.content.res.Configuration
import android.graphics.Bitmap
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.center
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.rotate
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView
class DebugItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
private val borderColor = context.getColor(android.R.color.holo_purple)
private val leftColor = context.getColor(android.R.color.holo_red_light)
import android.os.SystemClock
import timber.log.Timber
import kotlin.time.Duration
class TimingLogger(tag: String) {
private val tag: String = tag
get() = "T/$field"
private var splits = mutableMapOf<String, Long>()
@samueljarosinski
samueljarosinski / blog_post_cover_generator_for_sketch.js
Created April 15, 2020 02:29
Blog post cover generator for Sketch
const sketch = require('sketch/dom')
const UI = require('sketch/ui')
const Group = sketch.Group
const Rectangle = sketch.Rectangle
const Slice = sketch.Slice
const document = require('sketch').getSelectedDocument()
const page = document.selectedPage
if (document.selectedLayers.isEmpty) {
import csv
import glob
import os
import shutil
import sys
import urllib.request
if len(sys.argv) != 2:
print('Usage: ' + sys.argv[0] + ' [path to project]')
sys.exit()
android_gifify() {
adb shell screenrecord --bit-rate 8000000 --time-limit ${1:-5} /sdcard/record.mp4
adb pull /sdcard/record.mp4
adb shell rm /sdcard/record.mp4
gifify record.mp4 --good
rm -rf record.mp4
}
@samueljarosinski
samueljarosinski / detect.sh
Created February 13, 2014 01:21 — forked from kissarat/detect.sh
The script beeps when internet connection becomes available.
#!/bin/sh
modprobe pcspkr
while true
do ping -c 4 google.com 2> /dev/null
if [ $? -eq 0 ]
then beep
break
fi
sleep 5