Skip to content

Instantly share code, notes, and snippets.

@lenamuit
lenamuit / DeviceUuidFactory.java
Created January 12, 2015 02:33
Generate UUID for Android
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.Settings.Secure;
import android.telephony.TelephonyManager;
import java.io.UnsupportedEncodingException;
import java.util.UUID;
public class DeviceUuidFactory {
@lenamuit
lenamuit / Java-keytool-command.md
Last active December 30, 2023 12:15
Java Keytool command

Java Keytool Commands for Creating and Importing

These commands allow you to generate a new Java Keytool keystore file, create a CSR, and import certificates. Any root or intermediate certificates will need to be imported before importing the primary certificate for your domain.

Generate a Java keystore and key pair

keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -keysize 2048

Generate a certificate signing request (CSR) for an existing Java keystore

@lenamuit
lenamuit / AnimationBuilder.java
Last active June 4, 2021 21:31
Animation builder factory for Android Viewer
import android.content.Context;
import android.support.annotation.AnimRes;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
/**
* HOW TO USE
* AnimationBuilder.from(getActivity())
@lenamuit
lenamuit / install-oracle-jdk
Created January 6, 2015 17:36
Install JDK on Ubuntu
You can completely remove the OpenJDK and fresh Install Oracle Java JDK by the following steps:
Remove OpenJDK completely by this command: sudo apt-get purge openjdk-\*
Download the Oracle Java JDK here.
Note: download appropriate file, for example if your system is x64 Ubuntu (i.e, Debian) the download file is named like this: jdk-8u20-linux-x64.tar.gz
Create a folder named java in /usr/local/by this command: sudo mkdir -p /usr/local/java
Copy the Downloaded file in the directory /usr/local/java. To do this, CD into directory where downloaded file is located and use this command for copying that file to /usr/local/java/:
@lenamuit
lenamuit / SharePrefUtils.java
Last active December 7, 2019 07:55
SharePreferenceUtils for Android - the utils class to help you working with SharePreference
public class SharePrefUtils {
public enum Key{
//list of your keys here
}
private static SharedPreferences getSharePreference(Context context){
return context.getSharedPreferences("your_pref",Context.MODE_PRIVATE);
}
private static SharedPreferences.Editor getEditor(Context context){
@lenamuit
lenamuit / observer_timer.md
Last active October 31, 2019 09:26
Java, Android, RxJava. Fastest and simplest way to build a countdown timer or stick timer

In the pass, to build the timer task, for example: to show count down timer on TextView or show current position when play the music or video use MediaPlayer, I use TimerTask or Timer object as the best choices.

This is the old source code

timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
    @Override 
    public void run() { 
 runOnUiThread(new Runnable() {
@lenamuit
lenamuit / BitmapUtils.java
Created June 23, 2015 01:57
Picasso - Load image wrap content
public static void loadImageWrapContent(Context context, final ImageView imageView, String url){
Picasso.with(context)
.load(url)
.placeholder(R.drawable.progress_indeterminate_horizontal_holo)
.transform(new Transformation() {
@Override
public Bitmap transform(Bitmap source) {
int targetWidth = imageView.getWidth();
double aspectRatio = (double) source.getHeight() / (double) source.getWidth();
int targetHeight = (int) (targetWidth * aspectRatio);
//Link reference https://github.com/nbadal/android-gif-encoder
public byte[] generateGIF() {
ArrayList<Bitmap> bitmaps = adapter.getBitmapArray();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
AnimatedGifEncoder encoder = new AnimatedGifEncoder();
encoder.start(bos);
for (Bitmap bitmap : bitmaps) {
encoder.addFrame(bitmap);
}
encoder.finish();
@lenamuit
lenamuit / pom.xml
Created August 21, 2013 05:23
fix error --core-android when using google api libs
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.16.0-rc</version>
<exclusions>
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
<exclusion>
# install passenger & use passenger-nginx module to install nginx for us (compiled from source).
gem install passenger
sudo mkdir /opt/nginx/
sudo chown ubuntu /opt/nginx
passenger-install-nginx-module
# install the init scripts to start nginx
wget -O init-deb.sh https://gist.githubusercontent.com/lenamuit/515a775cb1c51924ffa2/raw/431e70fe93c4d052ecfa74d79635ce899aee706c/nginx
sudo mv 660-init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx