Skip to content

Instantly share code, notes, and snippets.

View petri's full-sized avatar

Petri Savolainen petri

View GitHub Profile
@petri
petri / loader.py
Created January 5, 2017 13:30 — forked from joshbode/LICENSE.md
YAML Loader with include constructor (Python 3)
import yaml
import os.path
class LoaderMeta(type):
def __new__(metacls, __name__, __bases__, __dict__):
"""Add include constructer to class."""
# register the include constructor on the class
cls = super().__new__(metacls, __name__, __bases__, __dict__)
@petri
petri / mysql_backup.sh
Created October 26, 2017 08:52
mysql backup bash script
# list of databases to back up (all of them except information_schema, see below)
declare -a databases=("mydatabase" "mysql" "performance_schema")
# current day of week as a number from 1 to 7 starting monday
# for week of year use %V (for ISO weeks from 1 to 53)
day_num=$(date +%u)
echo backing up for day "$day_num"
# where the backups are written
cd /var/backups/mysql/daily
@petri
petri / copy_backups.sh
Created October 26, 2017 11:58
scp copy cron job
sshpass -f "/etc/default/backups/remotepasswd" scp -r /var/backups/mysql/weekly/* remotebackup@myserver.com:/var/backups/remotebackup/weekly/

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@petri
petri / Checksum.py
Last active January 24, 2023 21:50 — forked from Zireael-N/Checksum.py
Python script that calculates SHA1, SHA256, MD5 checksums of a given file. Similar to what you might accomplish with eg. ”openssl dgst -sha512 -binary my-downloaded-file.zip | base64”
#!/usr/bin/python
import hashlib
import os
import sys
if len(sys.argv) < 2:
sys.exit('Usage: %s filename' % sys.argv[0])
if not os.path.exists(sys.argv[1]):
code {
background-color: red !important;
color: blue;
border: solid thin gray;
}
@petri
petri / country_names.py
Last active October 22, 2018 18:40
Common disambiguated country names
"""
An attempt to produce a good enough list of commonly understandable country names
from pycountry straight-jacket names. Thus country names produced are without
prefixes such as "Republic of", and are also disambiguated from one another
(British & US Virgin Islands and Republic & Democratic Republic of Congo).
People living in the two countries both known as Congo call their country
either Congo-Kinshasa or Congo-Brazzaville, ie. adding the name of the capital;
we use that convention as an incremental means for additional disambiguation.
Also, liberty is taken to call Lao People's Democratic Republic just Laos, and
use the commonly known names North and South Korea, rather than the official
@petri
petri / hfst.rb
Last active December 9, 2018 18:02
hfst homebrew recipe
class Hfst < Formula
desc "Helsinki Finite-State Technology (library and application suite)"
homepage "https://hfst.github.io"
url "https://github.com/hfst/hfst/archive/v3.15.0.tar.gz"
sha256 "1ce90956d7c91d75e7c141e3852504b02728672239746858a141ccfae1712d19"
depends_on "automake"
depends_on "autoconf"
depends_on "libtool"
depends_on "bison"
@petri
petri / splicing.py
Created April 26, 2020 13:05
Get all ordered n-size splices of a sequence in Python
def splice(sequence, size):
"return a list of all ordered splices of given size"
ss = len(sequence)
return [sequence[i:i+size] for i in range(0, ss-size+1)]
@petri
petri / gist:46bb6b8eac8ea5b8f01c90e7414d7951
Last active September 27, 2020 18:42 — forked from HQJaTu/gist:345f7147065f1e10587169dc36cc1edb
Python asyncio ordering test - single-connection multiplex version with asyncio.Queue
#!/usr/bin/env python3
# vim: autoindent tabstop=4 shiftwidth=4 expandtab softtabstop=4 filetype=python
# Proof-of-Concept for https://stackoverflow.com/q/64017656/1548275
# Do Python asyncio Streams maintain order over multiple writers and readers?
import sys
import argparse