Skip to content

Instantly share code, notes, and snippets.

View thanos's full-sized avatar

thanos vassilakis thanos

View GitHub Profile
import hashlib
from functools import wraps
from django.core.cache import cache
from django.utils.encoding import force_text, force_bytes
def cache_memoize(
timeout,
prefix='',
@thanos
thanos / install-rdkafka.sh
Created March 7, 2018 02:29
A script to install kafka rdkafka drivers for python
sudo apt-get update -y
sudo apt-get upgrade -y
wget -qO - http://packages.confluent.io/deb/3.2/archive.key | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] http://packages.confluent.io/deb/3.2 stable main"
sudo apt-get update && sudo apt-get install confluent-platform-oss-2.11
sudo apt-get install librdkafka-dev
ldconfig -p | grep librdkafka
@thanos
thanos / resize.sh
Created March 5, 2018 14:24
Resize a drive on EC2 Ubuntu 16.04
#resive the volue using EC2 tools.
rm /var/log/somediskhog/*.log.?
growpart /dev/xvda 1
lsblk
resize2fs /dev/xvda1
lsblk
@thanos
thanos / bttc-news.markdown
Created February 9, 2018 15:10
BTTC News
@thanos
thanos / docker_rm_a.sh
Created October 27, 2016 18:52
delete all me docker containers
sudo docker rm `sudo docker ps -a | cut -f 1 -d " "`
@thanos
thanos / couchdb_reduce.js
Created October 17, 2016 01:43
yet Another Coudhdb reduce
function (key, values, rereduce) {
if (rereduce) {
var results = {
'sum': values.reduce(function(a, b) { return a + b.sum }, 0),
'min': values.reduce(function(a, b) { return Math.min(a, b.min) }, Infinity),
'max': values.reduce(function(a, b) { return Math.max(a, b.max) }, -Infinity),
'count': values.reduce(function(a, b) { return a + b.count }, 0),
'sumsqr': values.reduce(function(a, b) { return a + b.sumsqr }, 0)
};
for(var i = 0; i < values.length; i++) {
@thanos
thanos / group.py
Created December 16, 2015 14:47
A custom django has_group conditional tag for testing if a user belongs to a group in a django template.
# A custom django has_group conditional tag
# usage:
#
# {% if request.user|has_group:"Manager" %} {% endif %}
#
# Developer: Thanos Vassilakis, 2002
import re, string
from django import template
@thanos
thanos / ntlog_handler.py
Created September 24, 2015 21:25
I use this when I need logging on a windows 7 or greater machine. Note the line commented out.
# -*- coding: utf-8 -*-
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
import sys, logging, socket, types, os, string, cPickle, struct, time
class NTEventLogHandler(logging.Handler):
"""
A handler class which sends events to the NT Event Log. Adds a
registry entry for the specified application name. If no dllname is
@thanos
thanos / simple python at exit error log
Created September 24, 2015 21:22
I usually add this to any server I write or I put this in the settings.py file of my django app.
import atexit
@atexit.register
def going_down():
import logging
logging.getLogger('myapp').error("SERVER GOING DOWN")
@thanos
thanos / gist:7c64b3a16847535ac528
Last active February 4, 2022 18:35
iso 4217 currency codes in a javascript object or python style dcttionary
iso_4217_currencies = {
"AED": "United Arab Emirates dirham United Arab Emirates",
"AFN": "Afghan afghani",
"ALL": "Albanian lek ",
"AMD": "Armenian dram",
"ANG": "Netherlands Antillean guilder",
"AOA": "Angolan kwanza",
"ARS": "Argentine peso",
"AUD": "Australian dollar",
"AWG": "Aruban florin",