Skip to content

Instantly share code, notes, and snippets.

View matthiask's full-sized avatar
🥳

Matthias Kestenholz matthiask

🥳
View GitHub Profile
@matthiask
matthiask / extract_gettext.py
Last active January 6, 2021 10:42
Extract gettext calls from JavaScript code
#!/usr/bin/env python3
"""
Extract strings::
python3 extract_gettext.py
Run tests::
python3 -m doctest -v extract_gettext.py
@matthiask
matthiask / consumers.py
Last active February 28, 2018 08:14
Channels 2 HTTP experiments (long polling / server sent events)
import asyncio
from datetime import datetime
from channels.consumer import AsyncConsumer
# from channels.http import AsgiRequest
class AsyncHttpConsumer(AsyncConsumer):
async def __call__(self, receive, send):
self.send = send
@matthiask
matthiask / safeimage.py
Created February 11, 2018 09:43
Minimal template tag for avoiding django-versatileimagefield crashes with invalid images
from django import template
from django.template.base import Variable
register = template.Library()
@register.simple_tag(takes_context=True)
def safeimage(context, imagefile, spec):
"""
@matthiask
matthiask / render_bundle_inline.py
Created September 11, 2017 08:52
render_bundle_inline for django-webpack-loader
import io
import os
from django import template
from django.conf import settings
from django.utils.html import mark_safe
from webpack_loader import utils
@matthiask
matthiask / translation.py
Created April 13, 2017 12:15
django-modeltranslation translation options helper
from __future__ import unicode_literals
from modeltranslation.translator import translator, TranslationOptions
from naturnetz.models import Branch, Staffer, StickyNote
def translation_options(model, **options):
translator.register(
model,
from django.core.management.base import BaseCommand
from feincms.module.page.models import Page
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('from_pk', type=int)
parser.add_argument('to_language', type=str)
@matthiask
matthiask / import_postaladdresses.py
Created December 21, 2016 15:12
Postal addresses
# coding=utf-8
from __future__ import print_function
from bs4 import BeautifulSoup
import re
import requests
from django.core.management.base import BaseCommand
from django.utils.encoding import force_text
@matthiask
matthiask / bot.js
Last active November 26, 2016 10:58
Slack Bot
const Botkit = require('botkit');
const request = require('superagent');
const controller = Botkit.slackbot();
// Slack Bot starten; und unendlich viele Wieder-Verbindungen zulassen
controller.spawn({
token: process.env.SLACK_BOT_TOKEN,
retry: Infinity,
}).startRTM(function (err, bot, payload) {
if (!err) return;
server {
listen *:80;
server_name ...;
root /home/www-data/.../htdocs;
error_log /home/www-data/logs/....error.log;
access_log /home/www-data/logs/....access.log combined;
@matthiask
matthiask / changelist.html
Last active February 27, 2016 08:10
admin list sortable
<script type="text/javascript" src="/static/app/jquery-ui-1.11.4.custom.min.js"></script>
<style>#result_list tbody tr { cursor: move; }</style>
<script>
django.jQuery(function($) {
$('#result_list tbody').sortable({
update: function(event, ui) {
$('#result_list tbody tr').each(function(index) {
var row = $(this);
row.find('.field-ordering input').val(10 * (index + 1));
row.removeClass('row1 row2').addClass((index % 2) ? 'row2' : 'row1');