Skip to content

Instantly share code, notes, and snippets.

@weiancheng
weiancheng / delay.cpp
Last active November 1, 2021 08:18
delay for seconds delay for milliseconds delay for nanoseconds
/// using standard library
#include <chrono>
#include <thread>
std::this_thread::sleep_for(std::chrono::seconds(10)); // delay for 10s
std::this_thread::sleep_for(std::chrono::milliseconds(10)); // delay for 10ms
std::this_thread::sleep_for(std::chrono::nanoseconds(10)); // delay for 10ns
@weiancheng
weiancheng / git.mk
Last active June 17, 2020 08:27
[git command] #git #gitignore
# get remote repository
git clone URL
# create new branch
git branch new_branch_name
git branch
git push origin new_branch_name
# delete branch
git branch -d branch_name
@weiancheng
weiancheng / build.gradle
Created June 17, 2020 07:25
[Android makes AAR file] #android #gradle #aar
// ...
android {
// ...
libraryVariants.all { variant ->
variant.outputs.all { output ->
variant.assemble.doLast {
exec {
def localProperties = new File(rootDir, "local.properties")
@weiancheng
weiancheng / test.cpp
Last active June 19, 2020 03:55
[Android ATrace] #android #jni #native #systrace #atrace #c++
#include <dlfcn.h>
void (*ATrace_beginSection) (const char *sectionName);
void *(*ATrace_endSection) (void);
void *(*ATrace_isEnabled) (void);
typedef void (*fp_ATrace_beginSection) (const char *sectionName);
typedef void *(*fp_ATrace_endSection) (void);
typedef void *(*fp_ATrace_isEnabled) (void);
@weiancheng
weiancheng / shader_handler.cpp
Created May 5, 2020 09:45
[Android OpenGL Shader] #android #opengl #shader #glsl
#include "shader_handler.h"
bool ShaderHandler::initializeShader() {
// vertex shader
vshader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vshader, 1, &vertex_shader_source, nullptr);
glCompileShader(vshader);
GLint vertex_compiled;
glGetShaderiv(vshader, GL_COMPILE_STATUS, &vertex_compiled);
@weiancheng
weiancheng / render_frame.cpp
Created May 5, 2020 09:00
[Android OpenGL Texture] #android #opengl #texture2d
#include "render_frame.h"
void RenderFrame::initialize() {
glGenTextures(1, &colorAttachmentId);
glBindTexture(GL_TEXTURE_2D, colorAttachmentId);
glBindTexture(GL_TEXTURE_2D, 0); // unbind
}
void RenderFrame::submitFrame(void *frame) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_RED);
@weiancheng
weiancheng / build.gradle
Created November 1, 2019 10:01
[Fragment] #android #jetpack #fragment #navigation
dependencies {
// Navigation library
def nav_version = "2.0.0"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
}
@weiancheng
weiancheng / build.gradle
Last active November 1, 2019 10:47
[Camera] #android #jetpack #camera #camerax #media
dependencies {
// CameraX core library
def camerax_version = "1.0.0-alpha06"
// CameraX view library
def camerax_view_version = "1.0.0-alpha03"
// CameraX extensions library
def camerax_ext_version = "1.0.0-alpha03"
implementation "androidx.camera:camera-core:$camerax_version"
// If you want to use Camera2 extensions
implementation "androidx.camera:camera-camera2:$camerax_version"
@weiancheng
weiancheng / BreadthFirsSearch.java
Last active October 16, 2019 10:17
[tree for Java] #data structure #tree #bfs #dfs
import java.util.*;
public class BreathFirstSearch {
public static bfs(Node tree) {
// using queue for BFS algorithm
Queue<Node> queue = new LinkedList<>();
// enqueue root
queue.add(tree);
@weiancheng
weiancheng / MainActivity.kt
Last active September 22, 2019 02:37
[export frame to jpeg] #kotlin #android #media #video
// the path of output folder
private val EXPORT_FOLDER = "/your/folder/path/"
// this is a trigger for enabling/disabling the function
private var exportFrameToJpeg = false
// a counter which acculating the number of video frame
private var nbFrame = 0
// the prepare function of decoder