Skip to content

Instantly share code, notes, and snippets.

View petrprikryl's full-sized avatar

Petr Přikryl petrprikryl

View GitHub Profile
@robotadam
robotadam / gunicorn_config.py
Created December 5, 2022 18:13
Gunicorn saturation monitoring
"""gunicorn configuration file to export server metrics
To launch add `-c webapp/gunicorn_config.py` to the gunicorn command line.
Requires statsd to be configured for gunicorn as well, e.g.
`ENV STATSD_HOST=statsd-exporter:9125`
"""
# Python imports
import ctypes
@jpedroribeiro
jpedroribeiro / getNestedPropValWithDotNotation.js
Last active June 12, 2023 09:48
How to get a nested property of an object with dot notation
/*
* Returns the value of a property in a nested object.
*
* @param {Object} sourceObject
* @param {string} dotNotationPath
* @returns {*}
*
*/
function getPropValue(sourceObject, dotNotationPath) {
@DmytroLitvinov
DmytroLitvinov / messages.html
Last active September 13, 2021 22:18
[Django middleware for AJAX messages] Middleware for JSON responses. It adds to each JSON response array with messages from django.contrib.messages framework. It allows handle messages on a page with javascript. Django 1.10. #tags: django, python, ajax
<div id="messages">
{% for message in messages %}
<div {% if message.tags %}class="alert alert-dismissable alert-{{ message.tags }}"{% endif %}>
<a class="close" data-dismiss="alert" href="#">&times;</a>
{{ message }}
</div>
{% endfor %}
</div>
@Jc2k
Jc2k / README.md
Last active March 30, 2023 10:31
Database rollback options in Django

Batching migrations

The idea here is that if you know which migrations were in version 2.0.3 of your project and which were in version 2.0.4 then setA - setB gives you the list of migrations you need to undo.

Django migrations give you a directed acyclic graph which describes how to get from the current database state to the target state. But there is no mechanism by which you can perform tasks like revert all the migrations that just ran in the last deployment.

Here is a quick recipe for batching Django migrations to allow you to do things like that.

Before you tag your project you do:

@bittner
bittner / 60-jetbrains.conf
Created September 25, 2015 07:57
Inotify configuration for IntelliJ IDEA (PhpStorm, PyCharm, RubyMine, WebStorm). Create this file with e.g. `sudo vim /etc/sysctl.d/60-jetbrains.conf`
# Set inotify watch limit high enough for IntelliJ IDEA (PhpStorm, PyCharm, RubyMine, WebStorm).
# Create this file as /etc/sysctl.d/60-jetbrains.conf (Debian, Ubuntu), and
# run `sudo service procps start` or reboot.
# Source: https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit
#
# More information resources:
# -$ man inotify # manpage
# -$ man sysctl.conf # manpage
# -$ cat /proc/sys/fs/inotify/max_user_watches # print current value in use
@clchiou
clchiou / non_graceful_shutdown.py
Created March 19, 2015 04:32
Python ThreadPoolExecutor (non-)graceful shutdown
#!/usr/bin/env python3
import concurrent.futures.thread
import sys
import time
from concurrent.futures import ThreadPoolExecutor, as_completed
def remove_file(path):
print('Removing file %s' % path)
@hlawrenz
hlawrenz / flower command line
Last active February 5, 2023 19:00
Serve celery flower behind Django authentication.
celery flower --address=127.0.0.1 --url_prefix=flower --broker=<broker url>
@d11wtq
d11wtq / docker-ssh-forward.bash
Created January 29, 2014 23:32
How to SSH agent forward into a docker container
docker run -rm -t -i -v $(dirname $SSH_AUTH_SOCK) -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK ubuntu /bin/bash
@thom-nic
thom-nic / cx_oracle_instructions.md
Created July 16, 2013 19:14
Installing CX Oracle for Python & Mac OS X. Instructions exist around the web, but they seem to be piecemeal and incomplete.
@stantonk
stantonk / django_orm_query_stacktrace.py
Created May 4, 2013 00:49
Django logging config to dump a stack trace for every ORM query, so you can find the code that is producing queries that are icky.
DEBUG=True
LOG_FILE_SIZE=1024*1000
LOGGING = {
'version' : 1,
'disable_existing_loggers':True,
'formatters' : {
'simple' : {
'format' : '%(levelname)s %(name)s %(message)s'
},