Skip to content

Instantly share code, notes, and snippets.

View rylexr's full-sized avatar
💭
Working on Memorigi Web!

R rylexr

💭
Working on Memorigi Web!
View GitHub Profile
@SH4DY
SH4DY / forkJoin.java
Last active October 10, 2016 02:12
Find the greatest number in an array with a multi-threaded fork/join approach
/**
* Find the greatest number in an array with a multi-threaded fork/join approach.
*
* This is a simple recursive divide&conquer approach to search through a list
* and return the max-element. It is using a subclass of java.util.concurrent.ForkJoinTask
* (namely RecursiveTask<V>).
*
* Theoretical aspect: Amdahl's Law.
* Possible speedup with n processors: S(n) = 1 / (B + 1-B*(1/n))
* where B is the fractal of the programm which can only be
@hamakn
hamakn / height.java
Created April 6, 2015 02:41
Android: Get height of status, action, navigation bar (pixels)
// status bar height
int statusBarHeight = 0;
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
// action bar height
int actionBarHeight = 0;
final TypedArray styledAttributes = getActivity().getTheme().obtainStyledAttributes(
@SH4DY
SH4DY / RomanConversion.java
Created April 8, 2015 20:44
Roman number conversion, following the rules: Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases,[2] to avoid four characters being repeated in succession (such as IIII or XXXX) these can be reduced using subtractive notation as follows:[3][4] the numeral I can be placed before V …
public class RomanConversion {
public static void main(String[] args){
System.out.println(toRoman(1904));
}
public static String toRoman(int x){
StringBuilder sb = new StringBuilder();
String number = x + "";
@alphamu
alphamu / ExpandableTextView.java
Created April 24, 2015 01:17
A TextView and that expand and contract to show more or less content. Using ellipses with the TextView or the TextUtils to calculate where to ellipsize text can return the wrong result as it doesn't cater for new line characters. This code will consistently returns the correct number of lines.
import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.widget.FrameLayout;
import android.widget.TextView;
@SH4DY
SH4DY / Inflight.java
Created May 12, 2015 07:39
In-Flight Entertainment. Knapsack with only 2 integer values. https://www.interviewcake.com/question/inflight-entertainment
//We can do this with only one loop
//thanks to the fact that we are looking for
//EXACTLY 2 movies which match the length.
//Duplicates are not being counted
//as we check for a hit FIRST and then put the
//value of the first movie into the map.
public static boolean isTwoMovies(int fl, int[] ml){
HashMap<Integer, Boolean> hm = new HashMap<Integer, Boolean >();
@VladSumtsov
VladSumtsov / ColorChangeEvaluatorListener.java
Last active October 16, 2020 08:57
Change viewpager background color on swipe. ViewPager background color evaluator.
import android.animation.ArgbEvaluator;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import static android.support.v4.view.ViewPager.SCROLL_STATE_IDLE;
import static com.corewillsoft.loansdeposits.ui.utils.SwipeDirectionDetector.Direction.LEFT;
import static com.corewillsoft.loansdeposits.ui.utils.SwipeDirectionDetector.Direction.RIGHT;
public abstract class ColorChangeEvaluatorListener implements ViewPager.OnPageChangeListener {
@SH4DY
SH4DY / setBetween.java
Created May 31, 2015 19:27
Given an integer n and two indexes i, j s.t. i >= j. return a integer where all the bits between positions i and j (both inclusive) are set to 1. The bits outside of this range shall not be modified.
/*
Given an integer n and two indexes i, j s.t. i >= j.
return a integer where all the bits between positions i and j (both inclusive)
are set to 1. The bits outside of this range shall not be modified.
*/
//Comments assuming 8 bit numbers
//Goal is to make a mask with 1's at positions j through i
public static int setBetween(int n, int i, int j){ //n = 00010000, i = 3, j = 1
@mandybess
mandybess / ItemDecoration.java
Last active April 6, 2024 09:56
RecyclerView extension that "sticks" items in the center on scroll
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class ItemDecoration extends RecyclerView.ItemDecoration {
/**
*
* {@link #startPadding} and {@link #endPadding} are final and required on initialization
* because {@link android.support.v7.widget.RecyclerView.ItemDecoration} are drawn
@fdoyle
fdoyle / FixedTransformerViewPager.java
Last active August 22, 2022 11:02
PageTransform + padding on viewpager doesn't work. this fixes it
package com.foo.ui.view;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
/**
* Created by fdoyle on 11/2/15.
*/
@lopspower
lopspower / README.md
Last active May 28, 2025 13:09
Hexadecimal color code for transparency

Hexadecimal color code for transparency

Twitter

How to set transparency with hex value ?

For example, you want to set 40% alpha transparence to #000000 (black color), you need to add 66 like this #66000000.

Download This sample on Google Play Store