Skip to content

Instantly share code, notes, and snippets.

View dchaplinsky's full-sized avatar

Dmytro Chaplynskyi dchaplinsky

View GitHub Profile
diff --git a/circus/arbiter.py b/circus/arbiter.py
index 006fed3..303b1ab 100644
--- a/circus/arbiter.py
+++ b/circus/arbiter.py
@@ -146,8 +146,8 @@ class Arbiter(object):
self.check_delay)
@classmethod
- def load_from_config(cls, config_file):
- cfg = get_config(config_file)
@dchaplinsky
dchaplinsky / exporters.py
Created March 7, 2013 12:59
Improvement for original XmlItemExporter of scrapy to enable saving of dicts to xml (so free-form data can be saved to XML too).
from scrapy.contrib.exporter import XmlItemExporter
class DictXmlItemExporter(XmlItemExporter):
def _export_xml_field(self, name, serialized_value):
self.xg.startElement(name, {})
if hasattr(serialized_value, '__iter__'):
if isinstance(serialized_value, dict):
for key in serialized_value:
self._export_xml_field(key, serialized_value[key])
@dchaplinsky
dchaplinsky / Blackboard.tmTheme
Created January 3, 2013 21:42
Fixed Blackboard.tmTheme for Sublime Text 2 (now with proper coloring for Diff). Matches diff colouring from TextMate Blackboard theme.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Blackboard</string>
<key>author</key>
<string>Domenico Carbotta</string>
<key>settings</key>
<array>
#!/usr/bin/env python
import sys
import os.path
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(PROJECT_ROOT, "../"))
from twisted.internet import reactor, task
from scrapy.crawler import Crawler
@dchaplinsky
dchaplinsky / httpdlogs.py
Created February 27, 2012 23:36
sysinfo plugin for PyMunin to parse last records in nginx/apache logs and gather stats about pageload time and amount of visits generated by search engine robots
"""Implements HttpdLog Class for gathering useful info from nginx/apache access logs.
"""
import re
from datetime import timedelta, datetime
import subprocess
__author__ = "Dmitry Chaplinsky"
__copyright__ = "Copyright 2012, Dmitry Chaplinsky"
__credits__ = []
@dchaplinsky
dchaplinsky / dump_fixtures.py
Created November 8, 2011 15:08
Script for dumping only particular fields of particular django models to JSON
import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),
"../"))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
from django.core import serializers
from django.db.models import get_model
from django.template.defaultfilters import slugify
MODELS_TO_DUMP = (
@dchaplinsky
dchaplinsky / avatars.py
Created September 28, 2011 18:12
Get avatars from social networks (facebook and google) with django-social-auth
from social_auth.backends.facebook import FacebookBackend
from social_auth.backends import google
def social_extra_values(sender, user, response, details, **kwargs):
result = False
if "id" in response:
from apps.photo.models import Photo
from urllib2 import urlopen, HTTPError
from django.template.defaultfilters import slugify
@dchaplinsky
dchaplinsky / pypistats.py
Created September 18, 2011 10:20
PyPI Download Stats (found here: http://www.codekoala.com/blog/2010/pypi-download-stats/, (c) by CodeKoala)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Calculates the total number of downloads that a particular PyPI package has
received across all versions tracked by PyPI
"""
from datetime import datetime
import locale
@dchaplinsky
dchaplinsky / views.py
Created September 16, 2011 22:30
social auth
SOCIAL_DETAILS = None
def soul_catcher(sender, uid, response, details, **kwargs):
global SOCIAL_DETAILS
SOCIAL_DETAILS = details
socialauth_not_registered.connect(soul_catcher, sender=None)
@render_to("account/signup.html")
def register(request, backend):
@dchaplinsky
dchaplinsky / sass.py
Created September 8, 2011 11:05
Update to webassets SassFilter to make it also work as output filter
import os, subprocess
from webassets.filter import Filter
class SassFilter(Filter):
"""Converts `Sass <http://sass-lang.com/>`_ markup to real CSS.
"""
name = 'sass'