Archive for the 'Programming' category

 | September 26, 2011 3:54 pm

The ability to create custom installation images (whether they be of servers, desktops, or more specialized devices) is a tremendously handy thing. In Windows Server 2008, Microsoft released a tool that makes the creation of these images much easier called ImageX.

ImageX works hand-in-hand with a second tool, called the Windows Preinstallation Environment (WinPE). In this series of videos, I will explain how you can use ImageX and Windows PE to create custom images and deploy them.

In this video, Part 2 of the series, we will cover how to create a custom WinPE image that includes ImageX and other useful tools. Part 1 talks about where to find and download WinPE/ImageX and how to install them.

The entire series is from a networking infrastructure course that I am currently teaching. I am posting it here in the hope that it will be helpful to a wider audience.

Show me more… »

 | September 22, 2011 9:50 pm

The ability to create custom installation images and deploy them to other machines is a very handy skill. If you are working in a large environment, you can create a master image with all of the tools needed for your work that could be used on all of your hardware. In this series of videos, I will explain how you can use ImageX and Windows PE to create custom images and deploy them.

Note: The following video is part 1 of a series that I have put together for a networking class that I am currently teaching. I have posted it here in the hope that it will be helpful to a slightly wider audience.

Show me more… »

 | September 21, 2011 7:57 pm

For the past year and a half, I’ve been using DreamHost, a company based out of California, to host this website. In most ways, it’s been a fantastic experience. The customer service is prompt and knowledgeable [1], they go out of their way to use renewable energy, and they give you all sorts of additional goodies when you sign up for an account [2].

But even though the experience has been mostly fantastic, I have one serious gripe: the actual hosting experience is terrible.

Let me see if I can explain why. With my previous host, Brinkster, it was rare to have a website outage. Things, for the most part, Just Worked ™. The website was up and people came to read it. That’s generally all you can ask from a hosting company. (To be clear, the hosting experience with Brinkster was great, everything else was middling to awful.)

With DreamHost, though, it’s another story. If you’ve come to this site lately (especially in the mornings or late evenings) it will be unresponsive. At other times, you might see a strange message in your browser, saying “Error 500: Internal Server Error.”

As the person paying for the hosting space, this is somewhat frightening.  HTTP errors (of which 500 is one) can be cryptic, and figuring out why your website (which was working five minutes ago and costing you money) is broken problem can require some serious time.

Wait, I've Almost Got It

500 Errors in General

The 500 error, in particular, is a true terror. It means that the web server encountered an unexpected condition and can’t return the web page to you. It’s a sort of catch-all error that gets generated when nothing more detailed is available. If you want additional information (something which might actually be helpful to fix the problem), you have to work your way through cryptic error logs and pray that some divinity is listening to your pleas. It’s not fun.

When hosting with Brinkster, I never had 500 errors. Not once. Occasionally there would be an outage, but these were repaired quickly and with little fuss. WIth Dreamhost, though, 500 errors happen all the time: at least daily, and sometimes hourly. They crop up when trying to do administrative tasks, when making posts, when trying to load the home page for the website, or when uploading files. The errors can be intermittent, or they might last for hours. It’s all very frustrating.

Lately, they’ve been so bad that I had essentially convinced myself to move away from DreamHost to another provider. Something I consider a true shame. It would mean giving up the goodies [3], probably paying more money, and losing shell access to the server. So, before I decided to move away forever, I decided to get in touch with DreamHost support (again) and work out the problems with my website.

Happily, after a protracted email message thread and a great deal of searching online, I’ve I’ve learned a few things about optimizing websites for DreamHost. I’ve also found a strategy (I think) for solving the dreaded “Internal server error” problem.

Show me more… »

 | September 20, 2011 8:46 pm

Note: Whenever I come across an interesting or potentially useful piece of source code, I like to make a copy and file it away. I post some of them here in the hope that they will be useful to others as well.

In my recent coding adventures, I needed to create a function to monitor the up-time of one of my Linux servers. A very simple thing (you would think), and yet, I wasn’t able to find a function in the standard library which would give me this piece of information. So … I decided to write my own.

