jon gales

Perl on your Mac part 2

By Jon Gales


If you missed my last lesson read
it before you read this one. If not you have a good change of being lost. If
you don’t feel 100% about last weeks lesson that is ok, you will after today.
The last lesson was a quick into to the basics of Perl, scalar variables and
the print function. We will be covering them both in more detail as well as
standard input and comments.

Scalar variables:

    • Always
    marked with a $ before ($scalar_variable)
    • Can contain A-Z, a-z, 0-9, and underscores in the name and must
    start with a letter.
    • Integers and character strings can be assigned as the value
    • Can be assigned different values in the same script such as:

    $one = 1;
    $one = 2; #$one now contains 2

    • Are
    case sensitive so $A and $a are two different scalars
    • Can be used in conjunction with each other such as:

    $one = 1;
    $two = 2;
    $answer = $one + $two;

    The operators
    for Scalar’s are

    as follows:

    Add

    =
    +
    Subtract

    =
    -
    Divide

    =
    /
    Multiply

    =
    *

    To increment
    a scalar (has to be a number) add ++ or — after it like:

    $value
    = 6;
    $value++; #the ++ increases the 6 to a 7
    print $value; #will print 7

    This is the
    principal that web counters work on. When a visitor visits the page it triggers
    a Perl script that reads a number from a file increases it by one prints it
    to the web and then prints it to file for the next time a hit is occurred.

Print
function:

The
print function is probably one of the most
important things you will need to learn
in Perl. Thankfully it is simple. Perl doesn’t
actually print things (on your printer)
it outputs them on screen. To print something
just put the following:

print
"WHAT YOU WANT TO PRINT";

You
can print scalars, strings, numbers, or
whole files (you will learn this at a later
date). Be careful to quote strings of text
(Perl will let you get away without quoting
scalar variables but not text strings).
Also don’t forget that ending semicolon.

Standard
Input:

We
briefly touched this in our last lesson
but not enough to thoroughly understand
it. The code for standard input looks like
this:

$VARIABLE_NAME
= <STDIN>;
chomp($VARIABLE_NAME);

That
chomp isn’t always needed but is a good
idea because sometimes input can get an
extra line in it and we don’t want that.
If there is nothing to chomp it does nothing.
This code picks up whatever was typed in
and dumps it into the $VARIABLE_NAME variable.

Comments:

Comments
are pieces of text that are solely meant for
human readers of the code. The computer automatically
ignores them. In Perl they are marked by a
pound sign #. Everything after a pound sign
is ignored. You have to comment every line
(there are no multi-line comments in Perl
like there are in C, PHP, and many other languages).
Commenting is a really really really really
(did I make my point?) good idea. Even if
you code looks good after your 5th Mountain
Dew at 3 a.m. I promise you it won’t look
good when your boss is looking over your shoulder
at 9 a.m. The first line of every Perl script
is a comment but this one isn’t ignored, it
tells the comp where to find Perl.


A
simple program using: Scalar Variables, Print
Function and Standard Input and comments is
below:

#!/usr/bin/perl
print "How old are you?
"; #prints
question
$age = <STDIN>; #puts response into
scalar
chomp($age);#get rid of that new line
$age_days = $age * 365; #times age by number
of days in a year
print "You are approximately $age_days
days old
"; #print answer

If
you are in X make the code a text file ending
in .pl and chmod it to 755. Then you can run
it by typing the path to file in the terminal.

 

Homework:
Your homework is to mess with the X
terminal. Practice writing stuff in pico and
chmoding it and moving around the directory.
Here are a few commands to get you started:


ls lists current directory
• cd changes directory (cd usr moves you
to the usr folder, cd / always moves you back
to the root directory).

If
you are on Classic you don’t have any homework
except to get OS X as soon as you can. It is
the future and kicks butt for Perl!

If you are having trouble or would like to ask me a question
please send me mail: jonknee@macmerc.com
or chat through AIM:
jonknee41 (add to buddy list)

Intro to Darwinism

By
Jon
Gales

No,
this isn’t going to be a religious or scientific battle about the origin of
our universe. It’s going to be a first look at Darwin, the underlying level
of Mac OS X. Right now you are probably asking yourself why, how, or are confused
as to what Darwin really is. I can give a you a great nutshell answer for each.
Strap on your geek boots, here we go!

 

What:

