Skip to content

Instantly share code, notes, and snippets.

View wangchauyan's full-sized avatar
🎯
Focusing

Chauyan wangchauyan

🎯
Focusing
View GitHub Profile
@wangchauyan
wangchauyan / xz-backdoor.md
Created April 1, 2024 02:27 — forked from thesamesam/xz-backdoor.md
xz-utils backdoor situation

FAQ on the xz-utils backdoor

Background

On March 29th, 2024, a backdoor was discovered in xz-utils, a suite of software that gives developers lossless compression. This package is commonly used for compressing release tarballs, software packages, kernel images, and initramfs images. It is very widely distributed, statistically your average Linux or macOS system will have it installed for

@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"
class EnumExample {
private enum Status {
Init, Success, Failed, Loading
}
public static enum ProcessStatus {
LOAD_STAGE(Status.Init),
END_STAGE(Status.Failed);
@wangchauyan
wangchauyan / checkMediacodecAbility.java
Created February 19, 2017 13:33
Check How Many MediaCodec Instance Your Device Support
public static int getMaxCodecInstanceByName(String name) {
final Vector<MediaCodec> codecs = new Vector<>();
final MediaFormat format = MediaFormat.createVideoFormat(MIME_TYPE, 1920, 1080);
MediaCodec codec = null;
for (int i = 0; i < max; i++) {
try {
codec = MediaCodec.createDecoderByType(MediaFormat.MIMETYPE_VIDEO_AVC);
codec.configure(format, null, null, 0);
codec.start();
@wangchauyan
wangchauyan / climbStairs.java
Last active October 13, 2019 15:12
LeetCode - Climb stairs
/*
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
*/
public class Solution {
public int climbStairs(int n) {
if(n == 0 || n == 1) return 1;
int finalWays = 0;
int f1 = 1;
int f2 = 1;
@wangchauyan
wangchauyan / Word-Break.java
Last active October 13, 2019 15:11
Word Break
/*
Give a string, and a dictionary, find out if this string could be segmented by a space which's substring
are in this dictionary.
For example, String "leetcode", dictionary ["leet", "code"],
then return true, cause this string could be segmented as "leet code";
*/
public class Solution {
public boolean wordBreak(String str, Set<String> dict) {
/*
Implement an algorithm to detemine if a string has all unique characters.
What if you cannot use additional data structure.
*/
// solution 1, with an array, time complexity = O(n), space complexity = O(1)
public class solution {
public boolean isUniqueChar(String str) {
if(str == null || str.length() == 0)
return false;
@wangchauyan
wangchauyan / MainActivity.kt
Created April 18, 2019 22:53
Android Onboarding Pop Animation
private fun hopAnimation() {
val animation = bottomContainer
.animate()
.translationYBy(-40f)
.alpha(0.9f)
.setDuration(400)
animation.withEndAction {
bottomContainer
.animate()
.alpha(0.5f)
@wangchauyan
wangchauyan / PerformanceTesting.java
Created December 21, 2017 13:44
Performance Testing 1
// Generate data
int arraySize = 32768;
int data[] = new int[arraySize];
Random rnd = new Random(0);
for (int c = 0; c < arraySize; ++c)
data[c] = rnd.nextInt() % 256;
// notice !!!
Arrays.sort(data);
@wangchauyan
wangchauyan / UploadImage.java
Created March 13, 2017 11:39
Google Volley Upload Images
public class PhotoMultipartRequest<T> extends Request<T> {
private static final String FILE_PART_NAME = "file";
private MultipartEntityBuilder mBuilder = MultipartEntityBuilder.create();
private final Response.Listener<T> mListener;
private final File mImageFile;
protected Map<String, String> headers;