Skip to content

Instantly share code, notes, and snippets.

View AchrafAmil's full-sized avatar
🧑‍💻

Achraf AchrafAmil

🧑‍💻
View GitHub Profile
#!/usr/bin/env tnode
import { execSync } from "child_process";
import fs from "fs";
import WebSocket from "ws";
const WINDOW_SIZE_MS = 50;
const SAMPLE_RATE = 16000;
const BYTES_PER_SAMPLE = 2;
const API_KEY = "";
> Task :testAll
2021-12-20 22:11:48.627 [Thread-22] INFO TestDatabasesManagerKt - Worker is shutting down, finishing cleanups.
Kotlin build report is written to /Users/achraf/health/server/build/reports/kotlin-build/server-build-2021-12-20-22-09-07.txt
Task timings:
48666ms :testAll
21136ms :jooq:generated:compileKotlin
6622ms :graphql:generated:compileKotlin
5377ms :features:story:impl:compileTestKotlin
3709ms :jooq:generated:generateJooq
@AchrafAmil
AchrafAmil / alterOn.kt
Created June 17, 2021 15:59
Operator to alter a first flow's last emitted value whenever the second flow emits. Transformation will take last value from both as in combine
/**
* Will emit all values from Flow<T1>, plus those from Flow<T2> after transformation giving the latest from Flow<T1>.
*
*/
fun <T1, T2> Flow<T1>.alterOn(other: Flow<T2>, transform: suspend (a: T1, b: T2) -> T1): Flow<T1> = channelFlow {
coroutineScope {
val thisLatestValue = AtomicReference<T1?>()
launch {
other.collect { t2 ->
data class AA(
val a1: String,
val a2: BB,
val a3: Int,
)
data class BB(
val b1: CC,
val b2: Int,
--------- beginning of crash
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.fabernovel.bugreproduction.dynamic_navigation, PID: 2879
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fabernovel.bugreproduction.dynamic_navigation/com.fabernovel.bugreproduction.dynamic_navigation.MainActivity}: android.view.InflateException: Binary XML file line #11 in com.fabernovel.bugreproduction.dynamic_navigation:layout/activity_main: Binary XML file line #11 in com.fabernovel.bugreproduction.dynamic_navigation:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at and
@AchrafAmil
AchrafAmil / CoroutineScopes.kt
Last active August 5, 2023 06:23
Kotlin coroutine scope associated with an Android View (scope cancelled on view detached and re-initialized in case it's re-attached)
import android.view.View
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
val View.viewCoroutineScope: CoroutineScope
get() {
var viewScope = getTag(R.id.viewCoroutineScope) as CoroutineScope?
@AchrafAmil
AchrafAmil / AppOpsCallback.kt
Created June 23, 2020 11:50
Android's AppOpsManager.OnOpNotedCallback implementation to log sensitive data access ops
import android.app.AppOpsManager
import android.app.AsyncNotedAppOp
import android.app.SyncNotedAppOp
import android.content.Context
import android.util.Log
import androidx.annotation.RequiresApi
@RequiresApi(30)
class AppOpsCallback(private val context: Context) : AppOpsManager.OnOpNotedCallback() {
@AchrafAmil
AchrafAmil / ProfileActivity.kt
Last active October 11, 2019 09:10
Android reactive programming sample
import com.jakewharton.rxbinding2.view.clicks
viewModel.bind(follow_button.clicks().map{ ProfileUiEvent.Follow })
viewModel.uiState.observe(this, ::showState)
viewModel.uiContent.observe(this, ::showContent)
ProfileActivity.kt
import com.jakewharton.rxbinding2.view.clicks
...
viewModel.bind(follow_button.clicks().map{ ProfileUiEvent.Follow })
viewModel.uiState.observe(this, ::showState)
viewModel.uiContent.observe(this, ::showContent)
@AchrafAmil
AchrafAmil / BodyEditorLoader.java
Last active December 2, 2016 16:57 — forked from zudov/BodyEditorLoader.java
That is a version of loader for physic-body-editor that works with new JSON API from libgdx nightlies - Works with org.jbox2d instead of com.badlogic.gdx.physics.box2d
package aurelienribon.bodyeditor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.Matrix4;
import org.jbox2d.collision.WorldManifold;
import org.jbox2d.collision.shapes.ChainShape;
import org.jbox2d.collision.shapes.CircleShape;