Skip to content

Instantly share code, notes, and snippets.

@danielesegato
danielesegato / ChannelSharedFlow.kt
Last active January 13, 2024 15:17
Coroutine: Channel Shared Flow
/*
* Copyright 2022 Daniele Segato
*
* 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
@danielesegato
danielesegato / TestFlowCollector.kt
Last active January 25, 2021 15:00
TestFlowCollector to test kotlin coroutines Flow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestCoroutineScope
import org.junit.Assert.*
import kotlin.coroutines.coroutineContext
import kotlin.reflect.KClass
@danielesegato
danielesegato / CreditCardFormatTextWatcher.java
Last active April 8, 2021 08:42 — forked from liberorignanese/MarginSpan.java
Android TextInputLayout with credit card mask
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.Spannable;
import android.text.TextWatcher;
@danielesegato
danielesegato / Maven-Publish.Android-Library.md
Last active March 30, 2023 11:44
Android Library Publishing Maven Artifacts via gradle

What is this

This gitst contains a script to push Android libraries as artifacts on a maven repository using the gradle build system.

It is somewhate a fork of Chris Banes gradle push script.

This was me while trying to understand how to setup maven publishing with gradle:

confused AF

Documentation is absent or very lacking and I found no script handling javadoc properly for Android.

@danielesegato
danielesegato / _Serverless-Bash-Autocomplete.md
Last active July 25, 2016 19:43 — forked from davidgf/serverless
Bash completion for Serverless

To enable serverless bash completion:

  • Install serverless: npm -g serverless
  • Append the servereless.bash code to the .bashrc or .bash_profile file in your home directory

This gitst is a fork of https://gist.github.com/davidgf/5bd76141aa70f9ed4d8f716851e68830. It avoid using find .to look for lambda functions: the command, if executed in the root directory or a big directory, can be really bad for performances. It also add subcommand handling for non-functions.

The script instead look for the serverless project file s-project.json starting from the current directory and looking up,

@danielesegato
danielesegato / RXJava-Wrap-CallbackAPI-README.md
Last active February 4, 2020 15:03
RxJava: Creating Observable from legacy asynchronous API using callbacks

About the gist

EDIT: This has become soon obsolete when Observable.fromAsync() has been released in RxJava. An issue from JakeWarthon here: ReactiveX/RxJava#4177 generated a pull request which is being implemented / discussed here: ReactiveX/RxJava#4179 . See below on how to use it.

I'm learning RxJava. Many Rx-libraries out there are using Obvservable.create() with an inline OnSubscribe implementation to wrap legacy APIs, like this one for the Android GoogleMap API:

class MapFragmentMapReadyOnSubscribe implements Observable.OnSubscribe<GoogleMap> {
  final MapFragment fragment;
@danielesegato
danielesegato / SlowARTDebugActivity.java
Created October 23, 2014 11:47
TESTCASE: Debug very slow on ART for method Html.fromHtml() - android bug 77984
package com.neosperience.projects.playgroundandroid;
import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@danielesegato
danielesegato / .gitignore
Last active May 5, 2017 01:06
Android development Git Ignores
# Android
gen/
build/
local.properties
# Old Android
bin/
proguard/
# suggestion: also ignore libs/*.properties files for old eclipse project
# can't be added here because multiple libs/ directory can be around in different paths
@danielesegato
danielesegato / AndroidBug-OptionItems-Fragments-29472-workaround.md
Last active March 27, 2019 13:40
Android Option Menu + Fragments Workaround with ViewPager / ActionBar / Drawer, Menu Items not displaying

This gist is a workaround to this bug:

https://code.google.com/p/android/issues/detail?id=29472

No changes are needed to your current code but changing the extended fragment/activity class.

All you have to do is put this two classes in your code and make your activity extend MenuManagerActivity and your fragment MenuDelegatorFragment. If you are using Nested fragment you must make sure that all fragments containing nested Fragments with options menu also extend MenuDelegatorFragment (both if the parent fragment need an option menu both if it doesn't need it).

@danielesegato
danielesegato / assimp.android.make.verbose.log
Created August 9, 2013 14:45
This is the log of the make command when compiling from Android. Following this guide: http://jazzyjester.wordpress.com/2013/02/02/test With the modifications I describe in the comments of that guide to compile for android-9
/usr/bin/cmake -H/home/mastro/ws/third-parties/assimp -B/home/mastro/ws/third-parties/assimp/buildandroid --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/mastro/ws/third-parties/assimp/buildandroid/CMakeFiles /home/mastro/ws/third-parties/assimp/buildandroid/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory `/home/mastro/ws/third-parties/assimp/buildandroid'
make -f code/CMakeFiles/assimp.dir/build.make code/CMakeFiles/assimp.dir/depend
make[2]: Entering directory `/home/mastro/ws/third-parties/assimp/buildandroid'
cd /home/mastro/ws/third-parties/assimp/buildandroid && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/mastro/ws/third-parties/assimp /home/mastro/ws/third-parties/assimp/code /home/mastro/ws/third-parties/assimp/buildandroid /home/mastro/ws/third-parties/assimp/buildandroid/code /home/mastro/ws/third-parties/assimp/buildandroid/code/CMakeFiles/assimp.dir/DependInfo.cmake --color=
make[2]: Leaving directory `