Posts

Showing posts from 2013

CentOS Install SSH server and configure for VirtualBox testing

Image
I have had some tasks to configure and install a CentOS distribution for my bug-tracking needs. Hope to help out someone with similar problems and or tasks.

I'll be using a fresh install of a CentOS Minimal 6.5.  And a Mac Book Pro with VirtualBox installed (as my testing environment).

First after install of a clean CentOS you need an SSH server to work in your usual environment. So to connect to a Linux, installed in a VirtualBox you will need basically 2 things:
openssh-server installdisable firewallVirtualBox Port configuration/Access configuration OpenSSH server install To install server you need to run in your VirtualBox Guest system (CentOS VM):
yum -y install openssh-server And start and add it to auto launch at system startup:
chkconfig sshd onservice sshd start Also make sure port 22 is opened in your VM. type:
netstat -tulpn | grep :22 Firewall settings Because it's a VM you can simply disable the firewall. But be sure not to do this at deployment/production server of a…

Python Generators explained simply.

Image
I'm often confused by recent obsession of generators in python. I'll try to explain them as simply as possible. Say you have never used iterators but coded in python. BUT I'm sure you have used dictionaries (dict) and have met requirement to iterate through it's keys and/or values. TADA! You have used generators already ;).

So generator is a function in python. Except for it uses a keyword yield in it's code. Thus making it the iterator. So you could call this function in a sequence like you would probably do iterating over a dictionary already. E.g.:
# typical iteration through dictionary key: value setforkey,valueindict.iteritems():# do someth# Usage of your own iteratorforiteminiterator_functuon():# do something with function generated output So this function returns an iterator generator like the dict() type has by default. And has a next() function, like usual iterators have.
So in attempt to using human language:
Generators are simple functions converted to it…

AJAX form in Django with jQuery.form plugin

Image
Here I will describe an example form using jQuery Form plugin. It will provide a good frontend, while Django serving a simple backend.
I made this AJAX form using unobtrusive javascript. With human language it means the form will function with JavaScript disabled. And so jQuery.form plugin will work as an AJAX speedup addition and not as a major requirement.

Features:
* Works both with JavaScript  and without.
* Uses standard Django ideology/hooks.
* Uses the most known jQuery plugin for forms AJAX handling.

Theory:
Main idea that Django supports both normal and AJAX request in a standard view. And has a handy request.is_ajax() request method. It returns True/False depending on if request search has HTTP_X_REQUESTED_WITH header for the string 'XMLHttpRequest'. jQuery.form plugin sure does have that.

Backend Django.
We will create an app called 'contact' for our task and place it in the example django project. Urls from the project will redirect to this app. OK. Here i…

CouchDB restoring deleted/updated documents and their data

Image
We are using CouchDB for production and happy with it. It is much more lightweight rather then MongoDB yet powerful. (For our needs at least). But sometimes you have situations that some code deleted/spoiled your Couch Database data. We had some bugs leading to deleting indexes. However compaction have not been run and here is the decision.

There are several ways for different situations. I'll try to cover them all.
So for deleted CouchDB documents you need to:
1. Make sure your document with this id is Deleted. To do it you need to request CouchDB for this document. E.g. with this string:
$db/$id Where $db is your CouchDB database name and $id is your deleted document id
it should return something like this:
{"error":"not_found","reason":"deleted"} 2. Get all the revisions of the deleted document. With this request:
$db/$id?revs=true&open_revs=all Where $db is your CouchDB database name and $id is your deleted document id.
3. Parse respon…

OS X Mavericks and Last.FM scrobling of iTunes radio

Image
I have used iTunes radio dramatically after installing a new version of iTunes. But the problem is my musical taste is recorded (Historically) at Last.FM profile. So It is something like combining your Last.FM profile with your iTunes Geniuos data. AFAIK iTunes uses it's data to play songs in a given station. After trying several decisions I have found a nice one that simply works.

You need an app called Bowtie. It's built for older OS X'es. But works nicely for this purpose. It has a themed desktop applet. So it's something like a nice bonus. Anyway you can connect it with Last.FM and that's it. Just one thing it sits in your memory. But I have found it does not consume too much resources or has obvious flaws that spoil Mac anyway.
One trick to install it you need to enable it install your system. It is not from apple store so...
as per stackoverflow question it can be done like so:

Go to System Preferences... > Security & Privacy and there should be a butt…

install ssh-copy-id on Mac OS X best way

