Skip to content

Instantly share code, notes, and snippets.

@xtman
xtman / crc32.py
Created January 29, 2022 09:03
Generate CRC32 checksum for a file
import zlib
import sys
BUFFER_SIZE=8192
def get_crc32(path):
with open(path, 'rb') as f:
crc = 0
while True:
data = f.read(BUFFER_SIZE)
@xtman
xtman / CRC32Utils.java
Created January 29, 2022 09:11
Java utility to generate CRC32 checksums
package unimelb.utils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
@xtman
xtman / detect_file_name_encoding.py
Created September 20, 2022 08:02
python code to detect file name encoding
import os
import chardet
for n in os.listdir('.'):
print(chardet.detect(os.fsencode(n)))
@xtman
xtman / count-files-in-dir.sh
Created June 12, 2024 04:35
count-files-in-dir.sh
#!/bin/sh
[ $# -ne 1 ] && echo "$(basename $0) <dir>" && exit 1
[ ! -d $1 ] && echo "$1 is not a directory." && exit 1
find "$1" -type f | wc -l
#!/bin/sh
[ $# -ne 1 ] && echo "$(basename $0) <dir>" && exit 1
[ ! -d $1 ] && echo "$1 is not a directory." && exit 1
if [ $(uname) == "Darwin" ]; then
find "$1" -type f -print0 | xargs -0 stat -f '%z ' | paste -sd+ - | bc
else
find "$1" -type f -printf %s\\n | paste -sd+ | bc