Skip to content

Instantly share code, notes, and snippets.

View vstoykov's full-sized avatar
🇧🇬

Venelin Stoykov vstoykov

🇧🇬
View GitHub Profile
@vstoykov
vstoykov / dictobject.py
Last active August 30, 2018 14:11
Simple dict sucblass for making it possible to access keys as attributes
from collections import defaultdict
class DictObject(dict):
"""
Simple dict subclass for making it possible to to access keys as attributes
This class can be used as object_hook when deserializing JSON for easy
access to attributes of the JSON objects.
@vstoykov
vstoykov / pfx2pem.sh
Last active July 25, 2017 13:29
Convert pfx files to key and pem files suitable for Nginx
#!/bin/bash
# Usage:
# ./pfx2pem.sh /path/to/domain.pfx
#
# Creates domain.pem and domain.key in the current directory
#
# Based on https://gist.github.com/ericharth/8334664#gistcomment-1942267
pfxpath="$1"
if [ ! -f "$pfxpath" ];
@vstoykov
vstoykov / pdftk
Last active October 19, 2017 13:40
Run pdftk in Docker
#!/usr/bin/env python
import os
import sys
import subprocess
PDFTK_DOCKER_IMAGE = 'agileek/pdftk'
def main(*argv):
file_args = {'stamp', 'output'}
// Place your settings in this file to overwrite the default settings
{
//-------- Editor configuration --------
// Controls the font family.
"editor.fontFamily": "Ubuntu Mono",
// Controls the font size.
"editor.fontSize": 14,
@vstoykov
vstoykov / CSVParser.py
Last active August 9, 2017 11:41
Parsing CSV files
"""
Easy parsing of CSV files.
Every row is a named tuple with column name defined by the header (first row).
By default header is not returned (only rows containing the data)
"""
import csv
from collections import namedtuple
try:
import json
except ImportError:
from django.utils import simplejson as json
from django.http import HttpResponse
from django.conf import settings
from django.core.serializers.json import DjangoJSONEncoder
JSON_CONTENT_TYPE = 'application/json; charset=%s' % (settings.DEFAULT_CHARSET, )
@vstoykov
vstoykov / seo_parser.py
Last active December 19, 2015 22:39
Simple parser to get all meta tags
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Fetch SEO data from given URL
"""
from HTMLParser import HTMLParser
from urllib2 import build_opener
@vstoykov
vstoykov / ProfilinkMiddleware.py
Created June 18, 2013 11:01
Print information about executed SQL queries and time needed for execution
import re
from time import time
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
from django.db import connection
PATH_INFO_RE = re.compile(r'^(/favicon\.ico|%s|%s)' % (settings.STATIC_URL, settings.MEDIA_URL))
@vstoykov
vstoykov / XUACompatibleMiddleware.py
Created February 19, 2013 20:23
Django Middleware which add a X-UA-Compatible header to the response. This header tells to Internet Explorer to render page with latest possible version or to use chrome frame if it is installed.
class XUACompatibleMiddleware(object):
"""
Add a X-UA-Compatible header to the response
This header tells to Internet Explorer to render page with latest
possible version or to use chrome frame if it is installed.
"""
def process_response(self, request, response):
response['X-UA-Compatible'] = 'IE=edge,chrome=1'
return response
@vstoykov
vstoykov / timeit.py
Last active December 11, 2015 20:18
Simple class for easy measuring time for code execution
from time import time
class TimeIt:
"""
Simple class for easy measuring time for code execution
Usage:
with TimeIt('Simple description of my code'):
do something...