Skip to content

Instantly share code, notes, and snippets.

@lyaotian
lyaotian / ViewUtils.kt
Created April 12, 2018 03:48
Create background of android shadow view,
package com.kollway.booktravel.util
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RoundRectShape
import android.support.annotation.ColorRes
import android.support.v4.content.ContextCompat
import android.view.Gravity
@lyaotian
lyaotian / Main.java
Created September 30, 2013 11:59
Delete all .svn files which inside the svn project directory.
package com.lyaotian.test;
import java.io.File;
import java.io.IOException;
/**
* User: Yaotian Leung
* Date: 9/30/13
* Time: 4:53 PM
*/
/*
* Compress the native libs located at libs/armeabi/ into archive file
* libs/armeabi.jar
* Destination directory inside the archive is lib/armeabi/<libs>
*
* Example of .jar needed structure :
* |---lib/
* |---armeabi/
* |---libdatabase_sqlcipher.so
* |---libsqlcipher_android.so
@lyaotian
lyaotian / gist:5938376
Created July 6, 2013 02:22
byte array vs int
public static int byteArrayToInt(byte[] b) {
return b[3] & 0xFF |
(b[2] & 0xFF) << 8 |
(b[1] & 0xFF) << 16 |
(b[0] & 0xFF) << 24;
}
public static byte[] intToByteArray(int a){
return new byte[] {
(byte) ((a >> 24) & 0xFF),
@lyaotian
lyaotian / gist:5801382
Created June 17, 2013 23:18
Depth-first Search
procedure DFS(G,v):
label v as explored
for all edges e in G.adjacentEdges(v) do
if edge e is unexplored then
w ← G.adjacentVertex(v,e)
if vertex w is unexplored then
label e as a discovery edge
recursively call DFS(G,w)
else
label e as a back edge
@lyaotian
lyaotian / gist:5801368
Created June 17, 2013 23:17
Breadth-first Search
procedure BFS(G,v):
create a queue Q
enqueue v onto Q
mark v
while Q is not empty:
t ← Q.dequeue()
if t is what we are looking for:
return t
for all edges e in G.adjacentEdges(t) do
o ← G.adjacentVertex(t,e)
@lyaotian
lyaotian / smack
Created June 14, 2013 05:50
Smack VCard usage
VCard vCard = new VCard();
SmackConfiguration.setPacketReplyTimeout(300000);
ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());
vCard.load(connection, user_mail_id);
Log.d("Vcard XML", vCard.toXML()); // complete VCard information
byte[] bs = vCard.getAvatar(); // Avtar in byte array convert it to Bitmap