Skip to content

Instantly share code, notes, and snippets.

View chuck-sys's full-sized avatar

Cheuk Yin Ng chuck-sys

View GitHub Profile
@chuck-sys
chuck-sys / superdiff.py
Created September 7, 2022 04:28
Check for similar and duplicate code structures in a file. Usually unneeded for well-written code.
#!/usr/bin/env python
'''
Perform a O(n^2) code comparison on a singular file with n lines to find duplicate code structures.
Strips all spacings before and after each line for comparison.
Usually checks for 100% similarity, but you can adjust the sensitivity (switch to levenshtein distance).
Requires Python 3.6 or higher. tqdm is optional but would enhance the experience.
@chuck-sys
chuck-sys / i3blocks-contrib.patch
Created January 6, 2021 07:46
Patches i3blocks-contrib to make things better. This includes escaping strings manually and non-default temperature sensors. This also includes mediaplayer trunctation, which is needed for songs that don't respect screen real estate.
diff --git a/mediaplayer/mediaplayer b/mediaplayer/mediaplayer
index f78bd78..e86959b 100755
--- a/mediaplayer/mediaplayer
+++ b/mediaplayer/mediaplayer
@@ -27,6 +27,7 @@ use Env qw(BLOCK_INSTANCE);
use constant DELAY => 50; # Delay in ms to let network-based players (spotify) reflect new data.
use constant SPOTIFY_STR => 'spotify';
+use constant MAX_WIDTH => 80;
@chuck-sys
chuck-sys / face-detect.cc
Created November 1, 2020 00:22
OpenCV face detection via webcam. CPU intensive, captures frame-by-frame instead of in-memory modifications.
// g++ face-detect.cc `pkg-config --cflags --libs opencv4` -o face-detect
// Remember to install vtk libraries or nothing will link.
#include <opencv2/imgcodecs.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <vector>
#include <chrono>
@chuck-sys
chuck-sys / random-caps.c
Last active October 17, 2020 16:20
Randomly capitalizes input from stdin, and spits it back out into stdout. Useful when piping.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#define BUFFER_SIZE 4096
#define CAPS_PROBABILITY 50
char randomCaps(char c) {
if (isalpha(c)) {
@chuck-sys
chuck-sys / upload.php
Created March 20, 2020 16:31
For when you want to transfer files from a phone to a computer.
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["file"])) {
for ($i = 0; $i < sizeof($_FILES["file"]["name"]); $i++) {
$filename = $_FILES["file"]["name"][$i];
$tempname = $_FILES["file"]["tmp_name"][$i];
if ($_FILES["file"]["error"][$i] != 0) {
// Error handling
echo "File $filename uploaded with error</br>";
continue;
@chuck-sys
chuck-sys / scraper.py
Created July 29, 2019 16:26
A web scraper that grabs pages from Cucumber Quest and logs the date as well as the number of pages uploaded on that date in CSV form.
#!/usr/bin/python
from urllib.request import urlopen
from bs4 import BeautifulSoup
from collections import defaultdict
BASEURL = 'http://cucumber.gigidigi.com/cq'
FIRSTPAGE = f'{BASEURL}/page-1'
def print_counts_to_file(fn, d):
with open(fn, 'w') as f:
@chuck-sys
chuck-sys / todo.sh
Last active May 4, 2019 21:42
A simple todo list using rofi and your local ~/.todo_list file
#!/usr/bin/env sh
TODO_FN="$HOME/.todo_list"
GREEN='#11dd11'
YELLOW='#ffff85'
if [ ! -f "$TODO_FN" ]; then
touch "$TODO_FN"
fi
TODOS=$(sed '/^$/D' "$TODO_FN" | sort)
@chuck-sys
chuck-sys / main.cc
Created April 11, 2019 23:08
ffmpeg tutorial
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
#include <cstdio>
#include <string>
#include <fstream>
#include <iostream>
@chuck-sys
chuck-sys / README.md
Last active May 14, 2018 22:49
Facebook Messenger message analyzer

Tested with Python 3.

BeautifulSoup is required to parse the HTML that the individual messages are in.

To use, first download a copy of your Facebook data. Then, run this script with the directory of all of your messages (usually something like /messages/). The analysis will come out through the standard output in CSV format, for easy importing into your favourite spreadsheet for analysis.

I would recommend adding separate columns after importing into your favourite spreadsheet for analysis. You may also (if you want to) train a neural network on the natural language (however basic and abbreviated).

@chuck-sys
chuck-sys / README.md
Last active August 9, 2018 18:35
Whatsapp data cruncher

Tested with Python 3. Doesn't work with Python 2 unless you change some of the format specifiers.

This script outputs to standard output in TSV format, and thus can be easily imported into any spreadsheet program for easy data visualization. I import it into Google Sheets, and do stuff there.

Feel free to add more analysis things.