Skip to content

Instantly share code, notes, and snippets.

View huangcd's full-sized avatar

Huang Chongdi huangcd

  • Microsoft Research Asia
  • Beijing, China
View GitHub Profile
@huangcd
huangcd / getStatusBarHeight
Created April 9, 2015 07:02
get staus bar of Android's height
public static int getStatusBarHeight(Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
result = context.getResources().getDimensionPixelSize(resourceId);
}
return result;
}
@huangcd
huangcd / NewsList.java
Created October 6, 2014 03:38
SwipeRefreshLayout and ListView
newsList.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(
AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
@huangcd
huangcd / sendEmail.java
Created September 26, 2014 05:39
Android send email
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MyActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
@huangcd
huangcd / volleySetTimeout.java
Created September 26, 2014 02:40
volley set timeout
myRequest.setRetryPolicy(new DefaultRetryPolicy(
MY_SOCKET_TIMEOUT_MS,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
using System;
using System.Collections.Generic;
using System.Threading;
/// <summary>
/// http://zrx.zhaojie.me/20140721/
/// 问题在于firstBuffer.Flush的时候会有新的item加到secondBuffer里面,导致一次Flush的时候firstBuffer的元素有可能比secondBuffer的元素少。
/// 解决方法是先把buffer给缓存出去(先缓存secondBuffer再缓存firstBuffer),然后再Flush。
/// </summary>
namespace IBufferTest
@huangcd
huangcd / wordpress_md.rb
Created July 23, 2012 08:12 — forked from DrayChou/wordpress_md.rb
wordpress blog -> markdown
# coding: utf-8
require 'rubygems'
require 'hpricot'
require 'fileutils'
require 'time'
require 'ya2yaml'
require 'nokogiri'
require 'cgi'
require 'chinese_pinyin'
@huangcd
huangcd / map.cs
Created July 18, 2012 00:23
a map function like python in C#
public static IEnumerable<TResult> Map<in TSource, TResult>(IEnumerable<TSource> sources, Func<TSource, TResult> mapper)
{
foreach (var source in sources)
{
yield return mapper(source);
}
}