Skip to content

Instantly share code, notes, and snippets.

View ads901119's full-sized avatar

Alan Sha ads901119

View GitHub Profile
@jgilfelt
jgilfelt / DrawerSafeViewPager.java
Last active December 19, 2015 09:39
DrawerLayout friendly ViewPager that will ignore rogue touch events from the bezel swipe gesture.
/*
* Copyright (C) 2013 readyState Software Ltd
*
* 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
@romannurik
romannurik / AndroidCreateGhostIcon.java
Created June 14, 2013 06:28
Android ColorMatrixColorFilter example: Creates a 'ghost' bitmap version of the given source drawable (ideally a BitmapDrawable). In the ghost bitmap, the RGB values take on the values from the 'color' argument, while the alpha values are derived from the source's grayscaled RGB values. The effect is that you can see through darker parts of the …
/**
* Creates a 'ghost' bitmap version of the given source drawable (ideally a BitmapDrawable).
* In the ghost bitmap, the RGB values take on the values from the 'color' argument, while
* the alpha values are derived from the source's grayscaled RGB values. The effect is that
* you can see through darker parts of the source bitmap, while lighter parts show up as
* the given color. The 'invert' argument inverts the computation of alpha values, and looks
* best when the given color is a dark.
*/
private Bitmap createGhostIcon(Drawable src, int color, boolean invert) {
int width = src.getIntrinsicWidth();
@Rplus
Rplus / Custom.css
Last active December 17, 2015 15:08
Themes for Chrome Developer Tools:
/*
just highlight .selector-matches~
screenshot: http://i.imgur.com/Do3BDTQ.png
ref: http://www.lostsaloon.com/technology/using-a-custom-stylesheet-in-a-web-browser/
css file located on:
Mac: ~/Library/Application Support/Google/Chrome/Default/User StyleSheets/Custom.css
PC: C:\Users\[USER NAME]\AppData\Local\Google\Chrome\User Data\Default\User StyleSheets\Custom.css
Ubuntu (Chromium): ~/.config/chromium/Default/User StyleSheets/Custom.css
(Google Chrome): ~/.config/google-chrome/Default/User StyleSheets/Custom.css
@keyboardr
keyboardr / FragmentUtils.java
Last active March 8, 2019 05:30
Utility method for getting the appropriate parent of a Fragment for a given callback interface.
import android.support.v4.app.Fragment;
public class FragmentUtils {
/**
* @param fragment
* The Fragment whose parent is to be found
* @param parentClass
* The interface that the parent should implement
* @return The parent of fragment that implements parentClass,
@HarishChaudhari
HarishChaudhari / country-code-to-currency-code-mapping.csv
Last active March 18, 2025 03:33
Country, Country Code, Currency code mapping in CSV format Taken from https://gist.github.com/304261 Contains 249 countries.
Country CountryCode Currency Code
New Zealand NZ New Zealand Dollars NZD
Cook Islands CK New Zealand Dollars NZD
Niue NU New Zealand Dollars NZD
Pitcairn PN New Zealand Dollars NZD
Tokelau TK New Zealand Dollars NZD
Australian AU Australian Dollars AUD
Christmas Island CX Australian Dollars AUD
Cocos (Keeling) Islands CC Australian Dollars AUD
Heard and Mc Donald Islands HM Australian Dollars AUD
@amlcurran
amlcurran / MultiContentAdapter.java
Last active December 11, 2015 03:38
Simple Adapter which can handle multiple input cursors asynchronously (ideal for usage with CursorLoaders)
/* Copyright 2013 Alex Curran
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
distributed under the License is distributed on an "AS IS" BASIS,
@galex
galex / SherlockMapFragment.java
Created December 27, 2012 21:13
Google Maps v2 + ActionBarSherlock = SherlockMapFragment
package com.actionbarsherlock.app;
import android.app.Activity;
import android.support.v4.app.Watson.OnCreateOptionsMenuListener;
import android.support.v4.app.Watson.OnOptionsItemSelectedListener;
import android.support.v4.app.Watson.OnPrepareOptionsMenuListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.internal.view.menu.MenuItemWrapper;
import com.actionbarsherlock.internal.view.menu.MenuWrapper;
@smugen
smugen / form.py
Created November 30, 2012 06:12
Taiwan R.O.C. ID validation with wtforms from part of my project
# -*- coding: UTF-8 -*-
from flaskext.wtf import Form, TextField, PasswordField, RecaptchaField, \
AnyOf, NoneOf, Regexp, Email, Required, EqualTo, Recaptcha
from wtforms.validators import StopValidation
from flask import request, session
import model
# 身份證字號格式驗證
def check_ID(form, field):
locations = dict(zip([c for c in 'ABCDEFGHJKLMNPQRSTUVXYWZIO'], range(10,36)))
@brutus
brutus / wtf-html5.py
Created November 8, 2012 11:58
HTML5 in WTForms
# -*- coding: UTF-8 -*-
"""
WTForms HTML5 Widgets
~~~~~~~~~~~~~~~~~~~~~
This modul adds HTML5 widgets to WTForms_.
It supports the new INPUT types for fields and also sets some of the
new INPUT attributes automatically (based on widget type and what kind of
@ccarpenterg
ccarpenterg / customized.py
Created November 2, 2012 22:10
A Tornado decorator to display a customized UI for authenticated users.
def customized(default=None, template=None):
def decorator(method):
@functools.wraps(method)
def wrapper(self, *args, **kargs):
self.template = default
if self.current_user:
self.template = template
return method(self, *args, **kargs)
return wrapper
return decorator