Donate to support Ukraine's independence.

03 Oct'13

Pelican on Windows

I enjoy using pelican so for so much. However, few issues hit my mind recently:

  • Medium is such a nice place to write that I can merely resist my temptation;
  • There is no ability to run person search across the static website;
  • I’m tied to UNIX environment in order to run the Pelican development server for preview.

I recalled a great quote:

Once you say you’re going to settle for second, that’s what happens to you in life.

—John F. Kennedy

So I decided to see if it’s possible to resolve all of that issues for …

Continue reading

03 Mar'13

Latest software sources

https://launchpad.net/~webupd8team

http://www.lfd.uci.edu/~gohlke/pythonlibs/

http://www.dotdeb.org/

Continue reading

05 Mar'12

Django fails with DEBUG=False on production

First, be sure to eliminate this issue: http://stackoverflow.com/a/4975210

Next, enable logging of all events. That will save you plenty of time.

Next, be sure to include both 404.html and 500.html in the root of your templates’ folder. See here and here for details.

If you are using nginx, be sure to include correct fastcgi configuration file: http://softwaremaniacs.org/forum/django/9093/ (post before the last). Fairly equal to http://serverfault.com/a/229188. But extensive configuration http://stackoverflow.com/a/605196 didn’t work for me.

Continue reading

05 Mar'12

MySQL with Django on Debian

First, install MySQL driver for Python:

sudo apt-get install python-mysqldb

Next, modify your config of MySQL: http://dba.stackexchange.com/a/8289

If you’ve already messed up the install, you can either drop/create database from scratch, or apply the following script to every table of your DB:

ALTER TABLE `table` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Alternative mirgation path: http://docs.joomla.org/Convert_a_MySQL_database_to_UTF-8

Continue reading

05 Mar'12

Python hostname

from socket import gethostname

print gethostname()

if 'prod' in gethostname:
    pass

Continue reading

08 Feb'12

Nonblocking console input in Python

By Nemesis Fixx:

import sys
import select
import tty
import termios
from threading import Thread

program_run = True
input_thread_timeout = 0.005 #seconds
quit_key = '\x1b' # x1b is ESC

#check stdin for input...
def isData():
        return select.select([sys.stdin], [], [], 0) == ([sys.stdin], [], [])

#check n terminate program on terminal condition,
#from a separate thread
class waitOnInput(Thread):
    def run(self):
        old_settings = termios.tcgetattr(sys.stdin)
        try:
            tty.setcbreak(sys.stdin.fileno())
            global program_run
            thread_run = True
            while thread_run:
                if isData():
                    c = sys.stdin.read(1)
                    if c == quit_key:
                        break
                        thread_run = False
                        program_run = False
        finally:
            termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
            thread_run = False


t …

Continue reading

11 Jan'12

PyOpenCl on x64 system

UPD: I found unofficial binary builds here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl, use x86 builds.

Do not forget to install pytools.

I’ve been into some difficulties since i began installing that software, even with help of http://wiki.tiker.net/PyOpenCL/Installation/Windows.

First, easy_install won’t work on x64 systems if installed by executable installer. Instead, use ez_setup.py which will determine the correct version of the software.

Next, install numpy.

finally, i’ve got a problem with module compilation. Let’s split it into two problems:

  1. wrong path to vcvarsall.bat (try to add …

Continue reading

24 May'11

Scrapy 0.12 Parsing with python

Based on Scrapy Tutorial (dead link: doc.scrapy.org/intro/tutorial.html)

  1. Install scrapy and dependencies
sudo apt-get install python-lxml
sudo easy_install -U Scrapy
  1. Create project
scrapy startproject dmoz
  1. Create item models
from scrapy.item import Item, Field

class DmozItem(Item):
    title = Field()
    link = Field()
    desc = Field()
  1. Create spiders (in projname/spiders/)
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from dmoz.items import DmozItem

class DmozSpider(BaseSpider):
    name = "dmoz.org"
    allowed_domains = ["dmoz.org"]
    start_urls = [
    "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/",
    "http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"
    ]

    def parse(self, response):
        hxs …

Continue reading