Skip to content

Instantly share code, notes, and snippets.

@loganlinn
loganlinn / ClickHouseDialect.kt
Last active July 16, 2020 17:51
Beginnings of ClickHouse <> JetBrains/Exposed integration
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.vendors.DataTypeProvider
import org.jetbrains.exposed.sql.vendors.FunctionProvider
import org.jetbrains.exposed.sql.vendors.VendorDialect
import java.util.*
object ClickHouseDataTypeProvider : DataTypeProvider() {
override fun binaryType(): String = "String"
override fun binaryType(length: Int): String = "FixedString($length)"
override fun blobType(): String = "String"
@loganlinn
loganlinn / dodns-refresh.sh
Created June 19, 2020 07:43
BASH script for dynamic DNS for domain managed with Digital Ocean
#!/usr/bin/env bash
# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Exit on error inside any functions or subshells.
set -o errtrace
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR
set -o nounset
# Catch the error in case mysqldump fails (but gzip succeeds) in `mysqldump |gzip`
set -o pipefail
# Turn on traces, useful while debugging but commented out by default
@loganlinn
loganlinn / Makefile
Created June 16, 2020 23:08
Base Makefile for Python project
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
help: ## displays available make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help
@loganlinn
loganlinn / compression_ratio.sql
Last active September 19, 2020 01:13
ClickHouse Queries
SELECT table,
name,
formatReadableSize(c) compressed,
formatReadableSize(u) uncompressed,
floor((c/u) * 100, 4) percent
FROM (
SELECT table,
name,
sum(data_compressed_bytes) c,
sum(data_uncompressed_bytes) u
class Nbconvert < Formula
include Language::Python::Virtualenv
desc "Converts notebooks to various other formats via Jinja templates"
homepage "https://nbconvert.readthedocs.io/"
url "https://files.pythonhosted.org/packages/04/f2/299fa4b15155ecbe2aefe7412249f0dd91f953b7a9b37c336317d564a1ca/nbconvert-5.6.1.tar.gz"
sha256 "21fb48e700b43e82ba0e3142421a659d7739b65568cc832a13976a77be16b523"
head "https://github.com/jupyter/nbconvert.git"
depends_on "[email protected]"
include Makefile.venv
Makefile.venv:
curl \
-o Makefile.fetched \
-L "https://github.com/sio/Makefile.venv/raw/v2020.05.07/Makefile.venv"
echo "ab60a72bb9215935db6d3d8cd0f8dfe8cd48e8cca0235227ecc476f1cff46e51 *Makefile.fetched" \
| sha256sum --check - \
&& mv Makefile.fetched Makefile.venv
name: datalab-dev
channels:
- conda-forge
- defaults
dependencies:
- jinja2=2.11.2=pyh9f0ad1d_0
- jupyter_client=6.1.3=py_0
- jupyter_core=4.6.3=py37hc8dfbb8_1
- jupyterlab=1.2.6=py_0
- jupyterlab_server=1.0.7=py_0
#
# act: activates a pyenv-managed virtualenv based on args, pwd, or fzf choice
#
act() {
local env="$1"
if [[ "$#" -ne "0" ]]; then
pyenv activate "$1"
return 0
# @description clones git repository (including submodules) and changes working
# directory to it. If `directory` not specified, uses $PROJECTS.
# and if that's not set, fallsback to current directory.
#
# @example gclone [email protected]:loganlinn/blog.git
# @example gclone loganlinn/blog
function gclone {
emulate -L zsh
if [[ "$#" -eq 0 ]]; then
import logging
import click
class ColorFormatter(logging.Formatter):
colors = {
"error": dict(fg="red"),
"exception": dict(fg="red"),
"critical": dict(fg="red"),