Skip to content

Instantly share code, notes, and snippets.

@qhm123
qhm123 / BTree.java
Created March 23, 2013 08:09
B-tree
package com.simpledb.misc;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BTree {
private static final int ORDER = 3;
@qhm123
qhm123 / gist:4192565
Created December 3, 2012 03:50
How exactly to use Notification.Builder
Intent notificationIntent = newIntent(ctx, YourClass.class);
PendingIntent contentIntent = PendingIntent.getActivity(ctx,
YOUR_PI_REQ_CODE, notificationIntent,
PendingIntent.FLAG_CANCEL_CURRENT);
NotificationManager nm = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
Resources res = ctx.getResources();
Notification.Builder builder = newNotification.Builder(ctx);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.some_img)
@qhm123
qhm123 / gist:4192553
Created December 3, 2012 03:48
android get drawable int value by drawable name
public static int getImage(String pic) {
if (pic == null || pic.trim().equals("")) {
return R.drawable.icon;
}
Class draw = R.drawable.class;
try {
Field field = draw.getDeclaredField(pic);
return field.getInt(pic);
} catch (SecurityException e) {
return R.drawable.icon;
@qhm123
qhm123 / gist:3087415
Created July 11, 2012 01:43
js relative path to absolute
// If it's a relative path, we need to make it absolute, using the
// reader's location (not the active component's location).
if (!url.match(/^\//)) {
var link = document.createElement('a');
link.setAttribute('href', url);
url = link.href;
delete(link);
}
@qhm123
qhm123 / proxy.js
Created June 21, 2012 04:53
跨域代理
function getHTTPObject() {
var http = false;
//Use IE's ActiveX items to load the file.
if (typeof ActiveXObject != 'undefined') {
try {
http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
@qhm123
qhm123 / gist
Created May 23, 2012 02:34
WebView截图
Picture picture = webView.capturePicture();
int weight = picture.getWidth();
int height = picture.getHeight();
if (weight > 0 && height > 0) {
Bitmap bitmap = Bitmap.createBitmap(weight, height,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
picture.draw(canvas);
}