Archive for the ‘Uncategorized’ Category

Functional dependencies: How databases relate

Tuesday, December 8th, 2009

“The single most important concept in relational schema design theory is that of a functional dependency,” write Ramez Elmasri and Shamkant Navathe in “Fundamentals of Database Systems.”

But what is a functional dependency? It is the actual relationships in the relational database. It is the relations among the attributes within a table. It is a constraint between two sets of attributes. The relations are permanent and unalterable.

For instance, a table may have two attributes, or columns. If one is the primary key, we can then say we can always determine the value of the second attribute using the primary key. This means we can use the primary key as an index to look up the second attribute. It is a mathematical certainty. The primary key is the determinant and the other is the dependent, the parlance of database-speak.

(Keep in mind that this relationship does not work in reverse. You can not use a dependent value to definitively determine the primary key, chiefly because the dependent value may not be unique in a given table).

Beyond the simple connection drawn between the primary key and the dependents, a number of other inferences can be made as well, using Armstrong’s inference rules, which cover the laws of logic such as transitivity and reflexivity.

All material taken from a class I’m attending at UMUC on relational databases, as well as from the book….



…All mistakes are my own, though..
–Joab Jackson

CSS: Making a Box for a Web Page

Wednesday, July 1st, 2009

I needed to make a box on the right hand of my Web site, to hold some information. It turned out to be pretty easy: I used the CSS Box Model.

First, add the CSS box model specifications in the header of your html document:

<style type=”text/css”>
#box {
width: 200px;
height: 650px;
float: left;
margin: 1px;
border-color: black;
border-style: solid;
border-width: 30 px;
background-color: #F00;
padding: 1em 2em;
}
</style>
</head>

Note: You can also put them in a separate CSS stylesheet, but for simplicity’s sake, we’ll place it in the document this time around.

Then, add in the box where you need it in the HTML part of the document:

<div id=”box”>
Test in the box goes here.
</div>
</body>
</html>

I’ve shamelessly lifted these examples from a fine Tech Republic tutorial.

The full set of box model attributes can be found in W3C’s specification. You can get quite fancy with placement, fonts and whatnot.

Now you’d think you could use “align” to put the box’s “div” tag, right? Wrong! It’s been deprecated. Use “float” and place it in the CSS spec instead.

For a crude example of this in action, see the code for my home page.

–Joab Jackson

Unix: Removing outside Root access from Ubuntu

Saturday, March 28th, 2009

Every Unix box has a root account, or an account that has absolute control over the machine, its files and controls.

From all accounts, admins should use this account sparingly, only for cases where cross-system control is needed. You can make big mistakes (i.e. wipe out the system with a badly-worded command) from root. If you have work to do that can be done from a user account, use that instead.

Ubuntu has taken this precaution to the next level. When you install Ubuntu, it disables the root account. If you want to do root commands, you issue them from your account through the “sudo” command. basically sudo allows you to issue commands from another user’s account (assuming you have the password).

The idea behind this is that not only will it limit the mistakes you may make, but also reduce the attack footprint of your server. A cracker, trying to get in via SSH, doesn’t even get the option to guess the password to the root account to gain entry, because root can’t log in from SSH at all.

Now, like many old Linux codgers, as soon as I set up Ubuntu, I enabled the root account, mainly because filling in a password every time I wanted to do something in root was a pain. But I just learned that sudo actually has an option (sudo -i) that will allow you to work within a shell of a user account entirely–this means you evoke sudo once and then every thing you do from the command line is done from the account you’ve sudo’d in from, such as root. which is pretty neat, and eliminates the need to be able to access root from the outside (i.e. via SSH).

But if you already enabled root on your Ubuntu, how do you un-enable it? Simple, from the root account, use the psswd command to “lock” the account, i.e. make it inaccessible from outside users. “passwd -l root”

–Joab Jackson

Unix: Getting the most from the “ls” command

Thursday, March 19th, 2009

You can learn a lot from the the Unix “ls” command, once you know all the options. If you come from the world of Microsoft DOS, then ls is Unix’s version of “dir.” From the command prompt, type in

#ls

will return a list all the files and directories in the current directory are in.

As in many Unix commands, there is a great deal you can do with the ls’s additional options. Options are noted by the “-” sign, followed by a letter deisgnating which option to use. Note which case is used for the option, as they are case-sensitive. Here are some useful options:

