<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hilarymason.com - Hilary Mason &#187; articles</title>
	<atom:link href="http://www.hilarymason.com/category/articles/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hilarymason.com</link>
	<description>I&#039;m a computer science professor, data scientist, and web geek.</description>
	<lastBuildDate>Mon, 26 Jul 2010 13:02:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Intro to the Linux Command Line</title>
		<link>http://www.hilarymason.com/blog/intro-to-the-linux-command-line/</link>
		<comments>http://www.hilarymason.com/blog/intro-to-the-linux-command-line/#comments</comments>
		<pubDate>Fri, 05 May 2006 01:48:29 +0000</pubDate>
		<dc:creator>Hilary Mason</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.3greeneggs.com/wp/articles/intro/intro-to-the-linux-command-line/</guid>
		<description><![CDATA[<p>This document will step through the process of accessing a Linux server, and several basic commands.</p>
			<h3>SSH</h3>
			<p>We will access the server via the <a href="http://en.wikipedia.org/wiki/Ssh">SSH</a>, or "Secure SHell", protocol. SSH provides encrypted communication between two terminals. It is an alternative to telnet or rlogin.</p>

			<p>First, make sure that you have an SSH client. If you are running Windows, I highly recommend <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">downloading Putty</a>. Click on the top Windows binary and save it to the desktop. You can run Putty.exe directly, without installing.</p>]]></description>
			<content:encoded><![CDATA[<p>This document will step through the process of accessing a Linux server, and several basic commands.</p>
<h3>SSH</h3>
<p>We will access the server via the <a href="http://en.wikipedia.org/wiki/Ssh">SSH</a>, or &#8220;Secure SHell&#8221;, protocol. SSH provides encrypted communication between two terminals. It is an alternative to telnet or rlogin.</p>
<p>First, make sure that you have an SSH client. If you are running Windows, I highly recommend <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">downloading Putty</a>. Click on the top Windows binary and save it to the desktop. You can run Putty.exe directly, without installing.</p>
<p>If you are using OS X, open a terminal and run &#8217;ssh&#8217;.</p>
<h4>Logging In</h4>
<p><a style="border:0;margin:0 25px 0 8px;float:right;" href="http://www.hilarymason.com/wp-content/uploads/2006/03/putty_thumb.jpg"><img id="image68" style="border:0;" src="http://www.hilarymason.com/wp-content/uploads/2006/03/putty_thumb-150x150.jpg" alt="putty_thumb.jpg" width="94" height="96" /></a></p>
<p>Type your hostname into the box. You can find your hostname by asking your ISP, but a good bet is that &#8220;www.yourdomain.com&#8221; will resolve to your server. You may need to request shell access</p>
<p>Click open. You&#8217;ll be presented with a warning, because you haven&#8217;t connected to that machine before. Approve the connection.</p>
<p>Next, you&#8217;ll see a login prompt. Enter your username. These will be assigned in class, but a good guess is your first initial and last name.</p>
<p><a style="border:0;margin:0 8px 0 25px;float:left" href="http://www.hilarymason.com/wp-content/uploads/2006/03/terminal_full.jpg"><img id="image69" style="border:0;" src="http://www.hilarymason.com/wp-content/uploads/2006/03/terminal_full-150x150.jpg" alt="" /></a></p>
<p>Enter your password. Both your username and password are case-sensitive.</p>
<p>You should see a screen like the one to the left. Congratulations! You&#8217;re logged into the system.</p>
<h4>The Prompt</h4>
<p>You&#8217;re now looking at an <span class="term">interactive shell</span> prompt. The shell accepts the commands that you type and sends them to the kernel, which executes them. This is how you interact with the operating system.</p>
<p>The prompt currently shows your username, the name of the machine (PVDACDLN-01), and your current directory (~, see below).</p>
<p>By default, our system assigns users to the <span class="c">bash</span> shell. There are many different shells available. In general, they all do the same thing, so most users choose a shell based on what they are most comfortable with.</p>
<p>Tip: By default, OS X uses <span class="c">bash</span> as the shell in a terminal. All of these commands will work nearly identically in OS X.</p>
<h3>Commands</h3>
<p>The remainder of this document is an introduction to Linux commands and a reference.</p>
<h4>The Filesystem</h4>
<p>The Linux filesystem is organized into a heirarchical series of folders, or directories. &#8216;/&#8217; indicates the <span class="term">root</span> directory, which contains all other files and directories.</p>
<p><span class="command">pwd</span> &#8211; pwd stands for &#8220;print working directory&#8221;. It <a href="http://en.wikipedia.org/wiki/Echo_%28computing%29">echoes</a> the current directory to the screen (this is where, in the filesystem, you currently are).</p>
<div style="border: 1px solid #000000; padding: 2px; width: 300px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">pwd</span><br />
/home/ham</div>
<p><span class="command">cd</span> &#8211; cd stands for &#8220;change directory&#8221;. It changes your current working directory to a new directory. If you try to change to a directory that does not exist, you&#8217;ll get a <span class="c">No such file or directory</span> error.</p>
<p>Tip: you can type &#8220;<span class="c">cd ~</span>&#8221; at any time to return to your home directory, or, if you know someone&#8217;s username, type &#8220;<span class="c">cd ~username</span>&#8221; to cd to their home directory.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 300px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">cd public_html</span><br />
[ham@PVDACDLN-01 public_html]$</div>
<p><span class="command">ls</span> &#8211; ls stands for &#8220;list&#8221;. It prints a list of files and directories in the current working directory to the screen. This version of <span class="c">ls</span> presents directories in blue.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 350px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 public_html]$ <span style="color: #dddddd;">cd ~</span><br />
[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">ls</span><br />
example.txt  <span style="color: #0000ff;">public_html</span><br />
[ham@PVDACDLN-01 ~]$</div>
<p>The <span class="c">ls</span> command also accepts various arguments that change the output of the command. For example, the &#8220;<span class="c">-a</span>&#8221; argument means &#8220;display hidden files&#8221;, while the &#8220;<span class="c">-l</span>&#8221; argument means &#8220;use long listings&#8221;. Command-line switches can be used singly or combined.</p>
<p>Filenames that begin with a &#8220;.&#8221; are hidden by default. Also note the &#8220;.&#8221; (current directory) and &#8220;..&#8221; (parent directory) operators.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 550px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">ls -a</span></p>
<p>.              .bash_logout   .bashrc_backup  .gtkrc       .viminfo<br />
..             .bash_profile  .emacs          <span style="color: #0000ff;">.kde</span> .zshrc<br />
.bash_history  .bashrc        example.txt     <span style="color: #0000ff;">public_html</span><br />
[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">ls -l</span></p>
<p>total 12<br />
-rw-r&#8211;r&#8211;  1 ham users    0 Feb 21 11:38 example.txt<br />
drwxr-xr-x  2 ham users 4096 Feb 21 11:32 <span style="color: #0000ff;">public_html</span><br />
[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">ls -al</span><br />
total 108</p>
<p>drwxr-xr-x  4 ham  users 4096 Feb 21 11:38 .<br />
drwxr-xr-x  4 root root  4096 Feb  3 13:39 ..<br />
-rw&#8212;&#8212;-  1 ham  users  297 Feb 21 11:21 .bash_history<br />
-rw-r&#8211;r&#8211;  1 ham  users   24 Feb  3 13:39 .bash_logout<br />
-rw-r&#8211;r&#8211;  1 ham  users  191 Feb  3 13:39 .bash_profile<br />
-rw-r&#8211;r&#8211;  1 ham  users  142 Feb  3 13:41 .bashrc</p>
<p>-rw-r&#8211;r&#8211;  1 ham  users  124 Feb  3 13:40 .bashrc_backup<br />
-rw-r&#8211;r&#8211;  1 ham  users  438 Feb  3 13:39 .emacs<br />
-rw-r&#8211;r&#8211;  1 ham  users    0 Feb 21 11:38 example.txt<br />
-rw-r&#8211;r&#8211;  1 ham  users  120 Feb  3 13:39 .gtkrc<br />
drwxr-xr-x  3 ham  users 4096 Feb  3 13:39 <span style="color: #0000ff;">.kde</span><br />
drwxr-xr-x  2 ham  users 4096 Feb 21 11:32 <span style="color: #0000ff;">public_html</span></p>
<p>-rw&#8212;&#8212;-  1 ham  users  632 Feb  3 13:41 .viminfo<br />
-rw-r&#8211;r&#8211;  1 ham  users  658 Feb  3 13:39 .zshrc<br />
[ham@PVDACDLN-01 ~]$</p></div>
<p><span class="command">clear</span> &#8211; The clear command requires no parameters. It clears the terminal and presents a prompt. It&#8217;s almost never necessary to do this, but it can be good for mental clarity.</p>
<h4>Information</h4>
<p><span class="command">who</span> &#8211; The who command requires no parameters. It prints a list of all logged in users to the screen.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 375px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">ham      pts/1        Feb 21 13:52 (10.21.5.164)</div>
<p><span class="command">top</span> &#8211; every program or command that runs on the machine is a process. The <span class="c">top</span> command displays running processes in order of the CPU cycles consumed.</p>
<p><span class="command">ps</span> &#8211; ps stands for &#8220;process snapshot&#8221;. It prints a list of the current running processes. Use the &#8220;-e&#8221; argument to see everyone&#8217;s processes.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 300px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">ps</span><br />
PID TTY          TIME CMD<br />
24948 pts/1    00:00:00 bash</p>
<p>25366 pts/1    00:00:00 ps<br />
[ham@PVDACDLN-01 ~]$</p></div>
<p><span class="command">man</span> &#8211; man stands for &#8220;manual&#8221;. It accepts one command name as a parameter. It will <span class="c">less</span> the man page for that command. Use the spacebar to page through it, or type &#8216;q&#8217; to quit. Try typing &#8216;<span class="c">man ls</span>&#8216;.</p>
<p>Man pages are generally dense and occassionally uncomprehensible, but they do usually present every possible option for a command.</p>
<p><span class="command">help</span> &#8211; help is a bash command that provides help for builtin commands. It accepts a command name or pattern (partial name) as an argument.</p>
<p>Unfortunately, <span class="c">help</span> only documents certain commands. Try &#8216;<span class="c">help help</span>&#8216;.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 700px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">help pwd</span></p>
<p>pwd: pwd [-PL]<br />
Print the current working directory.  With the -P option, pwd prints<br />
the physical directory, without any symbolic links; the -L option<br />
makes pwd follow symbolic links.<br />
[ham@PVDACDLN-01 ~]$</p></div>
<h4>Manipulating Files and Directories</h4>
<p><span class="command">cp</span> &#8211; the <span class="c">cp</span> command accepts two parameters. It copies a file to a file with the name specified in the second parameter. Each parameter may include a directory (relative or absolute) and a filename.</p>
<p>Use the <span class="c">-R</span> (recursive) switch to copy entire directories.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 600px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">cp example.txt moreexamples.txt</span><br />
[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">cp example.txt directory/example.txt</span></div>
<p><span class="command">mv</span> &#8211; the <span class="c">mv</span>, or &#8220;move&#8221; command, accepts two parameters. It renames the first file to the second filename. Each parameter may include a directory (relative or absolute) and a filename.</p>
<p>The <span class="c">mv</span> command is also used for renaming files.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 300px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">mv example.txt moreexamples.txt</span><br />
[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">mv example.txt directory/example.txt</span></div>
<p><span class="command">rm</span> &#8211; the <span class="c">rm</span>, or &#8220;remove&#8221; command, deletes a file.</p>
<div style="border: 1px solid #000000; padding: 2px; width: 450px; font-family: 'Courier New',Courier,mono; color: #00cc00; background-color: #000000;">[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">rm moreexamples.txt</span><br />
[ham@PVDACDLN-01 ~]$ <span style="color: #dddddd;">rm -r directory/</span></div>
<h3>Resources and Help</h3>
<p>Explore these links for additional information and explanations.</p>
<ul>
<li><a href="http://linuxcommand.org/learning_the_shell.php">Learning the shell</a></li>
<li><a href="http://www.ss64.com/bash/">Bash command reference</a></li>
<li><a href="http://www.ee.surrey.ac.uk/Teaching/Unix/">Unix tutorial for beginners</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.hilarymason.com/blog/intro-to-the-linux-command-line/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Rotating Images Tutorial</title>
		<link>http://www.hilarymason.com/blog/javascript-rotating-images-tutorial/</link>
		<comments>http://www.hilarymason.com/blog/javascript-rotating-images-tutorial/#comments</comments>
		<pubDate>Mon, 20 Feb 2006 05:19:05 +0000</pubDate>
		<dc:creator>Hilary Mason</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web dev]]></category>

		<guid isPermaLink="false">http://www.3greeneggs.com/wp/articles/artjavascript/javascript-rotating-images-tutorial/</guid>
		<description><![CDATA[
Introduction
Swapping new images into an established layout is one trick that can keep a site design fresh.  Some examples:

gettyimages
benstraw

There are several different techniques for accomplishing this effect. A server-side program is the best approach, because you can automatically pull files from a whole directory (eliminating the need to modify code), and it will work [...]]]></description>
			<content:encoded><![CDATA[<p><script src="http://www.hilarymason.com/wp-content/uploads/2006/02/rotate.js" type="text/javascript"></script></p>
<h5>Introduction</h5>
<p>Swapping new images into an established layout is one trick that can keep a site design fresh.  Some examples:</p>
<ul style="font-size:11px">
<li><a href="http://www.gettyimages.com">gettyimages</a></li>
<li><a href="http://benstraw.com/wp/">benstraw</a></li>
</ul>
<p>There are several different techniques for accomplishing this effect. A server-side program is the best approach, because you can automatically pull files from a whole directory (eliminating the need to modify code), and it will work even if a user has JavaScript disabled.</p>
<p>Unfortunately, not everyone has access to a host that supports server-side scripting. That&#8217;s okay, because the same thing can be accomplished with client-side code in JavaScript. I&#8217;ll show you how, with three JavaScript functions of varying levels of ease and functionality. First, gather two or more images that are the same size. Then read on&#8230;</p>
<h5>Setup</h5>
<p><a onclick="javascript:window.open('http://www.hilarymason.com/wp-content/uploads/2006/02/rotate.html','val','width=216,height=216,scroll=no,resize=no,toolbar=no')" href="."> Click here</a> to see the script run. Reload a few times (you may need to right-click and choose &#8216;reload&#8217;). Then view the page source.</p>
<p>This HTML is simple (and valid)!</p>
<p><code lang="html"></p>
<p><img id="pic" style="width: 200px; height: 200px;" src="rose1.jpg" alt="a rose of any name" /></p>
<p></code></p>
<p>The onload event of the body tag calls the rotating image function. The image tag should be positioned on the page as normal. The width and height are the same as the width and height of the images.</p>
<h5>Basic Function</h5>
<p>This is the most basic and straightforward implementation. Name your images incremental filenames, like &#8216;rose1.jpg&#8217;, &#8216;rose2.jpg&#8217;, etc. Then use the following function to load them dynamically:</p>
<p><code lang="javascript"><br />
function selectPicBasic() {<br />
// generate a random number between 1 and 3<br />
var randomNum = Math.floor(Math.random() * 3)+1;<br />
// build the filename string including the random num<br />
var filename = "rose" + randomNum + ".jpg";<br />
// set the src of the image equal to the filename<br />
document.getElementById("pic").src = filename;<br />
}<br />
</code></p>
<p>This function generates a random number from 1 to 3 (to refer to images &#8216;rose1.jpg&#8217;, &#8216;rose2.jpg&#8217;, and &#8216;rose3.jpg&#8217;). It builds the filename string piece by piece, using the concatenation operator (+). Finally, it gets a pointer to the image element in the body of the document via the tag&#8217;s id attribute, and sets the src attribute of the image element to the new, randomly generated filename.</p>
<p>This works for simple cases, but it does have some serious drawbacks; you need to modify two of the three lines of the function to update it, and it only supports filenames that follow the roseX.jpg pattern.</p>
<h5>Better Function</h5>
<p>This function expands the previous one and fixes those issues.</p>
<p><code lang="javascript"><br />
function selectPicBetter() {<br />
// create an array of all possible images<br />
var picArray = new Array('rose1.jpg','rose2.jpg','rose3.jpg');<br />
// select a random num between 0 and length of the array<br />
var randomNum = Math.floor(Math.random() * picArray.length);<br />
// assign a random array entry to the src of the image<br />
document.getElementById("pic").src = picArray[randomNum];<br />
}<br />
</code></p>
<p>This function uses an array to store a set of filenames. It generates a random number between zero (the first index of the array) and the length of the array, and sets the src attribute of the image to that entry in the array. To add more files to the rotation, just add them to the array.</p>
<h5>Cowboy Function</h5>
<p>This is the version written just because it can be. It&#8217;s a rewrite of the basic function, in one line.</p>
<p><code lang="javascript"><br />
function selectPicCowboy() {<br />
document.getElementById("pic").src="rose"+(Math.floor(Math.random()*3)+1)+".jpg";<br />
}<br />
</code></p>
<p>Don&#8217;t do this. Unless you&#8217;re a cowboy.</p>
<h5>Conclusion</h5>
<p>If you&#8217;re limited to client-side coding, the <span class="code">selectPicBetter()</span> function is a decent, quick, and clear approach to incorporating rotating images into your site.</p>
<p>Please learn from this code, but if you use it, I appreciate attribution!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.hilarymason.com/blog/javascript-rotating-images-tutorial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