Image
You often need to create identities for unknown/new servers. Then welcome to this article. I believe i have a best practice way of doing it on a MAC system.
First of all you need your identity file:
1. Generating ssh keys set You need to use tool that any unix system usually has. It's ssh-keygen. (Skip if you have it already)
Lastlogin: WedAug2116:07:34onttys002console@username:~$ssh-keygen-trsaGeneratingpublic/privatersakeypair.Enterfileinwhichtosavethekey(/Users/username/.ssh/id_rsa):yourkeynameEnterpassphrase(emptyfornopassphrase):Entersamepassphraseagain: Youridentificationhasbeensavedinyourkeyname.Yourpublickeyhasbeensavedinyourkeyname.pub.Thekeyfingerprintis:XX.XX.XX.XX.XX.XX.XX.XX.XX.XX.XX.XX.console@usernameThekey's randomart image is:+--[ RSA 2048]----+| + || + || + || + || + || . + || . + || . ...........+ || . .+.... |+-----------------+console@username:~$ N…

Django: Add Permission model to admin panel

Image
How to add a permissions model to your Django admin?
You may add those lines to anywhere in your code. But it is more convinient to add this to your admin.py or place where django admin custom code lies. Here are them:
fromdjango.contrib.auth.modelsimportPermissionadmin.site.register(Permission) Now you can manage them in in your Django admin panel. May look like this:
Hope this helps.

How to burn (write) an ISO image to USB drive in all new Mac OS X systems

Image
There are many programs in the market that can handle it for you. But you can do it with default Mac OS X tools. Those steps must be made in terminal. You need to know what you are doing and have root password to your system.
Here is your step by step guide to do it:

1. Convert your image. You need to change the image type from .iso to .img that dd util supports. To do this type a command like this:
hdiutil convert -format UDRW -o /path/to/destination/file.img /path/to/source/file.iso You must see output similar to this:
Reading Image File Name Here (Apple_UDF : 0)…... [ truncated ] .............................Elapsed Time: 4m 57.725sSpeed: 20.9Mbytes/secSavings: 0.0%created: /path/to/image/file.img.dmg 2. Remove the .dmg extension.mv /path/to/image/file.img.dmg /path/to/image/file.img 3. Get your flash drive device name. You can do it in various ways. one that is using standard utils here:
diskutil list This will list all your disks mounted to your mac. Output should be similar to thi…

Python converting PDF to Image

Image
I have a task to generate thumbnails of uploaded PDF's. And seems like there no really solid decisions yet. Just garbage on the surface in google results. after googling for a while I found out about many ways to do so. E.g. use python stdin/out to run external command line tool. It might work for you to. But it seemed not so pythonic for me. So I have searched fo better decision. My current is for now to install ImageMagick and MagicWand binding.
Install ImageMagick. I have used PIL a while ago to work with images. But it made me cry, before I have met sorl-thumbnails. It helped me a lot. But now I have to deal with PDF's. And ImageMagick seems like a complete decision to master it all.  It has to convert pdf to my direct desirables - jpeg. So to install ImageMagick I have used brew. Like this:
brew install imagemagick However there are many other ways to do so, depending on a platform. But I strongly recommend to look at brew.

Anyway installing ImageMagick is tricky. And in …

Show system files in Finder

Image
Default Mac OS X system behavior is to hide system and hidden unix files (usually starting with a . symbol, e.g.: .bash_history will be out of sight). This makes spotting/opening one of this files with Finder extremely difficult.

you may use your terminal, typing command like "ls -a" that will show all of the files in that particular directory, including hidden and system one's. But sometimes it may become annoying to use terminal while using the GUI.

So. To change this default behavior in finder you need to enter those commands in the terminal window:
defaults write com.apple.finder AppleShowAllFiles TRUE And after this you need to restart all your Finder processes like so:
killall Finder
Comments?

Django: How to debug Django

Image
There are several ways of debugging Django. I'll try to cover most common and tell what I know/use time to time. This article may become useful to Django newbies and is not intended to be "the only truth". It may help you know in general about debugging techniques commonly used in Python/Django projects that author is aware of. Let's get started. There are several methods to discuss here. 1. Print out into console. It may become handy while working with critical bugs that only appear in production for e.g. and are not traceable at development environment... The only way here to run your project manually and do debug in production. Those requirements are so rare that I only use standart (builtin) tools. There is a thing called PDB (Python Debugger). That comes in a standart set of usual python distribution. So it will be available to you at almost any environment where you have console access to your project. Here is an official documentation for pdb module. And you …