Skip to content

Instantly share code, notes, and snippets.

private int getActionBarHeight() {
int actionBarHeight = getSupportActionBar().getHeight();
if (actionBarHeight != 0)
return actionBarHeight;
final TypedValue tv = new TypedValue();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
} else if (getTheme().resolveAttribute(com.actionbarsherlock.R.attr.actionBarSize, tv, true))
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
import com.google.auto.value.AutoValue;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Marks an {@link AutoValue @AutoValue}-annotated type for proper Gson serialization.
* <p>
@Hackforid
Hackforid / fetch_proxy.py
Created September 29, 2014 16:51
fetch proxies
# -*- coding:utf-8 -*-
import time
import requests
import gevent
from gevent.pool import Pool
from pyquery import PyQuery as pq
@Hackforid
Hackforid / ListView Utils
Created October 15, 2014 03:34
Get ListView Height
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
public static String dump(Object object) {
Field[] fields = object.getClass().getDeclaredFields();
StringBuilder sb = new StringBuilder();
sb.append(object.getClass().getSimpleName()).append('{');
boolean firstRound = true;
for (Field field : fields) {
if (!firstRound) {
sb.append(", ");
@Hackforid
Hackforid / styles.xml
Created October 22, 2014 11:56
Android Style
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>
<style name="AppBaseTheme.Compact" parent="AppBaseTheme">
</style>
<style name="AppTheme.Preference" parent="android:Theme.Holo.Light"/>
#!/bin/bash
#
# git-svn-diff originally by (http://mojodna.net/2009/02/24/my-work-git-workflow.html)
# modified by mike@mikepearce.net
# modified by aconway@[redacted] - handle diffs that introduce new files
# modified by t.broyer@ltgt.net - fixes diffs that introduce new files
# modified by m@rkj.me - fix sed syntax issue in OS X
# modified by rage-shadowman - cleaned up finding of SVN info and handling of path parameters
# modified by tianyapiaozi - cleaned up some diff context lines
#
@Hackforid
Hackforid / gist:3b6792333299f47e70b6
Created April 21, 2015 07:19
Stetho Okhttp Picasso
public class App extends Application {
private static final String PICASSO_CACHE = "picasso-cache";
private static final long PICASSO_CACHE_SIZE = 100 * 1024 * 1024;
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
@Hackforid
Hackforid / gist:e38740495c5e8ddd43c9
Created May 12, 2015 12:48
Sqlalchemy批量插入
conn.execute(MyTable.insert(), [{'color': 'blue'},
{'color': 'red'},
{'color': 'green'}])
@Hackforid
Hackforid / gist:5760951e1fd6d5cd9e85
Created May 13, 2015 03:08
ThreadRequestContext
# -*- coding: utf-8 -*-
import threading
class ThreadRequestContext(object):
"""A context manager that saves some per-thread state globally.
Intended for use with Tornado's StackContext.