Skip to content

Instantly share code, notes, and snippets.

View amal's full-sized avatar
👨‍💻

Art Shendrik amal

👨‍💻
View GitHub Profile
@amal
amal / gradle_snippet.kt
Created June 1, 2023 11:04 — forked from cies/gradle_snippet.kt
Make Gradle print its task plan
// This prints the dependencies of each task in the current execution graph
gradle.taskGraph.whenReady(
closureOf<TaskExecutionGraph> {
println("About to run ${allTasks.size} tasks: (use `-i` to see why tasks are skipped, use `--rerun-tasks` to prevent UP-TO-DATE checks)")
allTasks.forEachIndexed { i, task ->
val dependenciesString =
if (task.dependsOn.isEmpty()) {
""
} else {
task.dependsOn.joinToString(", ", " (depends on ", ")") { dependency ->
@amal
amal / gist:2cb237497bb296e7c3a7da658734973a
Last active March 19, 2023 21:16 — forked from yorickhenning/gist:3275ea38e1619a5c8aa0efac9370484d
Reentrance checking coroutine Mutex
// https://github.com/Kotlin/kotlinx.coroutines/issues/3626#issuecomment-1451115356
// https://github.com/Kotlin/kotlinx.coroutines/issues/3626#issuecomment-1452820863
suspend fun <ReturnT> Mutex.checkedWithLock(
block: suspend () -> ReturnT
): ReturnT {
val element = LockedMutexesElement(this).key
check (currentCoroutineContext()[element] == null) {
"Reentered Mutex"
}
@amal
amal / ParallaxScreen.kt
Created September 29, 2022 14:26 — 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()
@amal
amal / Tooltip.kt
Last active July 10, 2024 15:05
How to show a tooltip in AndroidX Jetpack Compose?
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
// Tooltip implementation for AndroidX Jetpack Compose
// See usage example in the next file
// Tested with Compose version **1.1.0-alpha06**
// Based on material DropdownMenu implementation.
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.animateFloat
@amal
amal / androidx-migration-script.kts
Created August 3, 2019 02:03
AndroidX migration kotlin (KTS) script
import java.io.File
import java.nio.file.*
import java.nio.file.attribute.BasicFileAttributes
// Simple helper for AndroidX migration, written as Kotlin script
// Can be better then Android Studio migration
// But use at your own risk ;)
@amal
amal / ancient-assyrian-palace-iraq.html
Last active May 31, 2018 22:26
Aljazeera.com page html source example

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0 maximum-scale=1.0, minimal-ui" />
@amal
amal / Float128.java
Created October 21, 2017 16:28 — forked from rjeschke/Float128.java
128 bit floats in software (Java)
/*
* Copyright (C) 2012 René Jeschke <[email protected]>
*
* 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
@amal
amal / pr.md
Created October 19, 2017 11:40 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@amal
amal / setup_selenium.sh
Created August 14, 2017 21:32 — forked from curtismcmullan/setup_selenium.sh
Setup Selenium Server on Ubuntu 14.04
#!/bin/bash
# Following the guide found at this page
# http://programmingarehard.com/2014/03/17/behat-and-selenium-in-vagrant.html
echo "\r\nUpdating system ...\r\n"
sudo apt-get update
# Create folder to place selenium in
@amal
amal / latency.txt
Created January 22, 2017 18:15 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
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