Skip to content

Instantly share code, notes, and snippets.

View shawnfeng0's full-sized avatar
💭
Keep thinking

Shawn Feng shawnfeng0

💭
Keep thinking
View GitHub Profile
@shawnfeng0
shawnfeng0 / current_utc_time.c
Created April 27, 2023 18:20 — forked from jbenet/current_utc_time.c
work around lack of clock_gettime in os x
/*
author: jbenet
os x, compile with: gcc -o testo test.c
linux, compile with: gcc -o testo test.c -lrt
*/
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <chrono>
class Timer {
public:
Timer() { start_ = std::chrono::high_resolution_clock::now(); }
~Timer() = default;
template <typename T>
uint64_t elapsed() {
auto now = std::chrono::high_resolution_clock::now();
#include <archive.h>
#include <archive_entry.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <string>
#include <vector>
#pragma once
#include <tuple>
#include <type_traits>
template <typename... DestroyFuncs>
class DestroyGuard {
public:
~DestroyGuard() {
call_all_destroy_callbacks(
@shawnfeng0
shawnfeng0 / temp_file_write.c
Last active July 26, 2024 14:09
temp_file_write function
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>
#include <sys/file.h>
#include <time.h>
static inline long long get_uptime_ms() {
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
@shawnfeng0
shawnfeng0 / usbrelay_control.py
Last active April 1, 2026 02:35
USB Relay (16C0:05DF) Linux Control Script (Anti-Freeze Feature Report Edition)
#!/usr/bin/env python3
import os
import fcntl
import sys
import argparse
import glob
CMD_OPEN = 0xFF
CMD_CLOSE = 0xFD
HIDIOCSFEATURE_9 = 0xC0094806 # Write feature report