Skip to content

Instantly share code, notes, and snippets.

@Razeeman
Razeeman / Singletons.md
Last active February 23, 2025 03:15
Thread safe singleton implementations in java and kotlin.

Java

Not thread safe.

class SimpleSingleton {
    private static SimpleSingleton sInstance;
  
    private SimpleSingleton() {}
 
@nickbutcher
nickbutcher / LICENSE
Last active October 6, 2020 11:14
Fun with gradients and AnimatedVectorDrawables. Illustration by the wonderful https://twitter.com/VPoltrack
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@MeNiks
MeNiks / RealPathUtil.kt
Last active July 10, 2024 08:57
Kotlin code to get real path / sd card path from intent data while browsing file.
import android.annotation.SuppressLint
import android.content.ContentUris
import android.content.Context
import android.content.CursorLoader
import android.database.Cursor
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.provider.DocumentsContract
import android.provider.MediaStore
@kevinjam
kevinjam / Decrypt.java
Last active September 7, 2022 07:25
RSA Encrypt in PHP and Decrypt in Java or Kotlin
public class DecryptKey {
//before you proceed, you need to ensure your public key is PKCS8 since that is what can be read natively in java.
//If your key begins with-----BEGIN CERTIFICATE-----,
// the it is ssleay and you need to convert it using the openssl command below
//openssl pkcs8 -topk8 -inform pem -in public.key -outform pem -nocrypt -out pkcs8-public-key.pem
//TODO You can you phpsecLib lib but it doesn't support some Library
//opnssl work fine
final private static String RSA_PRIVATE_KEY =
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzTrKt2Y7HqQpt8w379Sl
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@orcchg
orcchg / ExpiryDateTextWatcher.java
Created April 19, 2018 17:29
TextWatcher for expiry date MM/YY automatically adding slash. For Android
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.NonNull;
import android.text.Editable;
import android.text.Spannable;
import android.text.TextWatcher;
import android.text.style.ReplacementSpan;
public class ExpiryDateTextWatcher implements TextWatcher {
private int maxLength = 5;
@abhinav272
abhinav272 / KeyboardHeightProvider.java
Created March 20, 2018 10:05
Keyboard height provider for android
import android.app.Activity;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.util.DisplayMetrics;
@chetanppatil
chetanppatil / install-postman.sh
Last active June 10, 2023 17:11
Install Native Postman On Linux
#!/bin/bash
# Download Postman
cd /tmp || exit
echo "Downloading Postman..."
wget -q https://dl.pstmn.io/download/latest/linux?arch=64 -O postman.tar.gz
# Extract and install Postman to /opt
echo "Extracting and installing to /opt..."
sudo tar -xzf postman.tar.gz -C /opt/
@samuel22gj
samuel22gj / OnItemVisibleChangeListener.java
Last active July 14, 2023 09:09
A callback listener to notify when item visibility change.
public abstract class OnItemVisibleChangeListener extends RecyclerView.OnScrollListener {
private static final String TAG = OnItemVisibleChangeListener.class.getSimpleName();
private int mFirstVisibleItemPosition = RecyclerView.NO_POSITION;
private int mFirstCompletelyVisibleItemPosition = RecyclerView.NO_POSITION;
private int mLastVisibleItemPosition = RecyclerView.NO_POSITION;
private int mLastCompletelyVisibleItemPosition = RecyclerView.NO_POSITION;
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
@rowland007
rowland007 / 51-android.rules
Created December 29, 2017 15:14
Linux udev rules for android devices
# These rules refer: https://developer.android.com/studio/run/device.html
# and include many suggestions from Arch Linux, GitHub and other Communities.
# Latest version can be found at: https://github.com/M0Rf30/android-udev-rules
# Skip this section below if this device is not connected by USB
SUBSYSTEM!="usb", GOTO="android_usb_rules_end"
LABEL="android_usb_rules_begin"
# Devices listed here in android_usb_rules_{begin...end} are connected by USB
# Acer