Skip to content

Instantly share code, notes, and snippets.

#!/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
@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
@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 / 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 / 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 / fix-and-install-parallel-tools.sh
Created December 15, 2021 00:39
Patch and install Parallel tools on Rocky Linux or CentOS Linux
#!/usr/bin/env bash
if [[ ! -d "/media/$(whoami)/Parallels Tools" ]]; then
echo "Please mount parallels tools disk before install"
exit
fi
echo "Copy install files to /tmp/parallels_fixed"
cp -rf "/media/$(whoami)/Parallels Tools" /tmp/parallels_fixed
chmod -R 755 /tmp/parallels_fixed
cd /tmp/parallels_fixed/kmods
echo "Unpack prl_mod.tar.gz"
@xtman
xtman / build-jre.ps1
Created October 22, 2019 05:28
A PowerShell Script to build Java Runtime from JDK 11+
if (-Not (Test-Path Env:JAVA_HOME)) {
Write-Output "JAVA_HOME environment variable is not set."
Exit 1
}
$Env:PATH = $Env:JAVA_HOME + "\bin;" + $Env:PATH
$VERSION_LINE = (java -version 2>&1 | Select-String version)
$NAME = ($VERSION_LINE | %{$_.Line.Split(' ')[0];})
$VERSION = ($VERSION_LINE | %{$_.Line.Split(' ')[2].Replace("`"", "");})
@xtman
xtman / ScanForBadNames.java
Created October 7, 2019 01:23
Java app to search for illegal or problematic file names. The results are saved to a CSV file.
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.atomic.AtomicLong;
@xtman
xtman / Google_App_Script_Upload_Multi_Files_To_GoogleDrive_Form.html
Created December 6, 2016 04:36
Google App Script: Upload Multiple Files to Google Drive (Form.html)
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<form id="uploaderForm">
<label for="uploaderForm">Upload multiple Files</label>
<div>
<input type="text" name="applicantName" id="applicantName"
@xtman
xtman / Google_App_Script_Upload_Multi_Files_To_GoogleDrive_Code.gs
Last active September 19, 2023 08:31
Google App Script: Upload Multiple Files to Google Drive (Code.gs)
function doGet() {
return HtmlService.createHtmlOutputFromFile('Form').setSandboxMode(
HtmlService.SandboxMode.IFRAME);
}
function createFolder(parentFolderId, folderName) {
try {
var parentFolder = DriveApp.getFolderById(parentFolderId);
var folders = parentFolder.getFoldersByName(folderName);
var folder;