Skip to content

Instantly share code, notes, and snippets.

View dlebech's full-sized avatar

David Volquartz Lebech dlebech

View GitHub Profile
@dlebech
dlebech / mysql_to_gcs.php
Created March 12, 2024 14:58
mysqldump-php to Google Cloud Storage with gzip streaming
<?php
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
# Install requirements:
# composer require ifsnop/mysqldump-php
# composer require google/cloud-storage
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/config.php';
@dlebech
dlebech / Gerrit comment formatting
Last active January 17, 2024 10:34
Comment formatting in Gerrit
The documentation for Gerrit when it comes to formatting comments is quite lacking. Here is short list created by trial and error and looking at the source code in:
./gerrit-gwtexpui/src/main/java/com/google/gwtexpui/safehtml/client/SafeHtml.java
Lists:
* List item 1
* List item 2
- List item 1
- List item 2
@dlebech
dlebech / .vimrc
Last active October 9, 2023 12:53
My .vimrc, .zshrc and vscode user settings
set nocompatible
filetype off
" Plug is installed with https://github.com/junegunn/vim-plug
"call plug#begin()
"Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
"Plug 'vim-airline/vim-airline'
"Plug 'ctrlpvim/ctrlp.vim'
"Plug 'Yggdroot/indentLine'
"
@dlebech
dlebech / binomial_prob.sql
Last active August 15, 2022 20:41
Binomial probability calculation function in SQL (BigQuery)
-- Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
-- Calculate the probability of k successes for n trials with probability of success k,
-- using the binomial distribution.
-- Calculate the binomial coefficient using the "multiplicative formula"
CREATE OR REPLACE FUNCTION functions.binomial_coef(n INT64, k INT64) AS ((
-- k!/(n!*(n-k)!)
-- We're going to have a hard time doing factorials here,
-- but based on the "multiplicative formula" in Wiki, it should be possible:
@dlebech
dlebech / tokenizer.js
Last active August 11, 2022 13:34
Keras text tokenizer in JavaScript with minimal functionality
// Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
class Tokenizer {
constructor(config = {}) {
this.filters = config.filters || /[\\.,/#!$%^&*;:{}=\-_`~()]/g;
this.lower = typeof config.lower === 'undefined' ? true : config.lower;
// Primary indexing methods. Word to index and index to word.
this.wordIndex = {};
this.indexWord = {};
@dlebech
dlebech / mongodbio.py
Last active July 15, 2022 22:20
Super-simple MongoDB Apache Beam transform for Python
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
"""MongoDB Apache Beam IO utilities.
Tested with google-cloud-dataflow package version 2.0.0
"""
__all__ = ['ReadFromMongo']
import datetime
@dlebech
dlebech / uwsgi-emperor
Created February 2, 2015 16:09
uWSGI start/stop script that can be added to /etc/init.d on Ubuntu Linux and used with "sudo service uwsgi-emperor start"
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: uwsgi-emperor
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the uwsgi emperor app server
# Description: starts uwsgi emperor app server using start-stop-daemon
@dlebech
dlebech / cache.py
Created March 20, 2016 16:51
Python LRU cache that works with coroutines (asyncio)
"""Global LRU caching utility. For that little bit of extra speed.
The caching utility provides a single wrapper function that can be used to
provide a bit of extra speed for some often used function. The cache is an LRU
cache including a key timeout.
Usage::
import cache
@cache.memoize
@dlebech
dlebech / fasttext_langdetect_example.py
Last active May 17, 2021 20:45
Quick example of language detection with fasttext small model (less than 1MB model)
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
# Prepare with: pip install fasttext
# Tested with Python 3.9
import urllib.request
import fasttext
# Download small model (917KB)
# Other options: https://fasttext.cc/docs/en/language-identification.html
@dlebech
dlebech / imagemagick-oneliners.bash
Created May 2, 2021 20:05
Some useful one-liners for Imagemagick, including resizing, convert to pencil and fake miniature
# Make * work in bash or zsh:
# zsh
setopt extendedglob
# bash
shopt -s extglob
# Resize all images (in-place) in a folder
# to 1200 pixels on the longest side
mogrify -resize 1200 *.jpg