The script below makes use of the “uptime” command (common in many Unix operating systems) to see how long the machine has been turned on. It works on both Linux and OS X computers. If I have time, I will add code for Windows as well.

FORMAT_SEC = 1
FORMAT_MIN = 2
FORMAT_HOUR = 3
FORMAT_DAY = 4

def uptime(format = FORMAT_SEC):
  """Determine how long the system has been running. Options:
  FORMAT_SEC returns uptime in seconds, FORMAT_MIN returns minutes,
  FORMAT_HOUR returns hours, FORMAT_DAY returns uptime in days."""

  def checkuptime():
    """OS specific ways of checking and returning
    the system uptime."""

    # For Linux and Mac, use "uptime" command and parse results
    if (sys.platform == 'linux2') | (sys.platform == 'darwin'):
      raw = subprocess.Popen('uptime',
        stdout=subprocess.PIPE).communicate()[0].replace(',','')
      up_days = int(raw.split()[2])

      if 'min' in raw:
        up_hours = 0
        up_min = int(raw[4])
      else:
        up_hours, up_min = map(int,raw.split()[4].split(':'))

      # Calculate the total seconds that the system has been working
      up_sec = up_days*24*60*60 + up_hours*60*60 + up_min*60
      return up_sec

  total_sec = checkuptime()

  # Get the days, hours, etc.
  if format == FORMAT_SEC: # Return seconds
    return total_sec
  if format == FORMAT_MIN: # Return minutes
    minutes = (total_sec)/(60)
    return minutes

  if format == FORMAT_HOUR: # Return hours
    hours = (total_sec)/(60*60)
    return hours

  if format == FORMAT_DAY: # Return days
    days = (total_sec)/(60*60*24)
    return days

  return -1 # If invalid option specified, return false.

 | 8:30 pm

Note: Whenever I come across an interesting or potentially useful piece of source code, I like to make a copy and file it away. I post some of them here in the hope that they will be useful to others as well.

For the past couple of days, I have been working on scripts to automate the administration of some of my computers. Because they’ve been running  big jobs that often take hours to complete, I’ve been leaving them unattended. But since I need to know as soon as the job is completed, it’s nice to receive some sort of alert. For that reason, I wrote a simple script that will send an email when the job is finished. It uses the string and smtplib modules from the standard library. Here’s the code:

import string, smtplib

# Email Settings
HOST = "smtp.gmail.com" # SMTP Server to Send Message From
PORT = 587 # Port you wish to communicate on
USER = "username@gmail.com" # Email Username
PASSWORD = "PASSWORD" # Email Password

FROM = "admin@oak-tree.us"
TO = "recipient@domain.com"

SUBJECT = "Server Notification from " + AMAZON_EC2
TEXT = "Server " + AMAZON_EC2 + " is shutting down.\n" + 'Timestamp: ' +
    str(CURRENT_TIME)

def sendmessage():
  """Send email notification to the specified email address."""
  server = smtplib.SMTP(HOST, PORT)
  server.ehlo()
  server.starttls() # Use Encryption
  server.ehlo
  server.login(USER, PASSWORD)
  BODY = string.join((
    "From: %s" % FROM,
    "To: %s" % TO,
    "Subject: %s" % SUBJECT ,
    "",
    TEXT
    ), "\r\n")
  server.sendmail(FROM, TO, BODY)
  server.quit()

In general, it’s pretty straightforward. You specify what host you want to connect to and the port, then you construct your message. Finally, you send it. In this example, I’ve added a few other things, like a line to log-on to the server and encryption.The actual connection and sending of the email is only two lines of code. The rest is setting up the message.

Pretty cool, huh?

 | June 20, 2011 11:13 pm

This video is the second in a series from a course (introductory and intensive) on web technologies that I am currently teaching. It shows how to validate an XML document using XML Schema. (The first entry in the series covers DocType definitions, DTDs.)

XML schema, like Document Type Definitions, are used to validate the structure of XML documents and web pages. XML Schema, though, is a much richer way to verify structure and data.

Like it’s older sibling, I am posting the video in the hope it will be useful to both students in addition to others that have lost themselves in the ether of XML Schema syntax.

Show me more… »

 | June 15, 2011 6:28 pm

