Skip to content

Instantly share code, notes, and snippets.

View derlin's full-sized avatar

Lucy Linder derlin

View GitHub Profile
@derlin
derlin / TotpGenerator.java
Created October 8, 2024 06:02
A simple java class to generate TOTP codes given a secret key
package com.divio.keycloak.e2e.utils;
import java.nio.ByteBuffer;
import java.util.Arrays;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
/**
* A simple TOTP (Time-based One-Time Password) generator, based on the algorithm described in RFC 6238.
@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 August 19, 2024 10:16
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 July 18, 2024 07:15
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">