Skip to content

Instantly share code, notes, and snippets.

@z4none
z4none / test.py
Created November 22, 2023 04:31
image process
import cv2
import numpy as np
def preprocess_image(image):
# 二值化
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, threshold = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
cv2.imwrite("01_threshold.jpg", threshold)
return threshold
@z4none
z4none / simplest_player.c
Created June 17, 2022 01:36 — forked from mashingan/simplest_player.c
Simplest example of creating player using FFMpeg and SDL2. Currently with choppy audio playing.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <windows.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
//#include <libavutil/frame.h>
#include <SDL2/SDL.h>
@z4none
z4none / auto_refresh.js
Created December 17, 2021 02:11
auto refresh bookmarklet ( with progressbar )
javascript:
timeout=prompt("Set timeout [s]");
countdown=0;
current=location.href;
if(timeout>0)
reload();
else
location.replace(current);
function reload(){
if(countdown <= 0) {
#include <Windows.h>
#include <iostream>
#include <thread>
struct pipe
{
pipe()
{
SECURITY_ATTRIBUTES sa = { sizeof(sa), nullptr,true};
CreatePipe(&read, &write, &sa, 0);
@z4none
z4none / crash_dumper.cpp
Created December 14, 2020 15:46
auto gen dmp file when crash
#include <windows.h>
#include <tchar.h>
#include <dbghelp.h>
#include <string>
#include "crash_dumper.h"
#ifdef UNICODE
# define tstring wstring
@z4none
z4none / main.cpp
Created August 2, 2020 01:52
ATL load image from res #atl,#wtl
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define CURRENT_HINSTANCE ((HINSTANCE)&__ImageBase)
CImage image;
image.LoadFromResource(CURRENT_HINSTANCE, IDB_BG);
m_bg.Attach(image.Detach());
m_dc_bg.CreateCompatibleDC();
m_dc_bg.SelectBitmap(m_bg);
@z4none
z4none / pyqt
Created July 22, 2020 09:08
QFileSystemModel and QSortFilterProxyModel
class MyFileSystemModel(QFileSystemModel):
changed = pyqtSignal(str, int, int)
def __init__(self, parent=None):
self.checks = {}
super(MyFileSystemModel, self).__init__()
def flags(self, index):
return super(MyFileSystemModel, self).flags(index) | Qt.ItemIsUserCheckable
@z4none
z4none / has_arg.cpp
Last active August 2, 2020 01:32
[has_arg] 命令行参数知否包含指定 option #c,#c++
static bool
has_arg(int argc, char **argv, const char *arg)
{
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], arg) == 0) {
return true;
}
}
return false;
}
@z4none
z4none / strutil.h
Last active April 20, 2022 09:52
[c++ string startswith / endswith]
//
bool starts_with(const std::string & str, const std::string & sub, bool ignore_case=false)
{
int str_len = str.size();
int sub_len = sub.size();
if (str_len < sub_len) return false;
if (ignore_case)
{
@z4none
z4none / setUrlParams.js
Created March 29, 2020 16:29
set url params
// set url params
// if params not exists in url, then add params
// if params exists in url, then replace
function setUrlParams(url, params) {
var parts = url.split("?");
var path = parts[0]
var old_params = {};
if (parts.length == 1);
else {
var items = parts[1].split("&");