Arrays in AWK

July 29th, 2008 1 Comment

Initializing an array:
The following code will create the months array. number_of_months will contain the length of the array (12).

number_of_months = split("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", months, ",");

Setting an array value using the key:
Array indexing in AWK starts at 1:

months[1] = "Jan";

Testing the existence of an array key:

if(2 in months)
{
  printf("The 2nd Month: %s\n", months[2]);
}

Iterating through an Array

Iterating through an array can be done using the key. The key can then be used to access the values inside the array
Note: Using this method, the order of the keys in the loop is arbitrary:
for(key in months)
{
  printf("Index %d: %s\n", key, months[key]);
}

Iteration can also be done using the incremental index method:
for (i=1; i<=number_of_months; i++)
{
  printf("Index %d: %s\n", i, months[i]);
}

Associative Arrays:

together["pees"] = "carrots";
together["gin"] = "tonic";

Deleting array elements and arrays:

delete months[12]; # Removes that element of the array
delete months; # Deletes the array itself

Opera Mini on the BlackBerry - Start PageOpera Mini 4 was released in November of 2007. The built-in BlackBerry Browser is okay for quick searches and such, but Opera Mini is far better for web browsing. Instead of showing a simplified version of web pages, Opera Mini will usually show the whole page as it would be shown in a desktop internet browser, allowing you to zoom in on the part of the page that you want to see (see screenshots below). A small cursor, which you can control with the scroll ball, allows you to move around the page and select links and form elements (such as text boxes and buttons).

The Start page, pictured above, gives you quick access to an address bar, searches, your customized list of bookmarks, and your recent history. New searches can also be added to the quick search bar using the “Create Search…” option available when entering text into a text field on any web site.

INSTALL

To install Opera Mini, open the browser on your BlackBerry, click the “menu” button and then click the “Go To…” link. Navigate to the Opera Mini download url, http://mini.opera.com/, and click on Download Opera Mini (as described on their download page).

CONFIGURATION

Once you have Opera Mini installed, I recommend that you review the settings. Setting the font size to “Small” was important for getting pages to look right on my BlackBerry Curve. Also, I like running in “full screen” mode so I can see as much of the page as possible at one time.

MORE CONFIGURATION

When attempting to Browse the internet with Opera Mini, your BlackBerry may pop up a dialog saying:

The application Opera Mini has attempted to access the network. Would you like to allow this?

Clicking “yes” will allow the connection to be made. In order to prevent this from popping up the future, I first tried going to Options->Advanced Options->Applications and changing all of the permissions for Opera Mini to allow, but this did not work. After doing some searching I discovered that this can be resolved by going to Options->Security Options->Firewall, and change the status to “Enabled”. The next time you browse the Internet with Opera, a dialog should pop up saying:

The application Opera Mini has requested a http connection to server4.operamini.com

This dialog box will provide a check-box for allowing “all http connections” in the future. Click this check-box and then click “Allow this connection”. This issue that made these steps necessary will hopefully be resolved in a future release.

SCREENSHOTS TAKEN ON MY BB CURVE

Opera Mini on the BlackBerry - New York Times - Zoomed OutOpera Mini on the BlackBerry - New York Times - Zoomed InOpera Mini on the BlackBerry - Wikipedia - Zoomed OutOpera Mini on the BlackBerry - Wikipedia - Zoomed In

Opera Mini on the BlackBerry - Slashdot - Zoomed OutOpera Mini on the BlackBerry - Slashdot - Zoomed In

 

 

 

 

 

 

 

 

Mediawiki is the server-side wiki software used by Wikipedia and many other wiki websites. Although installing Mediawiki and editing articles is very easy, there is a learning curve associated with developing and maintaining a wiki. This article aims to breakdown the things I learned in the process of building my first wiki site (Campers Wiki) and includes links to various pages that I found helpful.

INSTALL AND USER GUIDE

To start, here are some links related to the basics (downloading and installing MediaWiki and editing pages):

Download: http://www.mediawiki.org/wiki/Download
Install Guide: http://www.mediawiki.org/wiki/Manual:Installation
User Guide: http://meta.wikimedia.org/wiki/Help:Contents
Editor Cheat Sheet: http://en.wikipedia.org/wiki/Wikipedia:Cheatsheet

PRETTY URLS

Setting up pretty URLs is important for SEO (Search Engine Optimization): http://www.mediawiki.org/wiki/Manual:Short_URL

CACHING

Set up memcached to speed up mediawiki. Mediawiki will ask for the ip/port of memcached server during the initial install. On Ubuntu I was able to install via apt-get and set it up very painlessly. One downside, is that pages are cached and sometimes will sometimes not show changes immediately. An article’s cache can be purged by adding ?action=purge to the article’s URL.

EXTENSIONS

Mediawiki’s base functionality is limited in certain areas… Extensions can be added to improve it. The spam and template sections will involve setting up extensions.

SPAM

By default mediawiki is set up such that anonymous visitors can make changes. This makes it easy for anyone to make changes on the site, but leaves the site more open to spam… Thus, the 5 steps described in this article should be followed: Holy Grail for Blocking Spam in MediaWiki

TEMPLATES

Mediawiki articles can use templates to make life easier for editors and give articles consistency.

Here’s an example… This is the wikipedia article regarding PHP: http://en.wikipedia.org/wiki/Php
If you click on the edit this page tab at the top of that page, you’ll see the source code for that article. At the top is a section that looks like this:

{{infobox programming language
| name = PHP
| logo = [[Image:PHP logo.svg|180px|PHP]]
| designer = [[Rasmus Lerdorf]]
…..
}}

That is passing various parameters to the “infobox programming language” template. This creates the nice looking box on the right side of that article. That template can be edited by going to:
http://en.wikipedia.org/wiki/Template:Infobox_programming_language

Note: underscores and spaces are interchangeable in mediawiki URLs

That template (along with most other templates) uses if-statements to make the look cleaner when not all parameters are passed. These if-statements and other similar functions are only available if you install the Parser Functions Extension:
http://meta.wikimedia.org/wiki/ParserFunctions

More Information on Templates: http://meta.wikimedia.org/wiki/Help:Template
That information assumes the parser functions extension is installed

CHANGING THE DEFAULT SKIN

http://www.siteground.com/tutorials/mediawiki/mediawiki_skins.htm

CATEGORIES

All articles inside a wiki should be associated with one or more categories. This ensures that there are no orphan pages and makes it easy to find other articles associated with a particular article. It also ensures that search engines can properly index your wiki site. It is important that all wiki pages are categorized.

Info Regarding Categories: http://meta.wikimedia.org/wiki/Help:Category

Dave

SSH on the BlackBerryI just got a BlackBerry Curve. One of the first things I was interested in getting working was an ssh client. I was very pleased to find MidpSSH had a free mobile ssh client that worked on the BlackBerry. Here is the short and sweet installation (exact steps may vary depending on your BB version):

  1. Open the browser on your BlackBerry, click the “menu” button and then click the “Go To…” link. Navigate to the MidpSSH download url, http://xk72.com/wap (as described on their download page).
  2. Click on the “Latest Stable Release” link. Navigate to the BlackBerry Build section and download the OS version that matches your BlackBerry OS. Follow the on-screen steps.

The MidpSSH software should now be installed. When I attempted to connect to a server at this point I received the error:

Session Error - Writer: Invalid tunnel name

If you receive this error, refer to this forum post regarding Configuring Full Internet Access on your BlackBerry. I needed to configure my APN by going to Options -> Advanced Options -> TCP. The APN settings for common providers are listed on that forum post.

That’s it. You should now be able to create a new session in MidpSSH and make an ssh connection.

Dave