Skip to content

Instantly share code, notes, and snippets.

View wangchauyan's full-sized avatar
🎯
Focusing

Chauyan wangchauyan

🎯
Focusing
View GitHub Profile
@wangchauyan
wangchauyan / Go_NewtonMethod.go
Created May 18, 2016 07:46
this is an example that shows how to use newton method by go.
package main
import (
"fmt"
"math"
)
func Newt(x float64) float64 {
@wangchauyan
wangchauyan / yuv2rgb
Created May 18, 2016 04:46
Convert YUV to RGB
const char fragmentShader_yuv420p[] =
{
"precision mediump float;\n"
"uniform sampler2D Ytex;\n"
"uniform sampler2D Utex,Vtex;\n"
"varying vec2 vTextureCoord;\n"
"void main(void) {\n"
" float nx,ny,r,g,b,y,u,v;\n"
" mediump vec4 txl,ux,vx;"
" nx=vTextureCoord[0];\n"
@wangchauyan
wangchauyan / NSDateLocalTime
Created April 7, 2016 07:56
Translate Server GMT +0 to specific local time
// gmt time string from server
NSString *gmtDateString = @"08/12/2013 21:01";
NSDateFormatter *df = [NSDateFormatter new];
[df setDateFormat:@"dd/MM/yyyy HH:mm"];
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
NSDate *date = [df dateFromString:gmtDateString];
//Create a date string in the local timezone
df.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:[NSTimeZone localTimeZone].secondsFromGMT];
@wangchauyan
wangchauyan / SearchViewFragment.java
Created February 14, 2016 14:26
Create a search view in your fragment
public void onCreateView (LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// enable options menus
setHasOptionsMenu(true);
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
@wangchauyan
wangchauyan / gist:36c2e16d774b7ec10f9a
Created May 25, 2015 09:00
Hide Android Virtual Keyboard
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
private Runnable mLoop = new Runnable() {
@Override
public void run() {
UsbDevice dev = sDevice;
if (dev == null)
return;
UsbManager usbm = (UsbManager) getSystemService(USB_SERVICE);
UsbDeviceConnection conn = usbm.openDevice(dev);
l("Interface Count: " + dev.getInterfaceCount());
@wangchauyan
wangchauyan / Path_Sum.java
Created December 20, 2014 09:23
Find a path through root to leaf which's value is equal to specific sum value. And then return true or fasle.
package wcy.leetcode.gist;
import java.util.LinkedList;
/**
* Created by ChauyanWang on 12/20/14.
*/
public class Path_Sum {
class TreeNode {
TreeNode left;
@wangchauyan
wangchauyan / Valid_Palindrome.java
Created December 20, 2014 07:50
Valid a string is palindrome or not.
package wcy.leetcode.gist;
/**
* Created by ChauyanWang on 12/20/14.
*/
public class Valid_Palindrome {
public boolean Solution (String s) {
if( s == null || s.length() == 0) return true;
s = s.toLowerCase();
int start = 0;
@wangchauyan
wangchauyan / Longest_Common_Prefix.java
Created December 20, 2014 07:29
Find out longest common prefix
package wcy.leetcode.gist;
/**
* Created by ChauyanWang on 12/20/14.
*/
public class Longest_Common_Prefix {
int findMinLength(String[] strs) {
int minLength = Integer.MAX_VALUE;
for(String str : strs) {
@wangchauyan
wangchauyan / romanToInt.java
Created December 19, 2014 17:12
Roman String to Integer
package wcy.leetcode.gist;
/**
* Created by ChauyanWang on 12/20/14.
*/
public class romanToInt {
int getInteger(char c) {
switch (c) {
case 'i': return 1;
case 'v': return 5;