Autostart KDM in Slackware 12

Posted by strasm on June 5th, 2008

To get X to start in Slackware 12 you have to do a couple of things. First, edit /etc/inittab change the line like this:

id:3:initdefault:

to be

id:4:initdefault:

Now when you reboot you it works. Not so fast… When you try to login as any user other than root you get the error “your login shell is not listed in /etc/shells.” Despite many of the blogs I read this is not caused by the /etc/shells file. To fix this change the default shell of the user to be bash like this:

# chsh username

Enter the new value, or press return for the default

Login Shell [/bin/bash]:

Press enter and you are done. Now the error is gone and you can log in.

Fix Serial Port Permissions in Slackware

Posted by strasm on June 5th, 2008

In a recent project we needed to give access to non-root users so that they could run programs that read the serial ports. Using chmod or chown will not work. I came across a blog that showed how change permissions for devices. Basically you have to change the udev rules. You can find more detailed information on udev rules here.

In Slackware 12 it was easy to fix. I opened /etc/udev/rules.d/50-udev.rules and went to the section titled “#Serial or Dialout Devices.” Then I changed the port permissions from 0660 to 0666. The default group was uucp so I added users to that group. It now works as I expected.

PHP Pagination Class

Posted by strasm on April 18th, 2007

There are a few reasons that you might want to spit a query into multiple pages. The main reasons are to break up lots of data to make it easier to see, or to speed up big queries by limiting the results to a certain amount. When I coded class.pagination.php I wanted to make sure that it would be easy to skin as well as work with mod-rewrite. More importantly it had to work with complex pages that used an unlimited amount of join statements.
Here is a simple example. Make sure that you put the noted CSS classes in your style sheet. Say you want to break up a query on index.php?module=users. You can do use it like this:
[CODE]

require_once(”class.pagination.php“);

/* figure out what the link is for later */
$pagelink = “index.php?module=users”;
/* include class */
require_once(”../include/pages.class.php”);

/* get the page */
$page = $_GET[page];
if(!$page){ $page = 1; }

/* initialize variables */
$pageObject = new Pagination;
$pageObject->current_page = $page;
$pageObject->num_per_page = “50″;
$pageObject->link = $pagelink;
/*
* set up count query
*
* note that this is similar to your main query
*
*/
$countquery = “SELECT COUNT(ID) FROM users WHERE authority = ’staff’”;

/* count how many pages */
$count = $pageObject->getCount($countquery);

/* get limit clause for main query */
$limitsql = $pageObject->getLimits($count);

/* get pagination navigation to print at end */
$pagenav = $pageObject->getNavigation($count);
$mainquery = “SELECT * FROM users WHERE authority = ’staff’ “. $limitsql;

$data = mysql_query($mainquery);

while($row=mysql_fetch_array($data)){

//do something here

}

/* echo out the menu */
echo $pagenav;

[/CODE]

Converting Numbers to Text

Posted by strasm on April 12th, 2007

Here is a couple of functions that will convert numbers into text. I originally coded this in PERL back in college, but came across a need for it in PHP for one of the projects I was working on.

It is very easy to use. Here is an example:

[CODE]

include_once(”numbers-to-text.php“);
$string = NumbersToText(”1554.32″);

echo $string . “<br />\n”;

[/CODE]

Because I was coding this for use with dollar amounts these functions do no go beyond 2 decimal places. Also the highest number it will convert is 999,999,999,999,999.99. Once you see the pattern of how it works, it is easy to change it to meet your requirements.