Skip to content

Instantly share code, notes, and snippets.

View cesarferreira's full-sized avatar

César Ferreira cesarferreira

View GitHub Profile
@cesarferreira
cesarferreira / OnBackPressed.java
Created August 20, 2015 16:36
Using onBackPressed() in Android Fragments
private final static String TAG_FRAGMENT = "TAG_FRAGMENT";
private void showFragment() {
final Myfragment fragment = new MyFragment();
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment, fragment, TAG_FRAGMENT);
transaction.addToBackStack(null);
transaction.commit();
}
@cesarferreira
cesarferreira / tools.md
Created February 27, 2024 00:48
Cool tools

Cool CLI Tools

A collection of command-line interface (CLI) tools designed to enhance productivity and make terminal navigation and file management more efficient and visually appealing. Here's a brief overview of each tool, along with installation commands using Homebrew on macOS.

Installation

First, ensure you have Homebrew installed. If not, visit Homebrew's website for installation instructions. Then, you can install the following tools using Homebrew:

brew install lsd
@cesarferreira
cesarferreira / styles.xml
Created May 12, 2014 15:31
Android - Disable activity slide-in animation when launching new activity
<!-- Developer should create a style -->
<style name="noAnimTheme" parent="android:Theme">
<item name="android:windowAnimationStyle">@null</item>
</style>
<!-- Then in manifest set it as theme for activity or whole application. -->
<activity android:name=".ui.ArticlesActivity" android:theme="@style/noAnimTheme">
#!/bin/bash
#By Nate Flink
#Invoke on the terminal like this
#curl -s https://gist.github.com/nateflink/9056302/raw/findreplaceosx.sh | bash -s "find-a-url.com" "replace-a-url.com"
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: ./$0 [find string] [replace string]"
exit 1
fi
@cesarferreira
cesarferreira / BlinkAnimation.java
Created May 27, 2014 13:58
Make a View Blink for a desired duration (android)
// Animate a text view
TextView myText = (TextView) findViewById(R.id.textView1);
myText = (TextView)Utils.makeMeBlink(myText,250,20);
// Animate an image view
ImageView imageView = (ImageView) findViewById(R.id.imageView);
imageView = (ImageView)Utils.makeMeBlink(imageView,250,20);
@cesarferreira
cesarferreira / gradle.properties
Last active June 24, 2022 16:55
Global Gradle Properties
# The Gradle daemon aims to improve the startup and execution time of Gradle.
# When set to true the Gradle daemon is to run the build.
org.gradle.daemon=true
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
@cesarferreira
cesarferreira / RxJava.md
Last active February 2, 2022 07:28
Party tricks with RxJava, RxAndroid & Retrolambda

View Click

Instead of the verbose setOnClickListener:

RxView.clicks(submitButton).subscribe(o -> log("submit button clicked!"));

Filter even numbers

Observable
    .just(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
@cesarferreira
cesarferreira / api.java
Last active February 1, 2022 16:32
RxJava and Retrofit sample
public interface API {
@GET("/user/{username}/dogs")
Observable<Dog> getAllDogsOf(@Path("username") String username);
@GET("/dog/{id}")
Observable<Dog> getDogInfoById(@Path("id") int dogId);
}
/**
* Base Class for handling errors/failures/exceptions.
* Every feature specific failure should extend [FeatureFailure] class.
*/
sealed class Failure(val exception: Exception = Exception("Failure")) {
object None : Failure()
object NetworkConnection : Failure()
object ServerError : Failure()
/** * Extend this class for feature specific failures.*/
@cesarferreira
cesarferreira / MyRecyclerViewAdapter.kt
Last active July 1, 2021 04:24
DiffUtils kotlin extension
class DeliveryWindowsAdapter : RecyclerView.Adapter<DeliveryWindowsAdapter.ViewHolder>() {
var items: List<DeliveryWindowUiModel> by Delegates.observable(emptyList()) { _, oldList, newList ->
autoNotify(oldList, newList) { o, n -> o.id == n.id }
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val deliveryWindow = items[position]
holder.title.text = deliveryWindow.title
holder.price.text = deliveryWindow.friendlyPrice