Skip to content

Instantly share code, notes, and snippets.

View cb109's full-sized avatar
💭
🍴 🐘

Christoph Bülter cb109

💭
🍴 🐘
View GitHub Profile
@cb109
cb109 / tokenstring.py
Last active October 3, 2016 21:37
Resolve tokens in strings
# :coding: utf-8
"""Replace tokens in strings."""
import re
DOUBLE_CURLY_BRACED_TOKEN = r"{{\s*(\w+)\s*}}" # E.g.: '{{ token }}'
@cb109
cb109 / django-rest-boilerplate.py
Last active June 13, 2017 14:52
Generate code to expose Django models via the django-rest-framework
# !/bin/python
# -*- coding: utf-8 -*-
"""
Generate Django boilerplate code to expose models via a REST API.
Will generate code for the view, serialization and url routing. Results
are written to stdout; redirect them to a file and integrate them into
your project (views.py, serializers.py, urls.py) to get started quickly.
@cb109
cb109 / toggl_vacation.py
Created August 21, 2017 08:53
Batch create Toggl time entries for vacation
# -*- coding: utf-8 -*-
"""
A simple script to batch-create Toggl time entries for a vacation.
Note: Time zones and offsets are not handled here.
# Prerequisites
@cb109
cb109 / example_output.txt
Last active September 17, 2017 12:10
The Patrician II: OCR based Trade Recommendations
_________________________________________________
___ __ _ _ ________
/ _ \___ _/ /_____(_)___(_)__ ____ / _/ _/
/ ___/ _ `/ __/ __/ / __/ / _ `/ _ \ _/ /_/ /
/_/ \_,_/\__/_/ /_/\__/_/\_,_/_//_/ /___/___/
_________________________________________________
You should buy in this town:
beer for max. 52
@cb109
cb109 / urlState.js
Last active November 3, 2017 13:56
vue-router: Map state to URL query
/**
* A Vue mixin to map local component state to URL query.
*
* Uses vue-router's $route.query to get/set the query params.
*
* Useful e.g. to store and restore filters to/from the URL.
*
*/
var urlState = {
data() {
@cb109
cb109 / example_usage.py
Created December 12, 2017 13:25
Python per-module excepthooks
from .hook import register_module_excepthook
from .hook import install_global_excepthook
def some_module_function_that_may_fail():
raise ValueError("whoops!")
def module_excepthook(type_, value, tb):
print("Gosh, " + __name__ + " has produced an error!")
@cb109
cb109 / 1_CSS.css
Last active December 13, 2017 13:56
CSS vs Stylus
.desktop-mode.application {
margin: 0 auto;
max-width: 1280px;
}
.desktop-mode.shadow-box {
position: fixed;
height: 100%;
width: 100%;
z-index: -99;
max-width: 1280px;
@cb109
cb109 / user_sessions.py
Last active December 21, 2017 10:27
List all Django Sessions for a User
from django.contrib.sessions.models import Session
def yield_user_sessions(user):
"""Yield all Sessions associated with the user.
Note: This is extremely inefficient, since we have to deserialize
all existing Sessions. Consider this a debugging helper, not
a production tool. Should we need more frequent access to this
information, then adding a separate model to map users to
@cb109
cb109 / scrape_world_cup_matches.py
Last active June 14, 2018 10:58
Scrape historical soccer world cup match results from the FIFA archive (https://codepen.io/cb109/pen/rKmbmL?editors=1010)
# -*- coding: utf-8 -*-
"""Scrape all historical soccer world cup match results into a JSON file."""
import json
import requests
from bs4 import BeautifulSoup
urls = [
@cb109
cb109 / ngrok_to_qr.sh
Last active July 10, 2018 08:30
Render ngrok URL as QR code in your terminal
#!/bin/bash
#
# Assuming you have a running ngrok session, this snippet fetches the
# https URL from ngrok's local API and renders it as a QR code in your
# terminal. You can then scan it with a mobile phone to quickly load
# that URL.
#
# Based on:
# https://github.com/stedolan/jq/issues/861
#