Skip to content

Instantly share code, notes, and snippets.

View derlin's full-sized avatar

Lucy Linder derlin

View GitHub Profile
@derlin
derlin / generate_pdf_from_image_directories.py
Created September 11, 2022 16:58
Generate PDFs out of image directories (for mangas mostly)
"""
Generate PDFs out of directories with images.
If the directories have a sub-structure, the --levels argument can be used. For example, given the following structure:
├─ MyManga_volumes
│ └── Vol1
│ ├── 001.png
│ ├── 002.jpeg
│ ├── ...
@derlin
derlin / waitForText.js
Last active September 22, 2021 16:16
Get notified when something (pattern, text) appears on a page. Great for pages showing logs !
function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
function toArrayOfPatterns(searchPatterns) {
// transform strings, patterns, or arrays of strings/patterns into arrays of patterns
return (Array.isArray(searchPatterns) ? searchPatterns : [searchPatterns])
.map((pattern) => typeof pattern == "string" ? new RegExp(pattern) : pattern);
}
async function isNotificationPermissionGranted() {
// ask for permission to show notification
@derlin
derlin / DockerCassandra-InitDb.md
Last active April 27, 2024 18:29
Dockerfile and entrypoint example in order to easily initialize a Cassandra container using *.sh/*.cql scripts in `/docker-entrypoint-initdb.d`

Initializing a Cassandra Docker container with keyspace and data

This gist shows you how to easily create a cassandra image with initial keyspace and values populated.

It is very generic: the entrypoint.sh is able to execute any cql file located in /docker-entrypoint-initdb.d/, a bit like what you do to initialize a MySQL container.

You can add any *.sh or *.cql scripts inside /docker-entrypoint-initdb.d, but note that:

  • *.sh files will be executed BEFORE launching cassandra
@derlin
derlin / Dockerfile
Last active February 2, 2021 03:01
Dockerfile with openpose CPU & Python 3 API
# Dockerfile for openpose <https://github.com/CMU-Perceptual-Computing-Lab/openpose>
# CPU only and with the Python 3 API avilable.
# Last tested commit ID: 0a7d5b8e22db0b26b14ca3f3f8060299d3ee967d
# Author: Lucy Linder
FROM ubuntu:18.04
# get dependendies
# this will also install caffe-cpu so we don't have to build it from source (a pain in the schtroumpf)
RUN apt-get update && \
import unicodedata
SG_DIACRITICS = [
0x0300, # COMBINING GRAVE ACCENT
0x0301, # COMBINING ACUTE ACCENT
0x0302, # COMBINING CIRCUMFLEX ACCENT
0x0308, # COMBINING DIAERESIS
# TODO: what about ǜ (U+01DC) and ß ?
]
@derlin
derlin / leipzig.py
Last active December 2, 2022 22:39
Python scripts for downloading Leipzig Corpora Languages
import tarfile
from html.parser import HTMLParser
from io import BytesIO
import requests
import os
class LeipzigResourceFinder(HTMLParser):
"""Find available leipzig resources for a given language."""
@derlin
derlin / BERT_install_with_setuptools.md
Last active July 2, 2019 06:35
Make google BERT easily installable using setuptools

Make google's BERT easy to install using setuptools. Should keep working on later commits.

Usage (assuming a virtualenv):

# clone bert
git clone https://github.com/google-research/bert
# get gist files
wget \
https://gist.githubusercontent.com/derlin/2196c17e72a344e45d6f8676d0be53db/raw/fix_imports.py
@derlin
derlin / get_text.py
Created April 23, 2019 08:01
Get text from WikiExtractor.py output
#!/usr/bin/env python
"""
Usage:
1. clone https://github.com/attardi/wikiextractor
2. download a pages-articles.xml.bz2 archive from WikiMedia dumps
3. use wikiextractor to convert the XML articles into JSON:
```
python WikiExtractor.py -b 100M alswiki-latest-pages-articles.xml.bz2
@derlin
derlin / PCSwissFrench.keylayout
Last active August 4, 2023 06:48
PC layout Swiss-French for MacOS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!-- Key mapping for PC-style keys with Swiss French layout -->
<!--Last edited by Ukelele version 2.2.8 on 2015-06-02 at 17:10 (CEST)-->
<keyboard group="0" id="16101" name="PC Swiss French" maxout="1">
<layouts>
<layout first="0" last="0" modifiers="commonModifiers" mapSet="ISO"/>
</layouts>
<modifierMap id="commonModifiers" defaultIndex="0">
<keyMapSelect mapIndex="0">

Barcode checker

A little PYTHON code for basic barcode checking before using an ESC/POS printer barcode renderig function. This ensures the barcode will be renderer correctly.

Note that most ESC/POS printers, such as the Epson TM T20ii, don't usually bother with the checksums and stuff; they only care about the character set and the length of the string. There are also some special formats, for example the CODE128 should be prefixed with {B for alphanumeric barcodes, etc.