Skip to content

Instantly share code, notes, and snippets.

@audiserg
audiserg / keyboard_support.kt
Created October 17, 2019 14:07 — forked from emilieroberts/keyboard_support.kt
Keyboard support example for Android on Chrome OS
override fun onKeyUp(code: Int, ev: KeyEvent?): Boolean {
return when (code) {
KeyEvent.KEYCODE_J -> {
// Do something here
true
}
else -> super.onKeyUp(code, ev) // Important
}
}
@audiserg
audiserg / GroupBy.hs
Last active October 29, 2020 17:06 — forked from jbpotonnier/GroupBy.hs
groupBy in Erlang and Haskell
module GroupBy where
import Data.Map (Map)
import qualified Data.Map as Map
groupBy :: Ord b => (a -> b) -> [a] -> Map b [a]
groupBy f = foldr (\ v -> Map.insertWith (++) (f v) [v]) Map.empty
groupBy' :: Ord b => (a -> b) -> [a] -> Map b [a]
@audiserg
audiserg / FragFollow.java
Created December 16, 2020 11:11 — forked from deep15187/FragFollow.java
Direct intent to Facebook, Google plus, Linkedin, Twitter, Pinterest, Instagram, Snapchat and Youtube from a fragment after checking if app installed on device
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
@audiserg
audiserg / gist:59258d51a5f73097ec23961f4fedf6f9
Created July 9, 2021 08:12 — forked from markus2610/gist:2304781
Intent to start navigation activity - payload
final int defaultFlag = PackageManager.MATCH_DEFAULT_ONLY;
Intent[] explicitIntents;
//see an example here http://stackoverflow.com/questions/2662531/launching-google-maps-directions-via-an-intent-on-android
private Intent[] getExplicitIntents() {
if(explicitIntents == null) {
PackageManager currentPM = getPackageManager();
explicitIntents = new Intent[]{
new Intent("android.intent.action.navigon.START_PUBLIC"), //navigon with public intent
currentPM.getLaunchIntentForPackage("com.navigon.navigator"), //navigon without public intent
@audiserg
audiserg / DynamicProxies.kt
Created July 16, 2021 09:04 — forked from SupaHam/DynamicProxies.kt
Dynamic Proxies with Kotlin for accessing private classes.
/*
* Code by @vmironov on Kotlinlang slack.
*
* This code uses dynamic proxies in Java to make it easier to access inaccessible classes via an accessible representation.
*/
inline fun <reified T : Any> createMirror(value: Any) = createMirror(value, T::class.java)
fun <T> createMirror(value: Any, clazz: Class<T>): T {
val loader = clazz.classLoader
@audiserg
audiserg / Snackbars.kt
Created August 17, 2021 12:26 — forked from RankoR/Snackbars.kt
Extend Espresso to make Snackbar testing easier. Note: this code works only for AndroidX.
import androidx.annotation.StringRes
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.ViewInteraction
import androidx.test.espresso.matcher.ViewMatchers
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf
fun onSnackbar(@StringRes withText: Int): ViewInteraction {
return onView(
CoreMatchers.allOf(
@audiserg
audiserg / DashedBorder.kt
Created July 19, 2022 13:06 — forked from DavidIbrahim/DashedBorder.kt
dashedBorder modifier for android compose
import androidx.compose.foundation.BorderStroke
/*
* Copyright 2020 The Android Open Source Project
*
* 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
@audiserg
audiserg / pattern_matching.dart
Created January 23, 2023 06:21 — forked from nythrox/pattern_matching.dart
Flutter/Dart pattern matching
void main() {
Greeting message = Hi();
final result = match(message, {
on((Hi hi) => "hello, ${hi.name}"),
on((Bye bye) => "bye, see you at ${bye.seeYouAgain}"),
otherwise(() => throw Error()),
});
print(result);
@audiserg
audiserg / do_notation.dart
Created January 23, 2023 06:23 — forked from nythrox/do_notation.dart
Flutter/Dart do notation
main() {
// Either<dynamic, int> result
final result = Either.Do(() {
final num1 = perform(Right(5));
final num2 = perform(Right(2));
return num1 * num2;
});
print(result.value); // 10
// Option<int> result2
final result2 = Option.Do(() {
@audiserg
audiserg / do_notation_future.dart
Created January 23, 2023 06:23 — forked from nythrox/do_notation_future.dart
Dart await/async using Future and do notation
main() {
final value = async(() {
final num1 = await(Future.value(5));
final num2 = await(Future.value(2));
return num1 * num2;
});
value.then(print).catchError(print);
async(() {
[1,2,3,4,5].forEach((i) {