sensimevanidus

1 February, 2012

Installing MySQLdb Python module on MacOSX

I created an empty project for Django. It uses MySQL server; but when I wanted to run the application I got an exception that contained the following line (I won’t paste all of the traceback message):

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

When it comes to installing such libraries, packages, etc. on MacOSX, I find myself using MacPorts. So, the easiest way (at least for me) is using MacPorts. Be sure that you’ve installed MacPorts and on terminal, write the following:

sudo port install py27-mysql

MacPorts will add appropriate directories to the PATH environment variable automatically. Don’t forget to use the command python2.7 instead of python from now on.

That’s all about it!

sensimevanidus

2 June, 2011

Getting brief Git repository information

A good bash script that shows brief information about a Git repository. I’ve found the script here: http://goo.gl/QUe5t.

sensimevanidus

23 May, 2011

If you have something that you don’t want anyone to know, maybe you shouldn’t be doing it in the first place.

— Google CEO Eric Schmidt

sensimevanidus

7 April, 2011

boolean toggle

While exploring Tumblr, I saw the following post:

ec1975:

…when switching don’t mind using:

if ($val==0) $val = $1; else $val = 0;

instead use:

$val = abs ($val-1);

It’s ok (except the $1 typo); but the following solution is far more efficient:

$val ^= 1;

I saw the post and wanted to leave a comment; but I couldn’t. That’s why I’m posting this. :)

sensimevanidus

23 March, 2011

Whenever Ubuntu makes a new release, I realize that I’m getting older…

sensimevanidus

9 March, 2011

Running shell commands on a remote machine

If you’re familiar with unix-like systems, probably you’ve already worked with shell commands. My favorite shell is Bash and this post is about running Bash commands on a remote machine; but I guess the idea behind it can be used in other Unix shell systems too.

As a web developer, I frequently have to deploy projects to remote servers. When something changes, I need to re-deploy the whole project (especially when I work on projects written in Java). The easiest way for me is to write a deployment script that automatically goes over the boring mandatory steps (e.g. backing up the latest version on the remote server, copying files, preparing the package). This way is even more secure. Once I’m sure that the script does its job correctly, it does not have a choice to make a mistake.

During my first attempt to write such a script, I faced a problem when I wanted some commands of the script to work on the remote machine. Normally, to work on a remote machine you make a connection via ssh, find yourself on its shell and continue writing your commands. Here, the problem is that the script works on your local machine and if you open an ssh connection, it just gets stuck. A workaround for this problem is running commands like this:

ssh -p PORT_NUMBER USERNAME:PASSWORD@REMOTE_MACHINE_IP "cd /var/www; ls;"

The trick here is to append the desired commands after the connection command. But if the job you’re doing is complicated enough, appending such commands may drive you to have problems.

My solution to this problem is to write a second bash script, copying it to the remote server via scp and running that script remotely. Yes, of course it works and is a great idea! Let’s assume that the name of the bash script file is ss-script.sh (ss stands for Server-Side). In our local deployment script, let’s add these lines:

scp -P POST_NUMBER ss-script.sh USERNAME:PASSWORD@REMOTE_MACHINE_IP:/tmp
ssh -p PORT_NUMBER USERNAME:PASSWORD@REMOTE_MACHINE_IP "cd /tmp; chmod 777 ss-script.sh; ./ss-script.sh"

And that’s it! The script would work as expected and after it’s finished, your local script will continue to work from the next line!

sensimevanidus

2 March, 2011

Assigning Static IPs to Specific Devices on Pirelli PRG E4202G

I have a server at home. I use the fiber internet connection service of Superonline at 20Mbps. During the initial setup, they provided me Pirelli’s modem (PRG E4202G). Why I’m writing this post is my negative thoughts about the usability of its management console. It’s really hard at first to find out how advanced settings can be configured. It’s likely you’re lost. If you own one, you already understand what I mean.

I wanted my home server to have a static IP in the local network. The solution is simple; you assign an IP to the server’s MAC address. That’s all about it; but it took some time for me to figure out how it works on the management console of PRG E4202G. Here’s how:

  1. Login to the management console.
  2. Click on the Network Connections link from the navigation panel.
  3. Click on the LAN VLAN2 Properties (my server is connected to the modem via the wired ethernet protocol. if yours is different, you should select the corresponding one here.).
  4. Click the IP Address Distribution link (it’s hard to see that there’s a link here :) This made me suffer!).
  5. Click on the Connection List button.
  6. You’ll see a list of currently opened connections. Find the one that is your server and click on the Edit icon on the right-hand side.
  7. Enable the Enable reserved IP option.
  8. Enter your desired IP address to the corresponding input field.
  9. Click the Ok button.
  10. Restart the networking service on your server (or just restart your server).
  11. Now the modem will assign the desired IP address to your server.

That’s it!

    sensimevanidus

    19 December, 2010

    Fixing indentation and converting tabs to spaces in VIM

    I use VIM as the default text editor on my Ubuntu box and generally work on HTML files. It’s a common problem of developers to edit a malformed (e.g. indentations are bad, tabs are used instead of spaces) source code.

    When I encounter such a situtation, I enter the following commands in VIM to make the source code more readable (I wrote html as the filetype; but of course you should change it to your needs):

    1. :set filetype=html
    2. :filetype indent on
    3. :e
    4. gg=G

    These 4 commands fixes the indentations of the file; but it’s not enough. I tend to convert tabs to spaces and fix the indention to 4 columns:

    1. :set tabstop=4
    2. :set shiftwidth=4
    3. :set expandtab
    4. :retab

    That’s all!

    sensimevanidus

    3 September, 2010

    jdk installation on Ubuntu 10.04

    onur@grizu:~$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
    onur@grizu:~$ sudo apt-get update
    onur@grizu:~$ sudo apt-get install sun-java6-jdk