Skip to content

Instantly share code, notes, and snippets.

@mrleolink
mrleolink / WrapContentViewPager.java
Last active February 8, 2018 03:17
ViewPager that wraps current page's height
import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
/**
* {@link ViewPager} that wraps current page's height
package net.leolink.android.rxbus;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.util.SparseArray;
import java.lang.annotation.Retention;
import java.util.HashMap;
import java.util.Map;
@mrleolink
mrleolink / open-atlassian-stash-pullrequest.sh
Last active February 22, 2017 06:09 — forked from jakub-g/open-atlassian-stash-pullrequest.sh
Open Atlassian Stash pull request from command line (open browser at the right URL)
#!/bin/bash
##################################################################
# Open Atlassian Stash pull request from command line.
# (opens the default browser at the proper URL with data prefilled)
#
# It infers current branch name, repo name, current user name, from git config.
############################### CONFIG ###########################
URL_PREFIX="https://YOU_GIT_DOMAIN.com/your/project/path/compare/commits?commits&"
@mrleolink
mrleolink / Percolation.java
Last active February 16, 2017 12:38
My implementation of the union-find assignment at: http://coursera.cs.princeton.edu/algs4/assignments/percolation.html. This implementation includes handling backwash with only ONE union-find object and one extra integer array of size n*n to save status of components.
import edu.princeton.cs.algs4.WeightedQuickUnionUF;
/**
* Created by leolink on 11/24/16.
*/
public class Percolation {
private static final int UNOPENED = 0b000;
private static final int OPENED = 0b001;
private static final int CONNECTED_TOP = 0b010;
private static final int CONNECTED_BOTTOM = 0b100;
Find: ^(\W+public void .*?)_([A-Z]{1})([a-zA-Z]*)_([A-Z]{1})([a-zA-Z]*)\(\) \{$
Replace: $1_\l$2$3_\l$4$5() {
This will cause all texts like this:
" public void method1_DoThisDoThat_ReturnThisReturnThat() {"
be relaced with:
" public void method1_doThisDoThat_returnThisReturnThat() {"
@mrleolink
mrleolink / AsyncFuture.java
Last active November 27, 2016 09:02
An implementation of Future which also provides UI Thread callback for Android - Revision 1 is reviewed here: http://codereview.stackexchange.com/questions/143608/combination-of-javas-future-and-androids-asynctask
import android.os.Handler;
import android.os.Looper;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@mrleolink
mrleolink / .zshrc
Last active November 27, 2016 09:02
My .zshrc
# General
export LANG=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
# Path to your oh-my-zsh installation.
export ZSH=~/Dropbox/MY/Preferences/Unix/\[dot\]oh-my-zsh
export MANPATH="/usr/local/man:$MANPATH"
export SSH_KEY_PATH="~/.ssh/dsa_id"
# zsh custom folder
ZSH_CUSTOM="$ZSH/custom"
@mrleolink
mrleolink / UnsignedRightShiftOperator.java
Created October 8, 2015 05:27
Unsigned right shift operator explanation
int value = -229;
System.out.println(value);
System.out.println(value >> 5);
System.out.println(value >>> 5);
System.out.println(Integer.toBinaryString(value));
System.out.println(Integer.toBinaryString(value >> 5)); // `>>` preserves integer's sign
System.out.println(Integer.toBinaryString(value >>> 5)); // `>>>` doesn't preserve integer's sign, just shift everything to the right then fill all the empty bit on the left with 0
//======================= RESULT
-229
@mrleolink
mrleolink / intToHexString.java
Last active November 27, 2016 09:00
Explanation how to convert an int to hex string in Java use bitwise operations
public static String toHexString(int decimal) {
String codes = "0123456789ABCDEF";
StringBuilder builder = new StringBuilder(8);
builder.setLength(8);
for (int i = 7; i >= 0; i--) {
// E.g: let decimal = 229 -> its value when expressed in binary is 11100101
// And binary form of 0xF is 1111 (equals to ..00000001111)
@mrleolink
mrleolink / CustomEllipsizeTextView.java
Created November 20, 2014 08:56
A hack to set custom ellipsize and postfix string for Android's TextView
public class CustomEllipsizeTextView extends TextView {
private static final int MAX_LINE = 2;
private static final String ELLIPSIZE_STRING = "...";
private String originalText;
private int maxLines = MAX_LINE;
private String postfix;
private boolean postfixAdded;