Darwin
is FreeBSD for the PowerPC processor (G3 and up actually). It is open source
and can be downloaded free of charge from http://darwin.org/projects/Darwin/1.3/release.html
(an Apple site). The download is about 120 megs and the installation can’t
be easier. If you have ever tried to install Linux you will envy Darwin’s
install. It is truly drag and drop (and there’s not even any dragging!). Just
double click, select an empty partition and you are in UNIX. I said before
that Darwin is the underlying level of OS X. Here is what that means:

Aqua


Carbon Classic Cocoa

Open
GL
Quartz QuickTime


DARWIN

As you can
tell, Darwin is on the bottom of our chart; this means it controls all the
base level OS operations. You can access Darwin in the Terminal.app in OS
X (in the Utilities folder). That’s all good but we power users want more.
For that we move to why.

Why:

Why not? Well,
it isn’t user friendly, has no native GUI (X Windows can be installed but
isn’t part of Darwin), can’t run any of your applications, and the list gets
longer. What it does, it does well: all UNIX functions. Aqua is beautiful
but takes RAM and CPU cycles. That is a waste if you are using your box as
a server. OS X has real powerful server tools like Apache built-in, and MySQL
and PHP can be installed making OS X a powerful web server. The same server
can be run from Darwin without the wasted RAM and CPU cycles that Aqua brings.
In fact, Darwin can be your network’s NAT server (for sharing net access).
You can have an older G3 serve as your router/firewall/webserver all without
paying a dime. Even if you don’t want to use those features there is no easier
way to learn UNIX (except using it in the terminal).

How:

Once you run
the installer, go up to the startup disk control panel and select the disk
(or partition) with Darwin on it. If you don’t want to make it the default
disk, just hold Option at startup and select the boot disk at that point (instead
of using the startup disk control panel). After a few minutes you will have
a blinking cursor; type the following:

root

You will get
the following message: "Welcome to Darwin!". This signifies that
you are all logged in and are ready to do anything you choose. Here are the
commands I found most useful:

ls
= list files in current directory
cd
= change
directory (cd / takes you to the main directory)
mkdir
= make directory, creates folder

pico
= opens
up pico (a text editor). A file string followed by pico will open that file
in pico (Ex: pico /files/test.pl will open a file called test.pl located in
the /files directory)

All the OS
X directions in my Perl
tutorial
apply to Darwin (since it is OS X).

To connect
to the internet I edited the /etc/iftab file in pico to read:

en0
inet 192.168.1.102 netmask 255.255.255.0 up
en0 inet -DHCP-

The IP address
is specified by my router so that will change depending on your setup. If
you aren’t on DHCP try following the directions on this site: http://www.excel.net/~clobrien/darwin/Network.html

After I was
on the net I did an FTP transfer. To connect to an FTP server type:

ftp
ftp.servername.TLD
(replace TLD with the ending tld)

It will prompt
you for a username if necessary and then a password. You can use the cd and
ls commands to move around the file tree. Type: get FILENAME to download
files and: put PATH/TO/FILE.txt to upload files. Type ? for
a list of all commands.


That was my
experience with Darwin… I will write another article once I get PHP and
MySQL going (I am having some difficulties forwarding the right ports to my
computer at the moment).

 

If
you are having trouble or would like to ask me a question, please send me mail:
jonknee@macmerc.com

Extreme IE customization – Graphical Favorites

By: Jon Gales

Although very few people will admit to being a fan of Internet Explorer,
most Mac users will come in contact with it quite frequently. Although OmniWeb
and Chimera are good
browsers, IE still has more compatibility. I recently found a way to make Explorer
a little nicer ñ graphical
favorites:

ie gfx only Extreme IE customization   Graphical Favorites

The trick makes your "must have" sites more visible
while giving them a nicer appearance.

The first step is to make the graphic. Go to the site that you want to have
the graphical link to and look for a logo. In my case I went to MacMerc (big
surprise!) and found our logo. To save this to your desktop you can either click
on it and drag it to your desktop or control-click on it and choose "Download
Image To Disk"
. It’s your call but control clicking might be a little
easier if you’ve never dragged an image to the desktop before.

Once you have it saved to your computer you need to resize it. Although IE will
try to automatically resize it, the result will look like trash. I used Photoshop
[screen
shot]
but any basic image editor with resizing capability will work –
even iPhoto! If you
are using Photoshop and the logo is a gif (like it is in MacMerc’s case) the
mode needs to be switched to RGB [screen
shot]
Once the image has been resized it needs to be cropped [screen
shot]
. I saved off my image as ‘logo.gif’ and put it on my desktop.