#ls -l
….This of the verbose listing, offering, in addition to the name of each file/subdirectory, alkso offers (in this order): user permissions, the user permissions, owner, and group that the item belong to.

size of file, last modified

#ls -a
….Lists hidden files, those files that start with a “.” . Use this for finding system files.

#ls -F
….Appends each entry with either a “/” (to indicate it is a directory), a “*” (executable file) or “@” to show it is a symbolic link.

#ls -G
….Lists the group each file is owned by.

#ls -i
….Lists the innode (storage location on the disk) for each file.

#ls -L
….Lists the files referenced by the symbolic link, ratherthanthe names of the links themselves (if using symbolic links. See future entry on symbolic links).

#ls -m
….Separates each file and directory with a comma.

#ls -n
….Lists each file along with group identifying (GID) and user-identifying (UID) numbers instead of the group/owner names, respectively.

#ls -o
….Show owner with names.

#ls -p
….Indicate the directories by appending “/” onto the end of their names.

#ls -r
….List in reverse alphabetic order.

#ls -R
….List the contents of all the subdirectories.

#ls -s
….List the size of each file in blocks.

#ls -t
….List files in order of when they were modified, starting from the newest (but no dates).

#ls -u
….List files in order of when they were accessed, starting from the newest (but no dates).

#ls -t
….List one per line.


Some end-notes:

1. Using multiple options at once: Multiple options can be used together, i.e.

#ls -u1
…lists the files in order of when they were last accessed, one per line.

2. Piping ls results into a text file: Normally, when you use ls, it drops the input onto the screen. But you can also send the results (or “pipeline” them) to a file, using “>.” i.e.

#ls -a > [nameoffile]

If no file with that name exists, a new file is created with that name. The results can be piped into other commands as well. Check for future entries on pipelining.

3. Wildcards: Wildcards can be used to pick out only those files you are looking for. I.e.

#ls S*
…Will return only those files that start with the letter S.


A full list of working commands can be found on the ls man page, here. More explanation can also be found here. Also, check out Unix in a Nutshell by Daniel Gilly (O’Reilly).

–Joab Jackson

Time: The OS and the delivered time packet

Monday, February 16th, 2009

NTP gets the time to the client, but how does the operating system adjust its own time to this new time? The IETF put forth a generic way in RFC 1589.

The Unix kernel is alerted by a hardware counter interrupt at some fixed rate. In the 1589 scheme, OS’es keep the time by an accumulation of microseconds. It is some multiple of a hardware counter interrupt, which takes place at a periodic fixed rate, depending on the frequency of the counter (Which, by default, must be some divisor of the CPU frequency[?]). If this number does not divide evenly into a microsecond, the OS adds in some small sum periodically.

For instance, in the Ultrix kernel gets interrupted at 256 Hz. Since this does not divide evenly into a microsecond, the kernel adds 64 microseconds in each second.

For Unix systems, the NTP-driven clock adjustments are made using the adjtime()system call. One trick though: The clock frequency is changed by the value tickadj, which means the time can be slewed only by that amount(?). This rounding error can accumulate to such a degree the time is eventually wrong. As a result, a synchronization daemon must make an adjustment(?).

–Joab Jackson

Time: Why did Linux falter after this year’s leap second.

Wednesday, January 14th, 2009

From the Linux kernel mailing list, 3who discussed the item on Slashdot:

On the day after Dec 31 (in which a leap second was added onto UTC, and filtered via NTP to Linux servers), admins started reporting some older Linux kernels crashing.

Linas Vepstas wrote in that 32 users reported 53 crashes. They were hard-hangs and versions affected seemed to be 2.6.21, 2.6.26 and 2.6.27.

Vepstas suspected that when NTP bumped added the extra second, it started a race condition in the kernel, which basically called brought about a deadlock, very similar to this one.

Chris Adams traced the problem, literally.

the leap second code is called from the timer interrupt handler, which holds xtime_lock. The leap second code does a printk to notify about the leap second. The printk code tries to wake up klogd (I assume to prioritize kernel messages), and (under some conditions), the scheduler attempts to get the current time, which tried to get xtime_lock => deadlock.

Duane Griffin provided a quick patch to the problem. “the quick-n-dirty fix would be to not try to printk while holding xtime_lock (I think the NTP code is the only thing that does),” he explained, adding that a better fix would offer some advanced notification.

As it turns out, NTP may be the only widely-used function that printk’s while holding the xtime_lock, so to speak.

–Joab Jackson