Skip to content

Instantly share code, notes, and snippets.

Avatar
🐱
hax

Niclas Kron sphrak

🐱
hax
View GitHub Profile
@sphrak
sphrak / 0-sqlite-pagination.md
Last active Aug 20, 2022
sqlite3 stable cursor pagination with uuid's
View 0-sqlite-pagination.md

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 Aug 14, 2022
blender cheatsheet
View blender.md

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 / ParallaxScreen.kt
Created May 28, 2022 — forked from surajsau/ParallaxScreen.kt
Parallax effect with Jetpack Compose
View ParallaxScreen.kt
@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 / benchmark.sh
Last active Mar 31, 2022
measure android app startup time
View benchmark.sh
#!/bin/bash
# Simple bash script runs adb to measure startup time of android apps
trap ctrl_c INT
time=()
function ctrl_c() {
total=0
@sphrak
sphrak / terminal.md
Last active Feb 15, 2022
List of useful unix commands
View terminal.md

Useful unix commands

recursively search files matching *.fileExt for pattern in current directory

grep --color -inr --include \*.kt 'SDK_INT' .

Detect how many gradle daemons are running

@sphrak
sphrak / git_commons.md
Last active Jan 25, 2021 — forked from ravibhure/git_rebase.md
Git commons
View git_commons.md

In your local clone of your forked repository, you can add the original GitHub repository as a "remote". ("Remotes" are like nicknames for the URLs of repositories - origin is one, for example.) Then you can fetch all the branches from that upstream repository, and rebase your work to continue working on the upstream version. In terms of commands that might look like:

Add the remote, call it "upstream":

git remote add upstream https://github.com/whoever/whatever.git

Fetch all the branches of that remote into remote-tracking branches, such as upstream/master:

@sphrak
sphrak / latency.txt
Created Oct 4, 2020 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
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 / MainActivity.kt
Last active Jul 19, 2020
MVI Example 2 -- StateModel
View MainActivity.kt
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 / MainActivity.kt
Last active Jul 19, 2020
MVI -- Example 1 -- ConflatedBroadcastChannel
View MainActivity.kt
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 / kotlin-snippets.md
Last active May 14, 2020
kotlin-snippets
View kotlin-snippets.md

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