Draco's Weblog

My Personal Programming & Electronics Journal.

CodeIgniter Pagination Integrated With Bootstrap

| Comments

CodeIgniter pagination class is really cool, but I was having a hard time integrating it with the twitter Bootstrap CSS framework, it was something like an extra dozen config parameters while initializing the pagination library, so I had to modify the CodeIgniter pagination class to be compatible with Bootstrap.

I created a new file under application/libraries/ folder and called it MY_Pagination.php

The MY_Pagination.php file is included at the end of this post, feel free to use it in your projects. This version is compatible with Bootstrap version 2.3.2

I included most if not all of the Bootstrap pagination styling into this new library, so all I have to do later on is just initializing the library in the controller like so,

CodeIgniter Sessions Using PostgreSQL

| Comments

CodeIgniter is one of my favorite PHP MVC frameworks, it gives you the option to scale fast. Having a wide range of database drivers to choose from including postgres is a great option for me. I prefer PostgreSQL over MySQL for large projects where you have to insert 300k+ records daily or more. Of course you have to do some tweaks to your basic configuration of the PostgreSQL server to keep up with big data, but we might discuss this in a future post.

CodeIgniter offers a Sessions library to manage sessions your way instead of sticking to PHP server sessions variable $_SESSION. You can read more about it in the CodeIgniter User Guide V2.1.4: Session class.

It also gives you an option to save Session data into database, and it provides the database structure for MySQL, unfortunately this will not work with Postgres, so I created a Postgres version

1
2
3
4
5
6
7
8
9
10
CREATE TABLE  ci_sessions (
  session_id varchar(40) DEFAULT '0' NOT NULL,
  ip_address varchar(45) DEFAULT '0' NOT NULL,
  user_agent varchar(120) NOT NULL,
  last_activity bigint DEFAULT 0 NOT NULL,
  user_data text NOT NULL,
  PRIMARY KEY (session_id)
);

CREATE INDEX last_activity_idx ON ci_sessions(last_activity);

Saving the Session data into a database is more secure than cookies, and it gives you more options and functions, for example something like who is online and tracking active sessions.

Thanks, feel free to comment or suggest.

Maxmind GeoIP Using Python API

| Comments

GeoIP is a very important addition to projects, moreover keeping the GeoIP databases up-to-date. I’ll be using pygeoip python API along with Maxmind binary databases to create a simple python script that returns country name according to the supplied IP address.

Convert BIN/TOC Image to BIN/CUE

| Comments

So I was ripping a CD using Brasero and the output I got was a binary file along with a TOC file.

I wanted to mount this binary or convert it to ISO, so I came across this utility, toc2cue. which is is part of cdrdao port.

First install cdrdao, a read-write utility for CDs in disc-at-once mode

1
# portmaster sysutils/cdrdao

Then run the following command

1
# toc2cue filename.toc filename.cue

And you would have a cue/bin format which you can convert to ISO later using the procedures in this article.

Anyway I could have just used dd to create the ISO from a CD located at /dev/sr0 like so

1
# dd if=/dev/sr0 of=/path/to/file.iso

But it was nice knowing these utilities in case I came across these formats in the future.

FreeBSD: Build and Install a Custom Kernel

| Comments

FreeBSD is a very powerful OS and you can even achieve higher performance by modifying the Kernel and using the modules you need.

Before playing with the kernel you need to have the full FreeBSD source tree installed. The source tree lives in /usr/src

If you don’t have it then you can get it using subversion svn, follow this guide: Section A.5, “Using Subversion”.

A great resource for building a custom kernel is Chapter 9 of the FreeBSD Handbook, it should be your main guide through the process.

File System Index Node (Inode)

| Comments

The inode is a unique identifier in Linux/UNIX filesystems, it’s also known as the index number.

Definition on nixCraft: An inode is a data structure on a traditional Unix-style file system such as UFS or ext3. An inode stores basic information about a regular file, directory, or other file system object.

We can display the inode of a specific file name or a list of files in a directory by using the ls command.

Here is a typical output of files inode inside a directory,

1
2
3
4
5
$ ls -li
total 13
10376896 -rw-r--r--  1 draco  draco   200 Feb 11 19:01 test.c
10376892 -rw-r--r--  1 draco  draco   480 Feb 11 19:11 test.hex
10376897 -rw-r--r--  1 draco  draco   181 Feb 11 19:10 test

The numbers are the inodes of the respictive files.

One of the most common use of inodes is handling filenames with special characters or unicode like UTF-8, you cannot handle such filenames directly from the terminal, so you need to access it using its inode number.

My answer on StackOverflow to a related problem: http://stackoverflow.com/a/16216044/1708778

— Further reading: Understanding Filesystem Inodes (BSD DEVCENTER ONLamp.com)