Skip to content

Instantly share code, notes, and snippets.

View spiritedRunning's full-sized avatar
🎯
Focusing

Zach Liu spiritedRunning

🎯
Focusing
View GitHub Profile
@spiritedRunning
spiritedRunning / log.h
Last active November 29, 2022 02:22
print timestamp in log using C/C++
#define PRINT(tag, fmt, ...) printf("%s %s " fmt"", get_cur_time(), tag, ##__VA_ARGS__)
inline char* get_cur_time() {
static char s[32] = {0};
time_t t;
struct tm* ltime;
struct timeval stamp;
gettimeofday(&stamp, NULL);
ltime = localtime(&stamp.tv_sec);
@spiritedRunning
spiritedRunning / mark.py
Last active December 8, 2021 04:10
图片标注 按修改时间升序给图片加时间戳
import cv2
import os, time
samplePath = "sample"
index = 0
def mark(filename):
old_img_path = os.path.join(samplePath, filename)
print("old_path: ", old_img_path)
@spiritedRunning
spiritedRunning / ScannerMain.java
Last active December 2, 2021 05:19
OJ 输入读取方式
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
// 直接读取多行数据
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int a = sc.nextInt();
int b = sc.nextInt();
@spiritedRunning
spiritedRunning / YUVUtil.cpp
Last active December 1, 2021 03:30
YUV操作工具类
bool UYVYRotate90(unsigned char *src, unsigned char *dst, int width, int height) {
const int copyBytes = 4;
const int bytesPerLine = width << 1;
const int step = height << 2;
const int offset = (height - 1) * bytesPerLine;
if (NULL == dst) {
return false;
}
unsigned char *dest = dst;
@spiritedRunning
spiritedRunning / tempcolor2.java
Last active August 18, 2021 05:26
温度值简单转换
int fromColor = Color.rgb(0, 0, 255);
int toColor = Color.rgb(255, 0, 0);
for (int i = 0; i < data.length; i++) {
double ratio = (data[i] - mintemp) / (maxtemp - mintemp);
int red = (int) (Color.red(fromColor) * (1.0f - ratio) + Color.red(toColor) * ratio);
int green = (int) (Color.green(fromColor) * (1.0f - ratio) + Color.green(toColor) * ratio);
int blue = (int) (Color.blue(fromColor) * (1.0f - ratio) + Color.blue(toColor) * ratio);
@spiritedRunning
spiritedRunning / convert.java
Last active August 18, 2021 07:57
彩虹色多色阶热力图温度映射
private float a, b, c, d;
private int red, green, blue;
private static final float minTemp = 20.0f;
private static final float maxTemp = 40.0f;
private void setAbcd() {
a = minTemp + (maxTemp - minTemp) * 0.2121f;
b = minTemp + (maxTemp - minTemp) * 0.3182f;
c = minTemp + (maxTemp - minTemp) * 0.4242f;
d = minTemp + (maxTemp - minTemp) * 0.8182f;
@spiritedRunning
spiritedRunning / tempColor.java
Last active August 18, 2021 05:17
色值映射
Bitmap image = Bitmap.createBitmap(32, 32, Bitmap.Config.ARGB_8888);
int[] list = GetSingleColorList(Color.rgb(0, 0, 255), Color.rgb(255, 0, 0), (int) (maxtemp - mintemp) + 1);
//根据温度获取每个点的颜色
for (int i = 0; i < data.length; i++) {
int c = GetColor(list, data[i], maxtemp, mintemp);
image.setPixel(i % 32, i / 32, c);
}
@spiritedRunning
spiritedRunning / Daemon.cpp
Last active March 30, 2021 08:54
进程守护 使用信号量通知
#include <jni.h>
#include "ProcessWatcher.h"
extern ProcessBase *g_process;
JNIEXPORT jboolean JNICALL
Java_com_example_free_watcher_Watcher_createWatcher(JNIEnv *env, jobject instance, jstring objname_,
jstring type_) {
const char *objname = env->GetStringUTFChars(objname_, 0);
const char *type = env->GetStringUTFChars(type_, 0);
@spiritedRunning
spiritedRunning / JNIClass.java
Last active March 30, 2021 08:58
进程保护 监听文件是否存在
public class JNIClass {
static {
System.loadLibrary("loopjni");
}
public static native void createProcess(String pid);
public void restartActivity() {
try {