Skip to content

Instantly share code, notes, and snippets.

Avatar

Andj andjc

  • Melbourne, Australia
View GitHub Profile
@andjc
andjc / gitzip.sh
Created March 23, 2023 11:46 — forked from LeonardoCardoso/gitzip.sh
Zip folder ignoring files listed on .gitignore
View gitzip.sh
#...
function gitzip() {
git archive -o $@.zip HEAD
}
#... gitzip ZIPPED_FILE_NAME
@andjc
andjc / .bash_profile
Created March 23, 2023 11:44 — forked from signaltrace-dev/.bash_profile
Aliases for Git Bash - handy functions for common tasks
View .bash_profile
# generated by Git for Windows
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc
_gitzip(){
CURRDATE=`date +%Y%m%d`
NAME=${PWD##*/}
ARG=$1
LAST_COMMIT=$2
@andjc
andjc / gitzip.sh
Created March 23, 2023 11:44 — forked from dougalcampbell/gitzip.sh
gitzip -- create a zip file of a git project
View gitzip.sh
#!/bin/bash
##
## I usually put this in my .bashrc
##
## When in a git project dir, run 'gitzip foo' to get a 'foo.zip' in the parent
## directory.
gitzip() { git archive HEAD --format=zip --prefix="$*/" > ../"$*.zip"; }
@andjc
andjc / quarter.py
Created March 14, 2023 11:02 — forked from aodin/quarter.py
Python 3 datetime.date subclass
View quarter.py
import copy
import datetime
import pickle
# Each quarter corresponds to the following month and day combinations:
_q1 = (3, 31)
_q2 = (6, 30)
_q3 = (9, 30)
_q4 = (12, 31)
@andjc
andjc / thaisort.py
Created February 20, 2023 10:44 — forked from korakot/thaisort.py
Thai Sort
View thaisort.py
import icu
thkey = icu.Collator.createInstance(icu.Locale('th_TH')).getSortKey
words = 'ไก่ ไข่ ก ฮา'.split()
print(sorted(words, key=thkey)) # ['ก', 'ไก่', 'ไข่', 'ฮา']
@andjc
andjc / 1-unicode-js-regex.md
Created December 22, 2022 08:03 — forked from jakub-g/1-unicode-js-regex.md
Unicode-aware JavaScript regex cheat sheet
View 1-unicode-js-regex.md

Unicode-aware JavaScript regex (Unicode property escapes /\p{..}\P{..}/u) cheat sheet

Browser support MDN

@andjc
andjc / icu_totitle.py
Last active December 22, 2022 00:13
titlecasing: using pyicu, or to_title(), a wrapper to python's inbuilt method str.title().
View icu_totitle.py
from icu import Locale, UnicodeString
# loc = Locale.createCanonical("haw_US")
loc = Locale("haw_US")
s1 = "ʻōlelo hawaiʻi"
s2 = "oude ijssel "
print(UnicodeString(s1).toTitle(loc))
print(UnicodeString(s2).toTitle(Locale("nl_NL")).trim())
@andjc
andjc / docstrings.py
Created August 31, 2022 09:35 — forked from redlotus/docstrings.py
Google Style Python Docstrings
View docstrings.py
# -*- coding: utf-8 -*-
"""Example Google style docstrings.
This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.
Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including
@andjc
andjc / macos_lc_collate.md
Last active February 26, 2023 11:44
LC_COLLATE on macOS
View macos_lc_collate.md
$ ls -al /usr/share/locale/*/LC_COLLATE
lrwxr-xr-x  1 root  wheel    29 11 Jan 18:03 /usr/share/locale/af_ZA.ISO8859-1/LC_COLLATE -> ../la_LN.ISO8859-1/LC_COLLATE
lrwxr-xr-x  1 root  wheel    30 11 Jan 18:03 /usr/share/locale/af_ZA.ISO8859-15/LC_COLLATE -> ../la_LN.ISO8859-15/LC_COLLATE
lrwxr-xr-x  1 root  wheel    29 11 Jan 18:03 /usr/share/locale/af_ZA.UTF-8/LC_COLLATE -> ../la_LN.ISO8859-1/LC_COLLATE
lrwxr-xr-x  1 root  wheel    29 11 Jan 18:03 /usr/share/locale/af_ZA/LC_COLLATE -> ../la_LN.ISO8859-1/LC_COLLATE
lrwxr-xr-x  1 root  wheel    28 11 Jan 18:03 /usr/share/locale/am_ET.UTF-8/LC_COLLATE -> ../la_LN.US-ASCII/LC_COLLATE
lrwxr-xr-x  1 root  wheel    28 11 Jan 18:03 /usr/share/locale/am_ET/LC_COLLATE -> ../la_LN.US-ASCII/LC_COLLATE
-r--r--r--  1 root  wheel  2086 11 Jan 18:03 /usr/share/locale/be_BY.CP1131/LC_COLLATE
-r--r--r--  1 root  wheel  2086 11 Jan 18:03 /usr/share/locale/be_BY.CP1251/LC_COLLATE
@andjc
andjc / normalisation_sorting.md
Last active July 12, 2022 01:36
Unicode normalisation and default Python sorting
View normalisation_sorting.md

Snippet at https://github.com/enabling-languages/python-i18n/blob/main/snippets/sort_key_normalise.py

Default python sorting

If we take two strings that differ only in the Unicode normalisation form they use, would Python sort them the same? The strings éa (00E9 0061) and éa (0065 0301 0061) are canonically equivalent, but when we lists that only differ in the normalisation form of these two strings, we find the sort order is different.

>>> lc = ["za", "éa", "eb", "ba"]
>>> sorted(lc)
['ba', 'eb', 'za', 'éa']