Skip to content

Instantly share code, notes, and snippets.

View czpython's full-sized avatar

Paulo Alvarado czpython

View GitHub Profile
@czpython
czpython / kill_deleted_files.sh
Created May 18, 2014 06:03
Kill processes using deleted files. This frees up memory used by files that were unlinked but are kept open by a process.
lsof +L1 | grep 'deleted' | awk '{print $2}' | xargs kill -9
@czpython
czpython / middleware.py
Created August 1, 2014 17:39
Redirect /en/ to /
from django.conf import settings
from django.core.urlresolvers import is_valid_path
from django.http import HttpResponseRedirect
from django.middleware.locale import LocaleMiddleware
from django.utils.translation import (
activate as activate_language,
deactivate as deactivate_language,
get_language,
get_language_from_path
)
import traceback
def view_current_stack():
for line in traceback.format_stack():
print line.strip()
@czpython
czpython / view_migration_changes.py
Last active August 29, 2015 14:26
Script to view any missing migrations for models. Will not work with native django migrations
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
from django.conf import settings
from django.core.management.base import NoArgsCommand
from south.exceptions import NoMigrations
from south.migration import Migrations
@czpython
czpython / use_new_style_plugin_table_names.py
Last active November 13, 2015 09:40
Migrates old cms plugin table to new table
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import DataMigration
from django.db import connection, models
class Migration(DataMigration):
tables = {
'old_cmsplugin_table_name': 'new_table_name',
# -*- coding: utf-8 -*-
from django.core.management.base import NoArgsCommand
from cms.models import CMSPlugin
class Command(NoArgsCommand):
help = 'Fixes plugins whose parent is in another placeholder'
def handle_noargs(self, **options):
# -*- coding: utf-8 -*-
from django.conf import settings
from django.core.management.base import NoArgsCommand
from cms.models import CMSPlugin, Page
class Command(NoArgsCommand):
def get_corrupt_parent_plugins(self):
@czpython
czpython / get_mws_orders.py
Last active December 11, 2015 18:08
Script to test out the Python MWS API. It takes all orders created on 01/10/2013 and outputs them to a csv file.
# -*- coding: utf-8 -*-
"""
Sample script for mws api.
"""
import csv
from collections import OrderedDict
from mws import mws
# A module containing the API credentials
@czpython
czpython / usesthis_interview_parser.py
Created April 28, 2013 07:50
Parses the interview files provided by http://usesthis.com
# -*- coding: utf-8 -*-
from re import match, findall, DOTALL
from os import listdir
from os.path import dirname, abspath
from unipath import Path
import yaml
@czpython
czpython / hvad_admin.py
Last active December 17, 2015 10:29
Hack to display hvad translated fields in the admin's changelist.
from django.contrib.admin.util import label_for_field
from hvad.admin import TranslatableAdmin as BaseTranslatableAdmin
class TranslatableAdmin(BaseTranslatableAdmin):
"""
Translation friendly admin base class.
Allows user to display translated fields in the admin changelist.
"""