Skip to content

Instantly share code, notes, and snippets.

@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() {
# 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
#!/bin/sh
#
# used in https://gist.github.com/dannguyen/5415628 for CentOS
# modification of: http://articles.slicehost.com/2009/2/2/centos-adding-an-nginx-init-script
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
@lenamuit
lenamuit / centos-nginx.sh
Last active August 29, 2015 14:26 — forked from dannguyen/centos-nginx.sh
This is a nginx initialization script for CentOS that slightly modifies this template from Slicehost to use nginx's default install paths: http://articles.slicehost.com/2009/2/2/centos-adding-an-nginx-init-script
#!/bin/sh
#
# used in https://gist.github.com/dannguyen/5415628 for CentOS
# modification of: http://articles.slicehost.com/2009/2/2/centos-adding-an-nginx-init-script
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
@lenamuit
lenamuit / gist:ba0405a8da9a9a3d2d2f
Last active August 29, 2015 14:24
Android - Change color of image in imageView or ImageButton
imageView.setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP);
@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 / ScrollViewExt.java
Created June 24, 2015 16:52
ScrollViewExt with reach bottom callback
public class ScrollViewExt extends ScrollView {
private ScrollViewListener scrollViewListener;
public ScrollViewExt(Context context) {
super(context);
}
public ScrollViewExt(Context context, AttributeSet attrs) {
super(context, attrs);
}
@lenamuit
lenamuit / validate_email.java
Created June 24, 2015 09:12
Android, validate email address in one line
Patterns.EMAIL_ADDRESS.matcher(email).matches();
@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 / 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);