Tag Archives: linux

Personalize Geany

Even though I usually develop using gedit, sometimes it’s nice to use geany as an IDE. I usually install geany and personalize it to look (almost) like gedit. I use this blog post but change some of it. Geany is better for coding in some ways, especially code folding and column selection (ctrl+shift+select) is a plus.

$ sudo apt-get install geany

Now run geany and go to the preferences menu.

Edit -> Preferences
General > Startup : Uncheck “Load virtual terminal support”
General > Miscelaneous : Check “always wrap search”
Interface > Uncheck “show side bar”
Interface > Toolbar > Click the “Customize Toolbar” Button
Remove “Undo, Redo, back, forward, compile, execute, build, color chooser, quit” (if you want, maybe don’t remove Undo and Redo?)
Iconsize : Small
Editor > Set Indentation Widthto  4,  Type : Spaces
Editor > Check “line wrapping”
Editor > Line breaking column : 80
Editor > Display > Set Long line marker : column to 80
Editor > Display > Set color to #98A8B6
Files > Check “Replace tabs by space”

Save these settings by clicking “Apply”.

To Remove the message pane, uncheck “View -> Show Message Window”
Enablig Export Plugin is good if you like exporting as LaTeX or such.

Tools -> Plugin Manager -> Enable export

Now you’ll have a better looking Geany to develop.


Installing WordPress on CentOS 6.x

Let’s say you’ve got your new CentOS 6.x server up and running, with a minimal install. It is very easy to install the necessary items (including Apache, MySQL etc.) alongside WordPress to fully function.

First, let’s install the plugged.in LAMP installer for CentOS 6.x With this script, you’ll get everything you need to turn your Linux box into a web server. Details on how to use it is available on plugged.in

After this, we can easily get the wordpress installation and simply extract it.

wget http://wordpress.org/latest.tar.gz
tar -xzvf latest.tar.gz

Now get into MySQL using the password you’ve specified to plugged.sh

mysql -u root -p

Below, we’ll create a new database and new user to affiliate with.

CREATE USER wordpressuser@localhost;
SET PASSWORD FOR wordpressusername@localhost= PASSWORD("password");
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressusername@localhost IDENTIFIED BY 'password';

Of course, you’ll have to replace “wordpressuser” and “password” with yours.
After creating the necessary database, we tell wordpress itself about these.

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
vi ~/wordpress/wp-config.php

Open and edit the wp-config.php file according to change the database info as below (yet again, replace with yours)

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');

Save and exit.
Now we should move our files to the user folder we've created with plugged.sh and change the files' owner.
cp -r ~/wordpress/* /home/username/public_html/
chown -R username:username /home/username/public_html/
chmod -R 755 /home/username/public_html/

Now visit your domain, or IP address on your browser. It will redirect you to the WordPress onscreen installation instructions. If it doesn’t, add “wp-admin/install.php” to the end. (like example.com/wp-admin/install.php).

And you’re done!

Also, if you want to import an XML file from your old WordPress blog or something, you’ll need to install the php-xml package.

yum install php-xml

Adding Cronjob via Script

Here’s another snippet I don’t want to forget,
adding a cronjob via scripting.
Here’s the source for it, : http://stackoverflow.com/questions/878600/how-to-create-cronjob-using-bash

Don’t forget that it only works on BASH! Doesn’t work on sh.

command="$mypath/autograph.sh > /dev/null 2>&1"
job="*/5 * * * * $command"
cat <(grep -i -v "$command" <(crontab -l)) <(echo "$job") | crontab -

UNIX Process Time Bomb

Here’s a simple script that kills a process if it lives longer than the time specified. It’s written in Python, and is available on github.

Usage : timebomb.py <process-name> <minutes>

Example : $ timebomb.py firefox-bin 20

Outcome : This will kill the process named firefox-bin if it has been running longer than 20 minutes.

Crontab : You should probably add this to your crontab!

Dependency : Standard UNIX tools : Python 2.4.x, pgrep, ps, kill etc.

# A Pythonic Time Bomb
# Kills Processes Living Longer than the specified time.
# Don't Forget to add it to your crontab!
# http://github.com/eaydin

import subprocess, sys
if len(sys.argv) != 3 :
    print "Usage : timebomb.py <process-name> <time-in-minutes>"
    print "Takes only and exactly 2 arguments."
    raise SystemExit
try : int(sys.argv[2])
except :
    print "%s is not an integer." % sys.argv[2]
    raise SystemExit
try :
    if a == '' :
        raise SystemExit
    else :
        procc = subprocess.Popen(["ps -o pid,bsdtime -p $(pgrep %s)"%(sys.argv)[1]],shell=True,stdout=subprocess.PIPE).communicate()[0]
except : raise SystemExit 
for lines in procc.split('\n') :
    if lines != '' :
        if l[0] == 'PID' : pass
        else :
            if int(l[1].split(':')[0]) >= int(sys.argv[2]) :
                try : killer = subprocess.Popen(["kill","-9",l[0]],stdout=subprocess.PIPE).communicate()[0]
                except : pass
            else : pass

My vimrc file

Here’s my vimrc file. Simple, not much, Just some basic stuff for coding.

" Setting the tab stop distance
set tabstop=4 shiftwidth=4
" Places "spaces" instead of "tabs"
set expandtab
" Show line numbers
set number

color torte

" Highlight the current line, also highlights only the focused window.
hi CursorLine cterm=NONE ctermbg=blue ctermfg=NONE
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
set cursorline

" Encoding
set encoding=utf-8

" Highlight Search Matches
set hlsearch

edit : maybe you’d prefer this extraordinary tool! http://bytefluent.com/vivify/