Skip to content

Instantly share code, notes, and snippets.

View shayousefi's full-sized avatar

Shahin Yousefi shayousefi

View GitHub Profile
@shayousefi
shayousefi / color_conversion.py
Created August 8, 2016 17:10
RGB<->Hex conversion using NumPy.
import numpy as np
def rgb_to_hex(rgb: np.ndarray) -> str:
rgb = rgb.reshape(3)
return '#{:02X}{:02X}{:02X}'.format(*rgb)
def hex_to_rgb(hex_str: str) -> np.ndarray:
hex_str = hex_str.strip()
@shayousefi
shayousefi / pantone_skintone.json
Created July 17, 2016 20:52
Pantone SkinTone color hex values.
{
"5R04": "C6A098",
"5R05": "C39990",
"5R06": "C1958C",
"5R07": "BE9186",
"4R04": "C6A096",
"4R05": "C39A8E",
"4R06": "C19487",
"4R07": "BC8D80",
"4R08": "B58678",
@shayousefi
shayousefi / EndlessScrollSupport.java
Created August 27, 2015 00:30
Adding endless scroll support to a RecyclerView.
/**
* A class that adds endless scroll support to a {@link RecyclerView}.
*/
public class EndlessScrollSupport {
private final RecyclerView recyclerView;
private EndlessScrollListener endlessScrollListener;
private int startPage = 0;
/** The current offset index of data you have loaded. */
@shayousefi
shayousefi / ItemClickSupport.java
Last active October 13, 2018 13:41
Adding item click support to a RecyclerView.
/**
* A class that adds item click support to a {@link RecyclerView}.
*
* @author Hugo Visser
* @see <a href="http://www.littlerobots.nl/blog/Handle-Android-RecyclerView-Clicks/">
* Getting your clicks on RecyclerView</a>
*/
public class ItemClickSupport {
private final RecyclerView recyclerView;
private OnItemClickListener itemClickListener;
/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@shayousefi
shayousefi / ListRecyclerAdapter.java
Last active September 13, 2015 00:48
A RecyclerView adapter backed by a list.
/*
* Copyright 2015 Shahin Yousefi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@shayousefi
shayousefi / TextUtils.java
Created July 8, 2015 12:02
Formatting a number count to an abbreviated form with the appropriate unit suffix.
/**
* Formats a number count to an abbreviated form with the appropriate unit suffix.
*
* @param count number count
* @param <T> type of number
* @return An abbreviated count with the appropriate unit suffix.
*/
public static <T extends Number & Comparable<? super T>> String shortCount(T count) {
String base = "##0";
String[] suffixes = {"'K'", "'M'", "'B'"};
@shayousefi
shayousefi / GoogleUtils.java
Last active August 29, 2015 14:24
Handling Google API Java Client metadata request and response with RxJava
/**
* Sends the {@code AbstractGoogleJsonClientRequest} to the server and returns an {@code Observable}
* that emits the parsed {@code GenericJson} response.
*
* <dl>
* <dt><b>Scheduler:</b></dt>
* <dd>{@code executeAsObservable} does not operate by default on a particular
* {@link rx.Scheduler}.</dd>
* </dl>
*
@shayousefi
shayousefi / EllipsizingTextView.java
Last active April 15, 2022 20:05
A TextView that ellipsizes more intelligently. This class supports ellipsizing multiline text through setting android:ellipsize and android:maxLines.
/*
* Copyright (C) 2011 Micah Hainline
* Copyright (C) 2012 Triposo
* Copyright (C) 2013 Paul Imhoff
* Copyright (C) 2014 Shahin Yousefi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*