Skip to content

Instantly share code, notes, and snippets.

View gchenfc's full-sized avatar

Gerry Chen gchenfc

View GitHub Profile
@gchenfc
gchenfc / encrypt.sh
Created February 26, 2024 01:15
Convenience shell functions to tar-encrypt (and decrypt-untar) folders with gpg (default AES256)
# See also: README.
# These are convenience functions to encrypt and decrypt files and folders.
function help() {
echo "Functions:"
echo " compress_folder (in_folder) [out_file_basename]"
echo " decompress_folder (in_file) [out_folder]"
echo "Call with -h for help."
}
@gchenfc
gchenfc / prepForArxiv.sh
Last active August 1, 2022 15:15
A handy script to sanitize a latex project for an arXiv submission (Mac)
# This script sanitizes a latex project for an arXiv submission.
# Specifically, it "sanitizes" the project by removing any files that are not used in compilation.
#
# Usage:
# cd latex_folder_root
# ./prepForArxiv.sh
# (generates a zip archive in /tmp/archive.zip)
#
# It is not exhaustive, but it is pretty good and should work for most cases.
# Also, it does not remove comments within the latex source.
@gchenfc
gchenfc / natgeoexplorersdatascrape.ipynb
Last active June 24, 2022 02:45
NatGeoExplorersDatascrape.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gchenfc
gchenfc / primetest_minimal.py
Last active January 29, 2022 01:33
A minimal version of the Miller Rabin primality test that can be copy-pasted for quick-and-dirty prime checking.
"""
See also: https://gist.github.com/gchenfc/a0efa92e954a609bf031f7da4cc8dd70
Gauranteed correct up to 318,665,857,834,031,151,167,461 (which is >2^64 so works for any uint64)
Usage:
print(is_probably_prime(17)) # True
print(is_probably_prime(12345678910987654321)) # True
print(is_probably_prime(46)) # False
"""
_known_primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37)
@gchenfc
gchenfc / primetest.py
Created January 28, 2022 23:33
Simple implementation of the Miller-Rabin primality test.
"""Simple implementation of the Miller-Rabin primality test.
Usage:
```
from primetest import is_prime
print(is_prime(17)) # True
print(is_prime(12345678910987654321)) # True
print(is_prime(46)) # False
```
bool painton[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1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