Skip to content

Instantly share code, notes, and snippets.

@mrhether
mrhether / NeedGithubUsername.java
Last active November 10, 2015 20:22
Github names are vital and the smaller they are the better! This tool finds you the smallest github name available.
private final Log logger = LogFactory.getLog(getClass());
public void given_i_need_a_github_name() {
List<String> names = getNamePerms(6);
for (String name : names) {
System.out.print('.');
RestTemplate restTemplate = new RestTemplate();
String url = "http://github.com/" + name;
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
if (response.hasBody() && response.getBody().contains("This is not the web page you are looking for")) {
public static Bitmap addGradient(Bitmap src, @ColorInt int start, @ColorInt int end, int alpha) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap overlay = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(overlay);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
LinearGradient shader = new LinearGradient(0, 0, 0, h, start, end, Shader.TileMode.CLAMP);
@mrhether
mrhether / SpacesItemDecoration.java
Created August 24, 2015 22:01
The following code will handle padding on StaggeredGridLayoutManager, GridLayoutManager, and LinearLayoutManager.
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;
/**
* Created by markhetherington on 15-08-17.
*/
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
private int halfSpace;
@mrhether
mrhether / printInside.java
Created August 6, 2015 15:47
Reflection Method to print the insides of an object
public static String printInsides(Object object) {
StringBuilder result = new StringBuilder();
String newLine = "\n";
result.append( object.getClass().getName() );
result.append( " Object { " );
result.append(newLine);
//determine fields declared in this class only (no fields of superclass)
Field[] fields = object.getClass().getDeclaredFields();
@mrhether
mrhether / DynamicHeightViewPager
Created May 27, 2015 17:52
DynamicHeightViewPager
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int height = 0;
for(int i = 0; i < getChildCount(); i++) {
View child = getChildAt(i);
child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int h = child.getMeasuredHeight();
if(h > height) height = h;
}