Simulating Try-Catch in Go (Golang)

Jim Lawless
In the Go code I’ve been writing to help learn the language, I’ve been using a common function to deal with error conditions. The function terminateOnErr(err error) checks to see if the err parameter is nil. If not, it displays the paramter and calls os.Exit(1). func terminateIfError(err error) { if( err != nil ) { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } Later in the code, I use the following line after every error check that I need to perform:

Sending GMail with Go (Golang)

Jim Lawless
I needed a command-line e-mail sender utility that would send e-mail via my GMail account. I wanted the solution to work on Windows and OS/X for the time being. My solution is a utility named GSend. GitHub repo: https://github.com/jimlawless/gsend/ The Go source is as follows: // Copyright 2013 - by Jim Lawless // License: MIT / X11 // See: http://www.mailsend-online.com/license2013.php // // Bear with me ... I'm a Go noob. package main import ( "log" "flag" "net/smtp" "fmt" ) func main() { to := flag.

Variant Types in Go (Golang)

Jim Lawless
Here we Go again… I had corresponded with some seasoned Go programmers about variant types some time ago. I was searching for a way to keep a slice of data where each element might be a different data-type. The approach I had been taking was in trying to define a data-structure that could act as a wrapper for some of the basic data types. I then learned through the wisdom of these developers that Go could already accommodate my needs in a much simpler fashion.

Ancient Devtools

Jim Lawless
When I first began using microcomputers in the late 1970’s, development tools for 8-bit machines were precious and mysterious commodities. Most of these sorts of tools that looked to be useful were very expensive. My usage of most of these tools was driven by budgetary constraints. The Gateway Drug : BASIC All it really took to pique someone’s interest in microcomputers was to show them a simple program such as:

My First Android App

Jim Lawless
Several months ago, as the “year of learning to code” was getting underway, I wondered what it would be like to have a JavaScript REPL available for my mobile device. I figured that I could build my own mobile app using the PhoneGap framework that would simply expose a large textarea that could be eval()‘ed at the tap of a button. I bought an older Android tablet to prove the concept.

Building a World War II Foxhole Radio

Jim Lawless
When I was a kid, I was fascinated by crystal radios. The first one I had was in the form of a backpack for the Six Million Dollar Man action figure ( Mom picked up the crystal set at some kind of sale before I ever had the action figure ). The thing that fascinated me about crystal radios was that they required no external power-source; the radio signals themselves were strong enough to power a small earpiece at an acceptable volume.

BBS Fun in the Eighties

Jim Lawless
My introduction to the world of electronic bulletin-board systems ( BBS’s ) began in the mid-1980’s. One evening, my friend John called to say that he’d gotten a modem for his Commodore 64. On a whim, I went to Sears and spent over $60 for the same 300 baud “dumb” VIC-1600 modem. This modem was marketed for the VIC-20, but it worked with the C64 as well. It lacked the auto-answer/auto-dial features that were present in the 1650 modem.

Flirtin' with Forth

Jim Lawless
I was a senior in high-school in the mid-1980’s when I first encountered a dialect of the Forth programming language. I was quite familiar with BASIC and Z-80 assembly-language and was just beginning to hand-assemble some 6502 code. One of my instructors brought in King Microware Tiny Forth for the Commodore 64 computer in her lab. I was intrigued, at first, and tried to tinker with Forth. The booklet that came with Tiny Forth described the following line of code that I was supposed to enter at the OK prompt:

FIF Isn't Forth

Jim Lawless
Several years ago, I created a Forth-like programming language interpreter called FIF ( FIF Isn’t Forth ). I put FIF aside for a while as other events began to consume my time. I ultimately ended up losing all of the source code that I had built to that point. I had pondered trying to recreate it, but the work I had done in making FIF opened my eyes to things that I’d want to do differently.

Embedding Javascript in a Batch File

Jim Lawless
The program below is both a batch file and a JavaScript WSH console file. The dual nature of the file is achieved via JavaScript block comments and the strategy by which the command interpreter searches for target labels in a batch file. Save the file below as hybrid.bat … rem ( /* @echo off cscript /nologo /e:javascript hybrid.bat goto end */ ) // by Jim Lawless // This program sample is in the public domain function rem() { WScript.