Pages

Wednesday 23 October 2013

Vi Tip: Search and Replace Text

There are times when you would like to change text within a specific range:
First show the line numbers using;

:set nu

Then do the search and replace task like so:

:start_line,end_lines/text_to_be_searched_for_and_replaced/replacing_text/g

Modifying multiple files in one stroke 

The other day, I was working on code and felt that I had to change the date creation function and make use of SQLAlchemy's server_default = text("sysdate") from a rather bizare default = datetime.now()

so I run this;

sed -e 's/default = datetime.now()/server_default = text("sysdate")/g' -i models/*.py

and all python files were updated

How to install RapidSMS in Ubuntu 12.10

RapidSMS is a free and open-source framework for dynamic data collection, logistics coordination and communication, leveraging basic short message service (SMS) mobile phone technology (according to rapidsms.org). RapidSMS is a python program built on top of django. This is a quick "how to" to have rapidsms quickly set up on an Ubuntu machine. It is seven step process.

How to view bios info

There exist a myriad of ways of retrieving hardware details of a host machine in Linux (as is case with Linux).
To extract information such as bios date, bios vendor, your board vendor and the like, you can use the virtual file system sysfs. That information is stored in the /sys directory.The precise directory is: /sys/devices/virtual/dmi/id So typing $head /sys/devices/virtual/dmi/id should display all the necessary details for you. You may also want to use sudo or su for elevated privileges to view some restricted files.An alternative method to retrieving info on your BIOS and even other hardware information from dmi is dmidecode. This usually requires root privileges to execute.
dmidecode is actually a dmi decoder what decodes readings from the dmi table.

Bash: List of commands (Executing Commands Sequentially)

The bash shell has an interesting feature where one is able to execute a list of commands sequentially. A list refers to a sequence of one or more commands that are separated by the following operators; '&', '&&', '||', ';', or the new line character.

Bash Tips: Command History

There are several ways of working with command line history in a bash shell. The history command helps you check what commands have been typed previously. The bash command line history is usually stored in the file .bash_history in a user's home directory (that is; if you use bash as your user shell-which is true for Linux (I run the 3.0.0.12 kernel). You can check which shell is your default from the /etc/passwd file. It is usually the last value after the last colon on your username line e.g:
user_name:x:1000:1000:FirstName LastName,,,:/home/my_user_name:/bin/bash
The command line history is controlled by HISTSIZE and HISTFILE environment variables...

Vi Tip: Prepending Text to multiple lines

There are cases when you want (for many reasons), to add same text to the beginning of multiple lines. This may happen when you are coding (say python) and then you realise that you need to enclose your function within a class. So you add the class definition at the start of the module file. You then need to indent the function, as python requires. To indent you need to add four spaces (or your preferred number). In vi, you do this like so;

Limiting the number of simultaneous user logins

When a user is created, the user generally has an unlimited number of simultaneous logins. This, I think, is generally not a good idea. There should be a limit to the number of virtual terminals that a user can open simultaneously. Those users who just cannot resist opening many terminals should seriously consider installing screen. Read on...

VirtualBox: Managing Virtual Machines In Headless Mode


Virtual Box is a virtualization software that allows many operating systems (guests) to run simultaneously on a host operating system. In the concept of cloud computing, virtualization has become the "in-thing". It is increasingly common for applications to be run on different virtual machines running on one physical machine/server. The guest operating systems (Virtual Machines) can be run in either headed or headless modes. The difference is that in "Headed" mode, the guest displays an interface similar to that displayed when the monitor is connected to the system. More...

Kismet: Ultimate Access Point Discovery Tool




Kismet is an absolutely incredible piece of software for Linux boxes to discover any wireless access points (AP) in your neighborhood. Even if the AP does not broadcast anything and is pretending to hide, kismet will bust it. Mac users have kismac.Kismet is one of the ultra modern wireless sniffers. It can and should be used in together with others such as aircrack-ng, airodump, airdecap, airreplay and others. I view these applications as complementary rather than competing.  Just read on

Remove files or directories in Linux

This is a comprehensive way to remove/ delete files/ directories from konsole, or Terminal (whatever you call your command line). `rm' removes each given FILE. By default, it does not remove directories. rm short form of remove deletes directories and files from your disk.

What is Intelligence - Isaac Asimov

What is intelligence, anyway? When I was in the army, I received the kind of aptitude test that all soldiers took and, against a normal of 100, scored 160. No one at the base had ever seen a figure like that, and for two hours they made a big fuss over me. (It didn't mean anything. The next day I was still a buck private with KP - kitchen police - as my highest duty.) Read More

Working with Microsoft Ofice Excel Files



Want to use HSSF and XSSF read and write spreadsheets in a hurry? This guide is for you. If you're after more in-depth coverage of the HSSF and XSSF user-APIs, please consult the HOWTO guide.  Read More...

Wednesday 15 May 2013

Vi Tip: Search and Replace

 Search and Replace Text in Specific Range

There are times when you would like to change text within a specific range:
First show the line numbers using;

:set nu

Then do the search and replace task like so:

:start_line,end_lines/text_to_be_searched_for_and_replaced/replacing_text/g

Example:


100 
101     def _set_attr(j_patient):
102         self.id = j_patient.pop("patient.id", None)
103         self.voided = j_patient.pop("patient.voided", False)
104         self.created_by = j_patient.pop("patient.created_by", None)
105         self.created_on = j_patient.pop("patient.created_on", None)
106         self.modified_by = j_patient.pop("patient.modified_by", None)
107         self.modified_on = j_patient.pop("patient.modified_on", None)
108 
109     def _set_patient(self, patient):
110         patient.id = self.id
111         patient.voided = self.voided
112         patient.created_by = self.created_by
113         patient.created_on = self.created_on
114         patient.modified_by = self.modified_by
115         patient.modified_on = self.modified_on
116     


So, to change the word patient to person only under the _set_patient function, do this:

:109,115s/patient/person/g

Friday 29 March 2013

Modifying multiple files in one stroke



The other day, I was working on code and felt that I had to change the date creation function and make use of SQLAlchemy's server_default = text("sysdate") from a rather bizare default = datetime.now()

so I run this;

sed -e 's/default = datetime.now()/server_default = text("sysdate")/g' -i models/*.py

and all python files were updated

Note: the letter g at the after the replacement text ensures that all instances of the
text to be replaced are actually replaced and not only the first instance if the g (global) were left out

Wednesday 6 March 2013

How to install rapidsms in Ubuntu (12.10)



RapidSMS is a free and open-source framework for dynamic data collection, logistics coordination and communication, leveraging basic short message service (SMS) mobile phone technology (according to rapidsms.org). RapidSMS is a python program built on top of django. This is a quick "how to" to have rapidsms quickly set up on an Ubuntu machine. It is seven step process.

Step 1: install python-django, python-pip.

$sudo apt-get install python-django
$sudo apt-get install python-pip

Step 2: Install rapidsms from the cheeseshop.

$sudo pip install rapidsms

If you have rapidsms installed already, then you can upgrade it:
$sudo pip install -U rapidsms

Step 3: Next install the http router

$sudo pip install rapidsms-httprouter

Step 4: Now that all is set, create a new project like so:

$cd
$rapidsms-admin.py startproject my_project

Please replace the my_project with the appropriate/desired name of your project.
Django will notice that you do not have a super user/admin account for the new project that you are creating so it will suggest that you create one. Enter the user name you desire and password. I suggest you oblige and enter these!

Step 5: Now create the db. If the name of the project in Step 4 was my_project, then;

$cd my_project

Else $cd name_of_your_newly_created_project

Now create/sync the db.
$python manage.py syncdb

Step 6: Try accessing the webUI of your newly created installation. Personally, I prefer running programs that capture my prompt using screen
So part (a) of this process is optional

(a) $screen

(b) $python manage.py runserver 0.0.0.0:8000
       or
       $python manage.py runserver

     $ Ctrl - A + D (to exit screen----you may need to read the screen manual pages)

       The first Option allows you to acess the rapidsms WebUI both locally and remotely and the second    allows you to access the rapidsms WebIU locally only. Personally, I prefer the first option because I develop most apps in VMs (Virtual Machines)

(c)  $python manage.py runrouter


You can access the admin interface that django assisted to create for you by typing this: http://your_ip_address:8000/admin. Enter the user name and password you created in Step 4.

There you are!!! You now have a barebones rapidsms installation.!!!