Skip to content

Instantly share code, notes, and snippets.

@pgcd
pgcd / web2py2po.py
Last active December 9, 2015 18:59
Fixed /translate/convert/web2py2po.py for Translate Tookit 1.12.0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2009-2010 Zuza Software Foundation
#
# This file is part of translate.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@pgcd
pgcd / uploader.py
Last active August 29, 2015 14:18
Skipping Uploader for google drive
__author__ = 'pgcd'
import sys
import os
import subprocess
import hashlib
def hashfile(fname, blocksize=65536):
hasher = hashlib.md5()
with open(fname, 'rb') as afile:
@pgcd
pgcd / vtz_block.py
Last active May 14, 2016 11:11
Generate iCal VTIMEZONE block with DAYLIGHT and STANDARD components, based on pytz zoneinfo data
import pytz
import icalendar
import datetime
def generate_vtimezone(timezone):
if not timezone: # UTC as a fallback doesn't work, since it has no transition info
return None
z = pytz.timezone(timezone)
utc = pytz.timezone('utc')
dst1, std1, dst2, std2 = filter(lambda x: x[0].year in (datetime.now().year, datetime.now().year + 1),
@pgcd
pgcd / gist:57f6b2c4dd0502279aa1a827f45d01ba
Created March 9, 2017 21:12
Use Imagemagick to convert an uploaded image's color profile in Django
# It took me a day to figure out a way of converting the color profile before sending an uploaded image off to S3;
# The following works both for in-memory and temp file uploads (MemoryFileUploadHandler and TemporaryFileUploadHandler)
import subprocess
import logging
logger = logging.getLogger('imageprocessing')
color_profile = settings.BASE_DIR + 'sRGB.icc' # It should be an absolute path pointing to the icc file
f = uploadedfile # eg. the one you get from request.FILES.getlist(field_name)
command = ['convert', '-profile', color_profile, '-', '-']
try:
@pgcd
pgcd / __init__.py
Last active July 23, 2017 07:53
CouchPotato PostProcess Script to move to Google Drive and replace with a STRM for Kodi
from .main import PostProcess
def autoload():
return PostProcess()
@pgcd
pgcd / save_all_strms.py
Created June 18, 2017 16:06
Save STRM for all the videos in a gdrive directory
# usage: python save_all_strms.py gdrive:your_video_folder
import os
import sys
import re
from subprocess import Popen, PIPE
import logging
log = logging.getLogger('save_all_strms')
log.addHandler(logging.StreamHandler())
@pgcd
pgcd / compressors.py
Created September 7, 2017 05:12
DeferredCSSCompressor for django-compressor
from compressor.css import CssCompressor
class DeferredCssCompressor(CssCompressor):
template_name_file = 'deferred_compressed_css.html'

Keybase proof

I hereby claim:

  • I am pgcd on github.
  • I am pgcd (https://keybase.io/pgcd) on keybase.
  • I have a public key ASA-P78BVoVBnB5EQBsnisKQWoM18r_GOW43QGDkWwVBfwo

To claim this, I am signing this object:

@pgcd
pgcd / logging_setup.py
Created September 6, 2019 06:13
Django Logging setup to log directly to papertrail (syslog)
import socket
hostname = socket.gethostname()
PAPERTRAIL_HOST = 'logsN.papertrailapp.com'
PAPERTRAIL_PORT = 'XXXXX'
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'SysLog': {
'level': 'INFO',
@pgcd
pgcd / .bashrc
Created March 8, 2022 10:45 — forked from strarsis/.bashrc
Vagrant on WSL (Bash on Windows)
# Vagrant
export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"
export PATH=$PATH:/mnt/c/Program\ Files/Oracle/VirtualBox
export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/c/Users/<Windows Username>"