The following video is from an intensive (albeit introductory) course that I’ve been teaching on web technologies — XML, XHTML and CSS. It discusses how to validate the structure of an XML file using DocType definitions (DTDs).

DocType definitions are sets of instructions that tell a document parser whether a particular document is well formed or not. This allows for the parser to recognize potential errors.

I’m posting the video here in the hope that it will be helpful to a larger audience than just those in the course.  After all, DocTypes are an extremely useful tool.

Show me more… »

 | March 28, 2011 4:57 pm

kde-iconNext Monday, I’m going to be giving a talk entitled “Writing and Publishing With Open Source Tools” at Camp KDE, the annual KDE conference for North America. For those interested in attending, the talk happens at 12:15 pm at the Hotel Kabuki, in San Francisco.

I’m really excited about the talk and I think it’s going to be excellent. (I know, having high expectations for your own performance is the route to obscurity, disappointment, and insanity.) If you live in the bay area, or are going to be near San Francisco next Monday and Tuesday, please consider coming.

Note: While I think you should come to hear me, you might also be interested in the conference as a whole. There are going to be a number of interesting talks that cover KDE developments and core technologies.

I’m particularly excited to hear about what KOffice/Calligra is up to. The abstract talks about “Office Engines” and how KOffice/Caligra can be used to build custom applications. I’m wondering if the technology might be adapted for a mobile project I’m working on. The talks on QtWebKit and the Qt Graphics tools also look neat.

One of the reasons why I’m so excited about my talk is that it brings developments with the book full circle. I first started writing “Writing With Open Source Tools” due to a request for proposals  launched by KDE nearly two years ago. Now, I’m going back to KDE to talk about the (nearly) finished project.

I’m also going talk on other developments I consider timely. For example:

  • How open source publishing tools can be used to target print, web, and eBook platforms from a single source file.
  • How editors, writers, designers, and production people can work together in a seamless, collaborative manner.
  • The strengths of an open approach and where things stand to improve. (Especially for writers and designers.)

While there will be motifs common to the Salt Lake Linux User’s group presentation, most of it is exciting and new. (Which also means untried and untested. So, if it goes well, you can expect to be enlightened. If it goes poorly, expect to be entertained. Either way, it should be a good time.) Since I haven’t quite finished the presentation, it’s also adaptable. If there is anything specific you’d like to see covered, let me know in the comments and I will try to oblige.

Show me more… »

 | December 14, 2010 2:12 am

Roman Forum

Note: Still working on the book.

For quite some time, I’ve wanted to add forums to my website.  Forums are great way to interact with your readership or to provide community support for projects.  (This is particularly important for me as I get ready to release a new version of Time Drive and an alpha of LyX-Outline.)

Every time I try to find the perfect forums software, though, I usually come away somewhat disillusioned.

This isn’t because there aren’t great platforms out there, or that they are difficult to install and administrate.  Quite the contrary, actually.  The problem is that most of the forum plugins available for WordPress (the content management system that runs my site) are ugly.

I know that design aesthetics are a personal thing.   I also know that one person’s trash is another person’s art.  But for a quasi-business website, I would like to have professional looking and attractive forums.  I want them to match the appearance of my website, I would like the headers and backgrounds to use my stylesheet, and it would be nice if the visual hierarchy were established via typography.

Are these such unrealistic desires?

Every time I look, though, I fail to find a forum plugin that meets my needs and satisfies my tastes.  There are some that come close, but as math instructors have told me since grade school, “Close is still wrong.”  Life usually doesn’t offer partial credit.

This last round, I got so frustrated that I decided to create a somewhat custom solution. (Action born of frustration is becoming a theme in my work.)  Truly, if you want something that matches your vision, you really need to do it yourself.  And I have.  After a month of work, you can find my now-functioning forums at www.oak-tree.us/mingle-forum.

For those too lazy to click on the link, here’s a preview.

Oak-Tree.us Forums

Oak-Tree.us Forums - Grid

