Skip to content

Instantly share code, notes, and snippets.

View zhiyb's full-sized avatar
👻

Norman Zhi zhiyb

👻
View GitHub Profile
@zhiyb
zhiyb / main.py
Last active December 13, 2022 23:58
Collect all HDD temperatures through drivetemp and output highest temperature for fancontrol
#!/usr/bin/env python3
import subprocess, time, os
import json
sleep = 10
outfile = "/tmp/hddtemp_input"
tmpfile = f"{outfile}.tmp"
while True:
proc = subprocess.run(["sensors", "-j", "drivetemp-scsi-*-*"], capture_output=True)
@zhiyb
zhiyb / upload.php
Last active October 14, 2020 20:10
POST method ping-pong and hex dump
<?php
require 'dbconf.php';
$db = new mysqli($dbhost, $dbuser, $dbpw, $dbname);
if ($db->connect_error)
die("Connection failed: " . $db->connect_error . "\n");
$db->set_charset('utf8mb4');
$name = basename($_SERVER['SCRIPT_FILENAME'], ".php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
@zhiyb
zhiyb / channel.c
Created May 25, 2019 14:19
Ancient BMP file RGB channel conversion code
#include <stdio.h>
#include <inttypes.h>
#define NONE 0
#define BLUE 1
#define GREEN 2
#define RED 3
int getRGB(void)
{
@zhiyb
zhiyb / README.md
Last active May 25, 2019 14:10
Ancient hard link management script

Hardlink management scripts

Git pull etc. do not preserve hardlinks.
I sometimes need hardlinks inside repo, point to somewhere outside, so I wrote these scripts to manage hardlinks.

@zhiyb
zhiyb / Makefile
Last active January 1, 2019 13:23
A random Ingress question...
SHELL := /bin/bash
.PHONY: run
run: ap
time ./$<
ap: ap.o
$(CXX) -o $@ $^ -O3
%.o: %.cpp
@zhiyb
zhiyb / .gitignore
Last active October 11, 2020 22:16
Nintendo Switch screenshot management shell(python) script
*/
@zhiyb
zhiyb / main.c
Last active June 20, 2018 14:44
An inefficient compression algorithm
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char *argv[])
{
if (argc != 3)
return 1;
int seq_size = atoi(argv[1]);
int repeat = atoi(argv[2]);
@zhiyb
zhiyb / rmsame.sh
Created April 2, 2018 03:40
Find files with the same sha1sum
#!/bin/bash
declare -a sum file
cksum="$(eval sha1sum $(find . -type f -printf '"%p"\n'))"
sum=($(echo "$cksum" | cut -d\ -f 1))
eval file=($(echo "$cksum" | cut -d\ -f 3- | awk '{print "\""$0"\""}'))
for ((i=1;i<${#sum[@]};i++)); do
for ((j=0;j<i;j++)); do
if [ "${sum[i]}" == "${sum[j]}" ]; then
echo "${sum[i]} | ${file[i]} | ${file[j]}" #; rm "${file[i]}"
@zhiyb
zhiyb / Makefile
Last active February 21, 2018 23:17
Makefile for downloading all Minecraft client & server jars
MANIFEST_URL ?= https://launchermeta.mojang.com/mc/game/version_manifest.json
.DELETE_ON_ERROR:
.PHONY: manifest
manifest:
curl -s -o version_manifest.json -L $(MANIFEST_URL)
$(MAKE) JSON_URL="`jq -r < version_manifest.json '.versions|.[]|.url' | xargs`" versions
VERSIONS := $(basename $(notdir $(JSON_URL)))
@zhiyb
zhiyb / Makefile
Last active January 4, 2018 17:42
Combine images into PDF
IN := $(sort $(wildcard pages/front*.png))
IN += $(sort $(wildcard pages/prelim*.png))
IN += $(sort $(wildcard pages/page*.png))
OUT := $(IN:%.png=%.pdf)
PDF := $(shell basename "$$PWD" | sed 's/ /\\ /g').pdf
.PHONY: all
all: $(PDF)