Now open up a text editor and type
in the following code. If you are using TextEdit type Command-
shift-T before starting to type anything (switches to text mode). To save some
typing download (control-click and choose Download Link To Disk) this
file and open it in TextEdit (no preference hacking needed). Whichever way you
chose your file should be as follows [screen
shot]
:


<a href="http://www.macmerc.com"><img
src="logo.gif" alt="MacMerc"></a>


The image (logo.gif)
will link to http://www.macmerc.com
and it’s title (underneath the image) will be "MacMerc". You
can obviously change these if you are doing another site. If you want to do
several sites at once feel free to keep adding code – you don’t have to
delete the first line before adding a second. Download a transparent gif of
the logo if you can. Otherwise it may look a little funny on your tool bar!
You can always make a logo transparent in Photoshop if need be but most of the
times you should be able to find one. If you can’t make out the logo at the
small size either make up a new one in Photoshop or find a new site! Not all
sites have logos that fit well in the little space.

Put the text file, and image in a
folder (you can call it anything you like). Place this folder someplace that
it won’t be moved (/Users/username/Documents is a good place). If it does get
moved your bookmark will bust! Open the text file in Internet Explorer
by dragging in into a blank browser window, dragging it to the Dock icon or
choosing open in IE. Once the file is open you should see the logo you lovingly
prepared. If not go over what you did… If you’re still having trouble email
or IM [AIM: jonknee41] me and I’ll walk you through it. If you want to add MacMerc
I have posted the graphic I used here.

Once you have the logo just
drag it to the top tool bar [screen
shot]
, the logo should "stick" afterwards. If you need to delete
it or just want to see the text/image control-click in the top menu bar [screen
shot
] and choose the appropriate option. [screen
shot of graphics only]
[screen
shot of text only]

Most people will want to add Google
(as well as MacMerc…) and I have one more trick that will save you even
MORE time. Instead of linking to http://www.google.com
use this URL:

javascript:void(q=prompt(”,”));if(q)void(location.href=’http://www.google.com/search?q=’+escape(q))

The code for the page will look like
this:

<a
href="
javascript:void(q=prompt(”,”));if(q)void(location.href=’http://www.google.com/search?q=’+escape(q))">
<img src="logo.gif" alt="Google!"></a>

What it will do is pop up a box in
IE that you type your query into. Hit return and you’re taken to the results
page of Google! No need to hit the front page! You can easily customize this
javascript to work with a bunch of search sites like dictionaries, and image
search engines. It’s quite a time saver!

If you find any cool tricks that stem from this idea please send
them to me and I’ll let the rest of the world know (and also credit your name
of course). Also, if you go wild with this and want to send me a screen shot of your tool bar go ahead! I’d love to see/post what everyone has done.



macmerc Extreme IE customization   Graphical Favorites
MacMerc

joyoftech Extreme IE customization   Graphical Favorites
The Joy of Tech

ay2k Extreme IE customization   Graphical Favorites
After Y2K

apple Extreme IE customization   Graphical Favorites
Apple

macdesign Extreme IE customization   Graphical Favorites
MacDesign

macupdate Extreme IE customization   Graphical Favorites
MacUpdate

macsurfer Extreme IE customization   Graphical Favorites
MacSurfer

powerpage Extreme IE customization   Graphical Favorites
O’Grady’s
Powerpage

macminute Extreme IE customization   Graphical Favorites
MacMinute

macaddict Extreme IE customization   Graphical Favorites
MacAddict

macfans Extreme IE customization   Graphical Favorites
MacFans

unsanity Extreme IE customization   Graphical Favorites
Unsantity

iconfactory Extreme IE customization   Graphical Favorites
IconFactory

googlepopup Extreme IE customization   Graphical Favorites
Google
(Pop-up)

google Extreme IE customization   Graphical Favorites
Google

macmusic Extreme IE customization   Graphical Favorites
MacMusic

hsx Extreme IE customization   Graphical Favorites
Hollywood Stock
Exchange

imdb Extreme IE customization   Graphical Favorites
IMDb

audible Extreme IE customization   Graphical Favorites
Audible.com

amazon Extreme IE customization   Graphical Favorites
Amazon

thescreensavers Extreme IE customization   Graphical Favorites
The Screen Savers

techtv Extreme IE customization   Graphical Favorites
TechTV