Archive for Notes

Dec
08

Screen Size vs. Viewing Distance

Posted by: | Comments (0)

The following is a rule of thumb on the minimum viewing distance for a certain screen size:

Display Type Minimum Viewing Distance
16:9 HDTV 1.5x Diagonal
4:3 HDTV 1.8x Diagonal
Analog 3x Diagonal
Categories : General, Notes
Comments (0)
Nov
18

Run as root only

Posted by: | Comments (0)

To make sure that a script will be run by root only:


#!/bin/sh

if [ `id -u` != 0 ]; then
  echo "Permission denied, must be root"
  exit
fi

# Do the thing...
Categories : Linux, Notes
Comments (0)
Nov
10

Authenticate Users

Posted by: | Comments (0)

This snippet could authenticate users using their /etc/passwd or /etc/shadow entry. May have to run this with higher than normal privilege:


#!/usr/bin/env perl

print "Username: ";
chomp($uname = <stdin>);

$pwd = (getpwnam($uname))[1]; # get the user's pwd
die "invalid user\n" unless defined $pwd and length $pwd;
$salt = substr($pwd, 0, 2);

system "stty -echo";
print "Password: ";
chomp($word = <stdin>);
print "\n";
system "stty echo";

if (crypt($word, $salt) ne $pwd) {
    die "Sorry...\n";
} else {
    print "ok\n";
}
Categories : Linux, Notes, Perl
Comments (0)
Nov
09

How to Burn CDs

Posted by: | Comments (0)

For accomplishing other tasks such as copying CDs, etc., try carefully reading the cdrecord manual page and, if necessary, consulting the canonical CD recording FAQ at http://www.cdrfaq.org/.

——————————————————

Creating a data CD:

Step 1: Make a directory to contain the files you want to place on the the CD. “mkdir /image/userdir/” is the standard method.

Step 2: Copy the files from wherever they are to the directory you just created.

Step 3: Create the ISO9660 image that will be burned on the CD. You do this using the mkisofs command. An example command is:


csh> cd /image/userdir/
csh> mkisofs -o /image/burn-image/.iso
-l -R -L -V "" -P "" -p "" -A "" .

-o: the name of the file that will contain the
     image
-l: use long file names
-R: use Rock Ridge extensions. This means
     that long filenames will be used, file
     uid/gids and permissions will be preserved,
     symbolic links will be included, etc. In
     other words, the CD will try hard to
     emulate a Unix file system.
[-r: This is like the -R option, but file uid/gid
are set to 0, files will be readable by anyone
and all write permissions will be removed.
Use this switch if you anticipate needing to
read the CD in an environment where your
uid/gid do not exist. E.g., if you are sending
to CD to another institution.]

-L: Allow file names beginning with '.'.
-V, -P, -p, -A: See the mkisofs man page.

The final argument (in the example '.') is the
name of the top-level directory containing
file data.

See the mkisofs manual page for further details.

Read More→

Categories : Linux, Notes
Comments (0)
Nov
09

Disable single user mode using lilo

Posted by: | Comments (0)

In your LILO configuration section, write something like:


image = /vmlinuz
        label = Linux
        root = /dev/hda1
        password = wingedlizard
        restricted
        read-only

Then chmod this file 600 (so nobody but root can read it) and re-run /sbin/lilo.

The “restricted” keyword means that LILO will stop and ask for a password if you try to boot this kernel with _any_ keywords such as “1″ or “single” or “init=/bin/bash”. A password won’t be required during normal (no-added-keywords) boots.

Categories : Linux, Notes
Comments (0)
Sep
06

401K and IRA Limits

Posted by: | Comments (0)

The maximum pre-tax amount one can contribute each year to 401(k), 403(b), and 457 plans as determined by the IRS:


         Year        Age<50        Age>50
        2005        $14,000          $18,000
        2006        $15,000          $20,000

After 2006, the maximum pre-tax contribution limit is indexed in $500 incrememnts for inflation.

Traditional and Roth IRA Limits:


         Year        Age<50        Age>50
        2005        $4,000            $4,500
        2006        $4,000            $5,000
        2007        $4,000            $5,000
        2008        $5,000            $6,000

The contribution limits presented above for traditional and Roth IRA are scheduled to expire Dec 31, 2010 unless legislation is enacted to extend them.

Categories : General, Notes
Comments (0)
Dec
13

Biko Recipe

Posted by: | Comments (0)

This is a modified version of one of the most favorite Christmas noche buena dessert in the Philippines. The recipe is basically modified for those transplanted Filipinos whose only coconuts they can find comes in a can.

Ingredients:

  • 1 can coconut milk (400 ml)
  • 1/2 c water
  • 1 1/2 c brown sugar
  • 1 1/2 c sweet rice
  • evaporated milk (optional)

Procedure:

  1. Get the sweet rice cooking in a rice cooker.
  2. Mix the coconut milk, water, and brown sugar in a sauce pan.
  3. Heat the sauce pan with all the mixed ingredients until all the water has evaporated and it is caramelized. This is now called the “latik”. You have to keep stirring otherwise it will overflow and you’ll create a mess and your wife will kick you out of the kitchen. It will take a long time for the solution to become caramelized (latik), so you better not be doing something else. Now here’s the secret trick. To determine the proper consistency of the latik, take a glass of water from the faucet. Drop (just a single drop) of the solution you’re stirring into the glass of water. If you see that the “latik” settled to the bottom in whole (coagulated), then the latik is done and deserved to be called a “latik”.
  4. Mixed the cooked sweet rice and the latik in a bowl. You have to do this little by little to coat every grain of rice with the latik. What I do is take a little bit of rice, pour a little bit of latik, and mix them together very well. Put it aside in a baking pan, and repeat until you finish all the rice. Don’t worry if you end up with extra latik, you can also eat your biko, while drinking latik on the side.
  5. Once you have all the rice coated with the latik in a baking pan, you can optionally coat the top with some evaporated milk and bake it at 325 degrees for 15 minutes or until the milk forms a crust at the top.

There you have it. Enjoy your biko either with Coke or tea. Merry Christmas!

Categories : General, Notes
Comments (0)
Oct
29

Obtaining File Size

Posted by: | Comments (0)

The following snippet will determine the file size.


#include <iostream.h>
#include <fstream.h>

const char* filename = "example.txt";

int main() {
    long l, m;

    ifstream file(filename, ios::in|ios::binary);
    l = file.tellg();
    file.seekg(0, ios::end);
    m = file.tellg();
    file.close();

    cout << "size of " << filename;
    cout << " is " >> (m-1) << " bytes.\n";

    return 0;
}
Categories : Cpp, Notes
Comments (0)
Oct
29

Write To A Text File

Posted by: | Comments (0)

This snippet will write a text file.


#include <fstream.h>

int main() {
    ofstream outfile("example.txt");
    if (outfile.is_open()) {
        outfile << "This is a line.\n";
        outfile << "This is another line.\n";
        outfile.close();
    }
    return 0;
}
Categories : Cpp, Notes
Comments (0)
Oct
11

Quick Command Line Arg parsing

Posted by: | Comments (0)

To parse command line arguments passed to a script without using a module, parse @ARGV with the following:


foreach my $arg (@ARGV) {
    $a = 1, next if $arg eq '-a';
    $b = 1, next if $arg eq '-b';
    $c = 1, next if $arg eq '-c';
}

Note: This is good only for boolean (on/off) command line switches.

Categories : Notes, Perl
Comments (0)