Skip to content

Instantly share code, notes, and snippets.

View sphrak's full-sized avatar
🐱
hax

Niclas sphrak

🐱
hax
  • Stockholm, Sverige
  • 13:23 (UTC +02:00)
View GitHub Profile
@sphrak
sphrak / MaskExtension.kt
Created February 8, 2020 20:52 — forked from maiconhellmann/MaskExtension.kt
MaskExtension wrote in Kotlin
import android.support.annotation.StringDef
import android.text.Editable
import android.text.TextWatcher
import android.widget.EditText
@StringDef(PHONE_9_MASK, PHONE_8_MASK, CPF_MASK, ZIP_CODE_PT_BR, MONTH_YEAR, CREDIT_CARD)
@Retention(AnnotationRetention.SOURCE)
annotation class MaskType
const val PHONE_9_MASK = "(##) #####-####"
@sphrak
sphrak / semverdiff.sh
Last active March 5, 2020 09:55
a tiny script for outputting changelog diff between releases for (semver)
#!/bin/bash
# Usage
# chmod +x semverdiff.sh
# Get diff between 1.0.0..1.0.1
# ./semverdiff 1.0.1
get_diff() {
sed -n "/^## \[$1\]/,/^## /p" CHANGELOG.md | egrep "^(-|\s+)"
}
@sphrak
sphrak / kotlin-snippets.md
Last active May 14, 2020 18:05
kotlin-snippets

Kotlin Snippets

A tiny collection of Kotlin snippets that I find useful.

Measure Execution time

Keep in mind this is not an end all be all measurement since the jvm has indeterministic garbage collection but it can give you a general idea of whats taking time.

With return value

@sphrak
sphrak / MainActivity.kt
Last active July 19, 2020 13:08
MVI -- Example 1 -- ConflatedBroadcastChannel
class MainActivity : AppCompatActivity(R.layout.activity_main) {
@Inject
lateinit var viewModel: MainActivityViewModel
@Inject
lateinit eventChannel: ConflatedBroadcastChannel<MainActivityView.Event>
private var isInitialised: Boolean = false
@sphrak
sphrak / MainActivity.kt
Last active July 19, 2020 13:09
MVI Example 2 -- StateModel
class MainActivity : AppCompatActivity(R.layout.activity_main) {
@Inject
lateinit var viewModel: MainActivityViewModel
private var isInitialised: Boolean = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@sphrak
sphrak / latency.txt
Created October 4, 2020 11:16 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@sphrak
sphrak / ParallaxScreen.kt
Created May 28, 2022 11:32 — forked from surajsau/ParallaxScreen.kt
Parallax effect with Jetpack Compose
@Composable
fun ParallaxScreen(modifier: Modifier = Modifier) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
var data by remember { mutableStateOf<SensorData?>(null) }
DisposableEffect(Unit) {
val dataManager = SensorDataManager(context)
dataManager.init()
@sphrak
sphrak / 0-sqlite-pagination.md
Last active August 20, 2022 23:43
sqlite3 stable cursor pagination with uuid's

sqlite3 stable pagination with uuid

based on https://morningcoffee.io/stable-pagination.html.

In order for this to work I had to use uuidgen -t to generate time-based uuids otherwise the ordering would be messed up after 2-3 pages in.

create db

sqlite3 pagination.db
@sphrak
sphrak / blender.md
Last active August 14, 2022 15:25
blender cheatsheet

keys

move objects

hit g then move freely -- or combine with z, x or y to move along respective axis

deleting objects

hit x

@sphrak
sphrak / .editorconfig
Created December 24, 2022 23:26
ktlint
[*.{kt,kts}]
# possible values: number (e.g. 2), "unset" (makes ktlint ignore indentation completely)
indent_size=4
# true (recommended) / false
insert_final_newline=false
# possible values: number (e.g. 120) (package name, imports & comments are ignored), "off"
# it's automatically set to 100 on `ktlint --android ...` (per Android Kotlin Style Guide)
max_line_length=off
ktlint_standard_no-empty-first-line-in-method-block=disabled
ktlint_standard_trailing-comma-on-declaration-site=disabled