MacMerc.com is Back!

MacMerc.com is back… but why did it go?

I’m happy to announce the return of MacMerc.com and my intention to resume production on MacMerc.TV. It must have seemed strange after so much attention and effort was made to launch an ambitious podcast that was so well received (thank you all for that) to then not only stop producing that show but to take down the site that hosted it.

Believe me, it wasn’t part of the plan.

Let me take you back a year or so and I’ll try to explain.

Shortly after I launched the podcast, I started up a friendship over Twitter with Greg Grunberg ( @greggrunberg ) from NBC’s HEROES. He is an amazing guy with all kinds of projects on the go. At the time he told me about an idea he had for an iPhone app that would bring up coupons based on where the user was in proximity to the stores. He wanted to know if I knew anyone who could develop it. I did, of course. I connected him with my friend from my days on The Wizards of Technology, August Trometer ( @august ).

That was the start of the whirlwind of activity that became Yowza!! Mobile Coupons ( @yowza ). In the early months it took over a lot of my time and even distracted me from my day job a fair bit. I had no time to write blog posts, much less scripts. There was definitely no time for shooting and editing.

In the midst of all that, a hacker came a-hackin’ (it’s what they do). Somebody was repeatedly compromising MacMerc.com’s security and posting all kinds of filth and horror. With all the other stuff happening in my life, I couldn’t handle this as well. The only person that knew the site well enough to defend it was also the guy I recommended when Greg asked if I knew any coders, and he was busier than me.

I was sunk.

My only defense was retreat.

Through my friendship (and internship) with Cali Lewis at GeekBrief ( @calilewis ), I had met some amazingly wonderful people and made some great friends. One of them, Daynah ( @daynah ) came to my rescue and put up a “be back soon page” and went to work converting the data from my antiquated pre-Typepad content management system over to WordPress. She did a great job and I am so thankful for her help.

My participation with Yowza!! is much less than it was and I, once again, have time for blogging, script writing and podcasting.

Let’s dig in!

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