Skip to content

Instantly share code, notes, and snippets.

View yyunikov's full-sized avatar

Yuriy Yunikov yyunikov

View GitHub Profile
@yyunikov
yyunikov / UncaughtExceptionFilter.java
Last active August 29, 2015 14:08
Java: filter for handling and logging uncaught exceptions
/**
* Filter for handling and logging uncaught exceptions.
*/
@WebFilter(filterName="UncaughtExceptionFilter", urlPatterns = {"/*"})
public class UncaughtExceptionFilter implements Filter {
private static final Logger LOGGER = Logger.getLogger(UncaughtExceptionFilter.class);
@Override
public void doFilter(ServletRequest request, ServletResponse response,
@yyunikov
yyunikov / .gitignore
Created October 26, 2014 16:32
Android: .gitignore
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
@yyunikov
yyunikov / KeyboardUtils.java
Last active August 29, 2015 14:08
Android: some utilities for working with keyboard
public final class KeyboardUtils {
private KeyboardUtils(){}
public static void hideSoftKeyboard(final Activity activity)
{
final InputMethodManager imm = (InputMethodManager) activity.getSystemService(
Context.INPUT_METHOD_SERVICE);
if (activity.getWindow() != null && activity.getWindow().getCurrentFocus() != null) {
imm.hideSoftInputFromWindow(activity.getWindow().getCurrentFocus().getWindowToken(), 0);
@yyunikov
yyunikov / AsyncGenericLoader.java
Created October 26, 2014 17:09
Android: example implementation of Loader for generics
/**
* An {@link AsyncTaskLoader} implementation for loading objects like entities, cursors, etc.
* which takes care of delivering and reseting results. For Cursors you need to override
* onReleaseResources and perform all kind there, e.g. call close() method.
*/
public abstract class AsyncGenericLoader<T> extends AsyncTaskLoader<T> {
protected T mItems;
public AsyncGenericLoader(final Context context) {
@yyunikov
yyunikov / SearchViewFormatter.java
Last active August 29, 2015 14:12
Android: formatting search view and it's icons
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ImageSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SearchView;
import android.widget.TextView;
Unless specified otherwise, all of the below tinting applies to both Lollipop and pre-Lollipop using AppCompat v21. To use the support version of these attributes, remove the android namespace. For instance, "android:colorControlNormal" becomes "colorControlNormal". These attributes will be propagated to their corresponding attributes within the android namespace for devices running Lollipop. Any exceptions to this will be noted by including the "android:" prefix.
All Clickable Views:
-----------
* ripple effect (Lollipop only) -- "colorControlHighlight"
Status Bar:
------------
* background (Lollipop only) - "colorPrimaryDark"
@yyunikov
yyunikov / Hostname.java
Created January 15, 2015 14:52
Getting machine's hostname
public class SystemUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(SystemUtils.class);
private static final String HOSTNAME_VARIABLE = "HOSTNAME";
private static final String HOSTNAME_COMMAND = "hostname";
private SystemUtils() {}
@yyunikov
yyunikov / ObjectIdUtils.java
Created January 15, 2015 15:04
Example of generating unique id's using sha256
public final class ObjectIdUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectIdUtils.class);
private static final char[] BASE36 = {
'0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B',
'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T',
@yyunikov
yyunikov / ErrorHandler.java
Last active August 29, 2015 14:14
Example of error handling for Java web applications
@WebServlet("/error")
public class ErrorHandler extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
processError(request, response);
}
protected void doPost(HttpServletRequest request,
package com.pixite.fragment.widget;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable.Callback;
import android.view.Gravity;