Skip to content

Instantly share code, notes, and snippets.

View dlebech's full-sized avatar

David Volquartz Lebech dlebech

View GitHub Profile
@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 / redis.go
Created May 19, 2016 07:16
Connecting to Redis in Golang
package services
import (
"os"
"time"
log "github.com/Sirupsen/logrus"
"github.com/garyburd/redigo/redis"
)
@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

This is a copy of a support chat between Intercom and myself. It's referred to from a blog post I wrote here.

David:

Hello there

I wanted to make a report of what I believe to be a security hole in your app.

I recently had a support chat session with a service I use while being logged-in.

@dlebech
dlebech / letsencrypt.sh
Created February 25, 2016 09:04
Just so I don't forget, the one-liner to use for generating letsencrypt certs.
# One-liner for creating a certificate on a webserver.
# Install the letsencrypt github repo and then
./letsencrypt-auto certonly --webroot -w /var/www/websitename/or/whatever -d domain.com
@dlebech
dlebech / selenium.js
Created December 18, 2015 15:39
Node + Mocha + Selenium
'use strict';
const By = require('selenium-webdriver').By,
until = require('selenium-webdriver').until,
firefox = require('selenium-webdriver/firefox'),
test = require('selenium-webdriver/testing'),
utils = require('../utils'),
server = require('../server');
describe('register', function() {
@dlebech
dlebech / error.js
Last active December 15, 2015 19:16
Just testing out Error subclassing
'use strict';
class MyError extends Error {}
class MyVerboseError extends Error {
constructor(message) {
super(message);
this.name = this.constructor.name; // ! important
this.message = message;
Error.captureStackTrace(this, this.name);
@dlebech
dlebech / difflibtest.py
Created February 17, 2015 20:37
Python difflib test to see the difference between the different ratios.
#!/bin/env python
import difflib
import random
import string
import time
repetitions = 100000
# Pre-generate strings between 5 and 30 characters in length.
strings = [''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(random.randint(10,30))) for i in range(repetitions*2)]
@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 / .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'
"