While there are several goodies lurking below the surface, here are the most important features:

  • The forum is a stand-alone plugin for WordPress.
  • The user database is integrated with the website database.  (This means that when people are registered for the website, they are also registered for the forums.)
  • There is a notification system.  Users receive an email (or RSS item) when a response to one of their threads is posted.
  • The administration panel integrates with the WordPress dashboard.
  • The stylesheet uses the website headings and typographical hierarchy.
  • The plugin allows skins.

Most of these features come from forking Mingle forums, a WordPress plugin.  But there are also some significant changes to the way in which the forum integrates with the website and a completely rewritten/designed the header and footer.  (In the case of the footer, I simply got rid of it.)

In the near future, I’m going to make a few additional changes.  I’d like for the plugin to use a WordPress template instead of hard coding the layout.  I’d also like to add a preferences pane.  In the meantime, though, I thought I would post the files in the hope that they are useful.  Enjoy!

The project is licensed under the GPL.

Downloads

Somewhat Simple Forums (version 0.1).  WordPress plugin forked from Mingle forums.  In includes several typographical enhancements.

Installation

To install:

  1. Download the archive file.
  2. Go to Plugins > New > Upload.  From there, find the .zip file on your hard drive and upload to your server.
  3. Activate the plugin.

After the plugin has been activated:

  1. Create a new page for your forum.
  2. Turn the comments off.
  3. Paste the command [mingleforum] onto the page.
  4. Add categories and forums to the database.

 | October 26, 2010 5:05 pm

Note: Still working on the book, but because I needed a couple hour break, I decided to tackle some LyX-Outline stuff.  This post is related to one item on the to-do list.

Because I need to get away from the book for a while, I decided I would take a break and work on LyX-Outline stuff.  This includes one of the long-standing to-do items: adding support for sections of arbitrary length. Before I get too far down an implementation, though, I would like to request feedback from potential users.

I’ve been trying to find a good way to do this for several months and I think that I’ve finally determined how I would like for it to work.  (At least in the first release.)  Here’s what I propose:

  • Rather than hard-code a special inset into the C++, I think that I am going to add a style for these sections.
  • It will work as a module that you can add to any document you happen to be working on.  Special LyX-Outline templates will include the module by default.
  • The style will rank below all other headings in the document: section, subsection, subsubsection, paragraph, subparagraph.  This would allow for you to organize chunks of text in the body.  (I agree, it would be better to allow you to specify which level you would like this container to exist on, but LyX requires you to specify the indentation level of a particular heading.)
  • For higher level structures (e.g., section, subsection, subsubsection, paragraph, subparagraph), I would anticipate that you would use the other logical headings already provided by the document class.  For creative writing, I am creating layouts which include a heading for scene, that would work in a similar way to this “section of arbitrary length” but provide a container, so you can still group these arbitrary sections into folders.
  • Text in the title will not be added when you export/compile your document.
  • Like other types of section headings, you can add notes to them (which then appear in the corkboard and outline pane).
  • You can convert the “section of arbitrary length” title to a standard LyX/LaTeX section heading.

Does this proposal meet your needs?  This model would give you up to eight levels of hierarchy if working with one of the standard classes and up to four if working on a creative project.  Is that good enough?

After some investigation, I’ve found that completely adopting Scrivener’s model of an infinite number of folders/files would be extremely, prohibitively difficult in LyX.  Yes, it could be done, but it would require some significant rewrites to the way that LyX works.  My goal is to release LyX-Outline as soon as possible (literally, the day after the book has been finished) and I don’t want to get back into the business of major plumbing.  But if it is needed, I will.

There is also a second question.  What should these “sections of arbitrary length” be called?

Scrivener refers to blocks of text as “Chunks.”  That term in LyX, however, refers to something else.  (A block of code when using Sweave.)  LyX also reserves several other heading labels for use, meaning that “part”, “section”, “subsection”, “subsubsection”, “paragraph” and “subparagraph” are also out.

Anyone have any ideas?  I’m terrible when it comes to naming things, and if I make something up, it come out with a label like “Oak-Tree Anthropomorphic Writing Sections of Arbitrary Length”. That would just be bad, and humiliating.

Other people have recommended “Scrivening” and “Text-Block” as potential contenders, which I both like.  But I thought I would open the floor to other nominations before trying to make a decision.