Skip to content

Instantly share code, notes, and snippets.

@balazs-endresz
balazs-endresz / .sql
Created April 7, 2016 11:37
Postgres table sizes
-- https://wiki.postgresql.org/wiki/Disk_Usage
-- This version of the query uses pg_total_relation_size, which sums total disk space used by the table including indexes and toasted data rather than breaking out the individual pieces:
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
@balazs-endresz
balazs-endresz / gist:af96d95619c58f0702af
Created March 16, 2016 17:46
Stash un-staged changes
git stash save --keep-index
@balazs-endresz
balazs-endresz / .sh
Created March 1, 2016 13:16
Add new objectClass to existing ldap user
#! /bin/sh
ldapsearch -x -h localhost -b dc=example,dc=org,dc=uk \
'(&(objectClass=existingObjectClass)(!(objectclass=newObjectClass)))' dn \
|awk '/^dn: / { print $2 }' \
| (
while read line; do
printf 'dn: %s\nchangetype: modify\nadd: objectClass\nobjectClass: newObjectClass\n\n' "$line"
done
) \
@balazs-endresz
balazs-endresz / logging.py
Last active February 3, 2016 15:56
Remove passwords from all stack traces
from django.views.debug import SafeExceptionReporterFilter, CLEANSED_SUBSTITUTE
class CustomExceptionReporterFilter(SafeExceptionReporterFilter):
""" Add this is to the settings:
DEFAULT_EXCEPTION_REPORTER_FILTER = 'path.to.CustomExceptionReporterFilter'
"""
def get_post_parameters(self, request):
post_parameters = super(CustomExceptionReporterFilter, self).get_post_parameters(request)
cleansed = post_parameters.copy()
// ==UserScript==
// @name projects.torchbox.com tweaks
// @namespace https://projects.torchbox.com/
// @version 2
// @match https://torchbox.codebasehq.com/*
// @match https://projects.torchbox.com/*
// @grant none
// @noframes
// ==/UserScript==
/* jshint -W097 */
@balazs-endresz
balazs-endresz / .py
Created September 25, 2015 12:25
Remove duplicates from a list while preserving original ordering
sorted(set(sorted_list), key=lambda x: sorted_list.index(x))
@balazs-endresz
balazs-endresz / dev.py
Created September 9, 2015 14:09
django-libsass static() function that raises exception if the file doesn't exists
import ast
from django.templatetags.static import static as django_static
def strict_static(path):
"""
A stricter version of the static() function provided by django-libass:
https://github.com/torchbox/django-libsass#custom-functions
Raises an exception if a file is not found. Not for production use.
"""
@balazs-endresz
balazs-endresz / gist:7f209b929bcc9cfaa69c
Last active August 29, 2015 14:26
sort entries in server log by page load time
| grep -E '[0-9]{4,10} msecs'|grep -Eo '(POST|GET) [^ ]*|[0-9]* msecs' | sed -r '$!N;s/([^\n]*)\n([^\n]*)/\2 \1/' |sort -n

Keybase proof

I hereby claim:

  • I am balazs-endresz on github.
  • I am balazsendresz (https://keybase.io/balazsendresz) on keybase.
  • I have a public key whose fingerprint is 3727 0479 E105 6395 5C45 8027 D395 7C0A A4A5 7980

To claim this, I am signing this object:

@balazs-endresz
balazs-endresz / models.py
Created April 27, 2015 12:44
Wagtail page type validator
from django.core.exceptions import ValidationError
from django.utils.deconstruct import deconstructible
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.utils import resolve_model_string
@deconstructible
class PageTypeValidator(object):
"""