Skip to content

Instantly share code, notes, and snippets.

View EvanLyu732's full-sized avatar
:octocat:
Welcome!

EvanLyu732 EvanLyu732

:octocat:
Welcome!
View GitHub Profile
@EvanLyu732
EvanLyu732 / use_rsync_backup_root.md
Created September 13, 2024 07:09
rsync backup entire root folder
sudo rsync -avxHAX --progress --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*/.cache/*","/var/cache/*","/var/tmp/*"} / /path/to/backup/destination/

Let's break down this rsync command:

  1. sudo: Run the command with root privileges, necessary for accessing all system files.

  2. rsync: The command itself.

@EvanLyu732
EvanLyu732 / transformer.c
Created June 28, 2024 05:41
transformer in pure c written by chatgpt.
/* This file is written by chatgpt */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SEQUENCE_LENGTH 512 ///< Maximum sequence length for input data
#define MAX_EMBEDDING_DIM 512 ///< Maximum embedding dimension for the model
@EvanLyu732
EvanLyu732 / ps_all_processes_mem_usage.md
Created November 10, 2023 02:01
linux monitor process usage using command line
$ watch ps -e -o pid,user,%mem,cmd --sort=-%mem
@EvanLyu732
EvanLyu732 / yuyv2bgr.h
Created November 1, 2023 08:03
yuyv2bgr
#pragam once
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Conversion algorithm from: https://en.wikipedia.org/wiki/YUV
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constexpr int ConvertYUYV_2_BGR(const int nWidth, const int nHeight,
u_char *pPixSrc, u_char *pPixDst) {
if (nullptr == pPixSrc || nullptr == pPixDst) {
std::cerr << "FAIL: Cannot convert YUYV to BGR from/to NULL pixel buffers"
<< std::endl;
return -1;
#!/bin/bash
#
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#

First your OpenCV should be compiled with CUDA (and OpenGL) support to test all this features. Detect your CUDA hardware with OpenCV CUDA by:

#include <iostream>
using namespace std;

#include <opencv2/core.hpp>
using namespace cv;

#include <opencv2/cudaarithm.hpp>
using namespace cv::cuda;
@EvanLyu732
EvanLyu732 / test_callback_timer.cpp
Created September 28, 2023 02:30
A program scenario in C++ that bind timer to a callback function
#include <atomic>
#include <iostream>
#include <thread>
#include <unistd.h>
// A simple timer that use atomic bool to identify it's status.
struct Timer {
bool overdue() { return flag_.load() ? true : false; }
void reset_timer() {
@EvanLyu732
EvanLyu732 / checklist.md
Created September 6, 2023 03:06
linux-performance-analysis-in-60-secs

from https://www.brendangregg.com/Articles/Netflix_Linux_Perf_Analysis_60s.pdf

uptime # Load averages to identify if load is increasing or  decreasing (compare 1-, 5-, and 15-minute averages).
dmesg -T | tail # Kernel errors including OOM events.
vmstat -SM 1 # System-wide statistics: run queue length, swapping, overall CPU usage.
mpstat -P ALL 1 # Per-CPU balance: a single busy CPU can indicate poor thread scaling.
pidstat 1 # Per-process CPU usage: identify unexpected CPU consumers, and user/system CPU time for each process.
iostat -sxz 1 # Disk I/O statistics: IOPS and throughput, average wait time, percent busy.
@EvanLyu732
EvanLyu732 / cpp_stm_free_tutorial.md
Created August 7, 2023 03:00 — forked from graninas/cpp_stm_free_tutorial.md
Software Transactional Memory in C++: Pure Functional Approach (tutorial)

Software Transactional Memory in C++: pure functional approach (Tutorial)

In this article I’ll tell you about my pure functional library for Software Transactional Memory (STM) that I’ve built in C++. I adopted some advanced functional programming concepts that make it composable and convenient to use. Its implementation is rather small and robust, which differentiates the library from competitors. Let’s discuss what STM is and how to use it.

- Boost C++ Libraries (https://www.boost.org/)
- Facebook's Folly (https://github.com/facebook/folly)
- Electronic Arts' EASTL (https://github.com/electronicarts/EASTL)
- Bloomberg's BDE (https://github.com/bloomberg/bde)
- Google's Abseil (https://abseil.io/)
- The Awesome Cpp list (https://github.com/fffaraz/awesome-cpp) with
dozens more