Skip to content

Instantly share code, notes, and snippets.

View AndrewWang1993's full-sized avatar
🌴
On vacation

AndrewWang AndrewWang1993

🌴
On vacation
View GitHub Profile
@AndrewWang1993
AndrewWang1993 / PrimerCompare
Created January 8, 2015 16:35
素数排序(神奇的排序方式)
import java.math.BigInteger;
class PrimeCompare implements ICompare {
@Override
public boolean compare(String longString, String shortString) {
BigInteger product = new BigInteger("1");
for (int i = 0; i < longString.length(); i++) {
int index = longString.charAt(i) - 'A';
@AndrewWang1993
AndrewWang1993 / parser Online XML
Last active August 29, 2015 14:13
XML Media Parser(视频播放列表XML解析)
http://121.40.186.170/shipin/test1.php
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
.detectDiskReads().detectDiskWrites().detectNetwork()
.penaltyLog().build());
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
.detectLeakedSqlLiteObjects().detectLeakedClosableObjects()
.penaltyLog().penaltyDeath().build());
@AndrewWang1993
AndrewWang1993 / Android grid View XML
Last active August 29, 2015 14:13
以流的形式从URL获得XML信息
XmlPullParser xmlPullParser = null;
try {
InputStream is = util.getInput("http://121.40.186.170/shipin/test1.php");
XmlPullParserFactory pullFactory = XmlPullParserFactory.newInstance();
xmlPullParser = pullFactory.newPullParser();
xmlPullParser.setInput(is, "UTF-8");
} catch (Exception e) {
Log.v("TAG", e.toString());
}
ArrayList<Object> arrarys = util.ParseXml(xmlPullParser);
@AndrewWang1993
AndrewWang1993 / select some frames from a animation-list by using reflection
Last active August 29, 2015 14:16
select some frames from a animation-list by using reflection(使用反射从动画列表里选择几个图片来显示)
imageView = (ImageView) findViewById(R.id.myImageview);
small_imageView = (ImageView) findViewById(R.id.small_image);
imageView.setBackgroundResource(R.anim.m_anim);
animationDrawable = (AnimationDrawable) imageView.getBackground();
public void start(View view) { //A button click
if (!animationDrawable.isRunning()) {
animationDrawable.start();
controlFrame = new Thread(new Runnable() {
@Override
@AndrewWang1993
AndrewWang1993 / Use Bitmap-factory to measure pic width and height without allocated memory
Last active August 29, 2015 14:17
使用BitmapFactory对象测量一个图片的高和宽而不用分配内存
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; // Don't allocated memory
BitmapFactory.decodeResource(getResources(), R.id.myimage, options);
int imageHeight = options.outHeight;
int imageWidth = options.outWidth;
String imageType = options.outMimeType;
@AndrewWang1993
AndrewWang1993 / xxx.md
Last active August 29, 2015 14:18 — forked from wen-long/xxx.md

##科学上网之实践篇 ####1. HOSTS

hosts翻墙是我最厌恶的一种方式,原因如下

  1. 不全,一定没有 100% 收录的 hosts 文件
  2. 需要不定期更新,你根本不知道什么时候哪个 ip 会失效
  3. 会助长 GFW ,hosts 收集的 ip 也会被 GFW 维护人员知道,他们可以很轻松的屏蔽掉一个又一个可用 ip

但是在某些情况下,hosts 可以作为应急方案,还是给出若干 hosts 提供方网址

Hosts collection

@AndrewWang1993
AndrewWang1993 / quickSort
Created April 26, 2015 15:14
quickSort(快速排序)
/**
* Qucik sort 54,12,9,89,3,19,29,1 (1)选择54作为中轴 并定义tmp=54 1,12,9,89,3,19,29,1
* (2) 定义一个队尾游标,从后向前扫描,选择小于54的第一个元素,并把它复制到54这个位置 1,12,9,89,3,19,29,89
* (3)定义一个队首游标,从前向后扫描,扫描到大于54的第一个元素,并把它复制到1这个位置 1,12,9,29,3,19,29,89
* (4)继续步骤2的扫描,扫描小于54的第一个元素,并把它复制到89这个位置 1,12,9,29,3,19,54,89
* (5)继续步骤3的扫描,当扫描游标触碰到队尾游标时还未发现大于54的元素,则把tmp复制到队尾游标所指向的位置
* (1,12,9,29,3,19)54(89) (6)分别对54左右两个数组执行步骤1
*
* @param str
* @return
@AndrewWang1993
AndrewWang1993 / allSort_1(方法1)
Last active August 29, 2015 14:19
allSort(全排列)
public String[] allSort1(String str) {
int len = str.length();
if (len == 0) {
return null;
}
int count = 0, n = 1;
for (int i = 1; i <= len; i++) {
n *= i;
}
String[] strings = new String[n];
@AndrewWang1993
AndrewWang1993 / MD5
Last active August 29, 2015 14:20
Java MD5/SHA1 MessageDigest(MD5,SHA1加密)
import java.security.MessageDigest;
public class HashTest {
public static String HashTest(String message, String type) {
StringBuilder sBuilder = null;
try {
MessageDigest messageDigest = MessageDigest.getInstance(type);
messageDigest.update(message.getBytes());
sBuilder = new StringBuilder();