Skip to content

Instantly share code, notes, and snippets.

View lukassup's full-sized avatar
🍕

Lukas Šupienis lukassup

🍕
View GitHub Profile
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""\
Start RabbitMQ server:
$ sudo systemctl start rabbitmq.service
Start Celery worker:
$ celery worker -A tasks -l debug

Generate random hex strings in Python

import uuid
uuid.uuid4().hex
'705e54562bca4991910e53958bf24729'

Lambda functions in Python

Note: I use Python 3, but most of these should work in Python 2 too.

Intro

Lambda functions are also known as anonymous functions and are typically passed as arguments to other functions. Notable examples are the map(), reduce(), filter() built-in functions which require a function to be passed as an argument.

##
# mpv.conf
#
hwdec=vaapi
#hwdec=vdpau
vo=opengl
#vo=wayland
#vo=opengl-hq
#vo=opengl-hq:deband=no
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import curses
import sys
def curses_wrapper(func, *args, **kwds):
"""Wrapper decorator that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error or exit.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
xml = '''\
<RECORDSET>
<RECORD ID="1">
<FIELDNAME>ORIGINALSEVERITY</FIELDNAME><FIELDVALUE>0</FIELDVALUE>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""various date/time utilities
<datetime.datetime> parsing behavior
[year(-|/|.)month(-|/|.)day(_whitespace_)][[[hour]:minute]:second]
<datetime.timedelta> parsing behavior
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""various date/time utilities
<datetime.datetime> parsing behavior
[year(-|/|.)month(-|/|.)day(_whitespace_)][[[hour]:minute]:second]
<datetime.timedelta> parsing behavior
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess
from shutil import which # Python 3.3
# Reset locale
os.environ.setdefault("LC_ALL", "C")
#!/bin/bash
random_choice() {
choices=("$@")
echo ${choices[$(( $RANDOM % ${#choices[@]} ))]}
}
random_choice "$@"