Latest Entries »

Almost every shell script written depends on something else.  Many times those things are already on your computer.  Basic stuff like cat and echo are arguably on every unix distribution in the known universe.  Other things start to vary more widely between different distributions.  Stuff like dialog or perhaps even perl may not be on your system.  Especially if it’s a compacted or embedded system.  To give your shell script a nice polished feel that makes it more portable and easier to use, you should add a couple of lines of code to check and make sure any extra items are there first.  Here is an example that checks for :

if ! which perl > /dev/null; then
echo “Please install perl or make sure it is in your path”
exit
fi

This will help people quickly determine why your script is failing to run on their platform.  Futhermore, it will save you support emails and save users of your script frustration.  Especially if they are newer users who aren’t accustom to debugging scripting glitches.

Hello, world is the most basic of all test programs.  It’s one of the first steps to determine if you have your development environment set up correctly and is also a good first program to learn in any language because it will give you a good idea of the bare minimum requirements to build a program in a given language.

BASIC

Let’s start with Hello, World in basic since that was the first programming language I ever encountered.  The code is very simple:

10 PRINT “Hello, World”

RUN

10 is a line number which is a requirement of old basic compilers.  Generally the lines are numbered  10, 20, 30, etc although they don’t have to be.  Part of the reason for this is so you can later insert other line numbers into your code without renumbering all of your lines of code.  Newer BASIC implementations have sub-routines and other features have have allowed them to ditch the line numbers.  The program is executed from top to bottom so everything in basic has to be in order.  The command RUN at the bottom runs the program and will display your text.  It is not actually part of the program.

Ruby

In Ruby, there are two easy ways to do a hello world program.  I’ll assume you are using a Unix-based machine to try this example.  You’ll need to create a text file called hello.rb with a text editor.  The first way is:

puts ‘Hello, World’

Save your file and type ruby hello.rb at the command prompt.  If all went well, it should print Hello, World and then give you back your command prompt.  I’m assuming that you have installed ruby and it’s in your path.  On a Debian system, it’s easy to install ruby if it’s not already there.  Use a command such as sudo apt-get install ruby.  The other ruby hello world example is:

print(“Hello, World\n”)

C

Hello, World in C is far more complex than any of the other examples.  This is because C is highly structured and not very forgiving.  It also doesn’t have the printf function in the core language so the standard input and output library must be included.  I will also assume you are using a Unix environment for this example.  If you try to run this in a dos/windows environment it will probably fail.  Here is the hello world code in C:

#include <stdio.h>

int main(int argc, char *argv[])
{
printf(“Hello World\n”);
return 0;
}

To run it, you’ll need to put the code in a text file called hello.c.  Then type in gcc hello.c at the command prompt.  This should generate a file called a.out.  At the command prompt, type ./a.out to run the program.  Different compilers and environments may give different results.

Bash

The last example I’ll give is for bash scripting.  Some people would argue that bash is not a programming language but nevertheless it’s a very powerful way to accomplish tasks with other programs and it’s a good way to automate repetitive tasks.  Here is hello world in bash:

#!/bin/sh

echo “Hello, World”

To run this you could simply type the bottom line at the command prompt.  Instead, save it to a file called hello.sh.  Now before you run it, you’ll need to set the executable bit.  Type chmod 755 hello.sh at the command prompt.  Now you can type ./hello.sh to execute the script.

Two channel mixer for my intercom

My 1960's Nutone vacuum tube intercom

I have a 1960’s house that I purchased from the original owner. As a result I have the original Nutone intercom which is vacuum tube based and works really well considering it’s almost 50 years old. When I bought the house, the intercom didn’t work so I popped it off the wall and took a look at the tubes. You can’t tell if they are good or bad by looking at them but I wrote down the model numbers and went on eBay. I found all the tubes I needed for about $15 shipped. When they arrived I popped them in and it worked perfectly but being a 50 year old intercom, it only would receive AM radio. As nostalgic as that is, I like techno and electronic music. I noticed that the intercom had a switch that said radio or phono. I pulled the unit off the wall again and looked for the phono input and couldn’t find it. Finally I crouched down and looked up. There it was on the bottom of the unit. Since my stereo system is on the wall directly behind the intercom, I soldered in a nice piece of Canare coaxial cable with an RCA end on it and dropped it down the wall and put in a plate. Now with the switch set to phono, I hooked up to the tape recorder output on my stereo and have a CD player or airtunes pumped through the whole house. That’s how I’ve had it set up for the near four years I’ve lived here.

This has been great but from time to time I’ve noticed something missing out of the music so I tasked my friend James with building me a small two channel mixer that could fit inside the wall plate. He’s been on a roll lately of designing and cooking circuit boards for various projects and trying to perfect his techniques so I figured this would be a good, easy little project to hone some skills with. The board looks fabulous! It’s higher quality than many electronic devices I’ve opened up over the years even which is kind of scary really. It has a 78XX  series regulator for the positive side of the op amp and a 79XX regulator for the negative side of an op amp. The gain is fixed but there is a potentiometer that adjusts the attenuation on the output side. It works on 12-18VAC.  The PCB was made with the laser printer toner transfer method using glossy paper cut from catalogs that came in the mail and a cheap Scotch TL901 laminator.

Front side of the two channel mixer

Back side of the two channel mixer

He gave me the finished product and I hooked it up to test for a bit. When he had it and built it, he was testing with a 15vac wall wart so when I plugged in my 18VAC wall wart, it wasn’t being loaded down much (maybe 20mah) so there was really no typical voltage drop. That being said, it was putting almost 20 volts into the circuit and essentially running parts of the circuit at peak capacity. He suggested that I should use a lower voltage power supply.  I stopped in at a local goodwill the other day and found a 12VAC 300mah wall wart for $1. That was one problem.

The other problem was apparent when listening to it because it was distorting the audio. I handed it back to James and he took the circuit home for troubleshooting. He found that the filter caps on the output side were slightly undersized.  This was causing the negative power regulator to oscillate.

He sent it back my way with larger filter caps and I plugged in my new power supply.  Now it’s good to go and ready for installation.

How to move a website with a mysql backend

I’ve always found sites built on MySQL a little scary.  With HMTL and typical flat files, you can just always open your data in a text editor, make changes, save it and move on.  The problem with this approach is that you will eventually hit a wall where maintaining the data isn’t very practical.  Take my cooking site for instance www.sinfulvegetarian.com.  If that site didn’t have a backend database, I would have to maintain over 40 HTML pages.  Even if I did use server-side includes (which I do) the site would become unwieldy very quickly.  As it sits, I’ve only coded about seven pages for that website.  Two of those pages are the server-side included headers and footers.  This is so I can maintain the Google Analytics code on only one footer instead of updating five footers if Google decides to change that code again.  So while I still have a bit of the fear of the unknown when it comes to mysql, I find it very useful.  This brings me to my most recent hitching point with MySQL.

I recently decided to consolidate all of my websites on one virtual server via add-on domains.  This allows me to pay less than $10 per month and host my seven plus websites in one place.  This saves me a ton of money over what I was doing and is totally acceptable because all of my sites are relatively low in load and traffic.  The main reason I put it off as long as I did was because several of my sites are driven by mysql backends.  I was afraid of corrupting the database or not being able to move it or just flat out afraid of the unknown but finally I put my mind to it and figured it out.  I hope this article helps someone out there complete this VERY simple task that is not very widely/well documented to my knowledge.  I am going to assume rudimentary knowledge of how to FTP, edit text files and how to access your hosting company’s control panel.  Most companies that I’ve used seem to use similar control panels but if not, you can always ask your hosting company for tech support on this topic.

First off, you’ll need to pull your entire site down from with FTP to your local computer.  If you have a Mac, I suggest Cyberduck.  If you are using a PC, Coreftp provided me years of excellent service.  After you’ve saved your website, now you need to snag the database.  You’ll need to log into your existing hosting company’s cpanel and choose the phpMyAdmin option.  Some hosts have a direct way to access this tool as well.  If in doubt, ask tech support.  When phpMyAdmin pops up, choose the export tab.  Now there is a place to select which database to export.  Highlight the one that corresponds to your site (or one of them if there is more than one, I’m only giving instructions to do this one at a time).  Now most importantly, ignore all the options and leave them default except for where it says “save to file” at the bottom and asks for a name.  Give it a memorable name and hit go.  Save the file to your local computer.

Now on the new web server, you need to log into your control panel and find what might be called the “MySQL Databases” icon.  Whatever the case, you are trying to get to the place where you create new MySQL databases and users.  Now create a new username and password.  This is something you’ll need to write down and use in a few minutes but you won’t need to remember it so choose something secure.  Then you need to create a database.  Use something description and write that down also.  THIS IS IMPORTANT!!!   Look on the page and you will probably notice that username and database name you chose have something appended to them.  Usually this is the username that you needed to log into the control panel and FTP.  THAT is what you need.  So if you named your database acmewidgets, your full database name is probably something like johnsmith_acmewidgets.  So far you should have:

username: johnsmith_widgetsuser

password: Ty23$%!!!

database: johnsmith_acmewidgets

One more thing before you leave that page.  You need to associate the username with the database and assign privileges.  I will let you be the judge of which privileges you need to provide but remember if something doesn’t work, you can always come back here later and tweak the settings.

Now, open up the database.sql file that you saved on your local computer with a text editor.  You will see something like this at the top:

— phpMyAdmin SQL Dump
— version 3.2.4
— http://www.phpmyadmin.net

— Host: localhost
— Generation Time: Apr 20, 2010 at 01:43 AM
— Server version: 5.1.30
— PHP Version: 5.2.4


— Database: `john_widgets`

CREATE DATABASE `john_widgets` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `john_widgets`;

You will need to change the three occurrences of your old database name to the one you just created on your new web server.  One is just a comment but it’s still good practice to change it.  Save and close the file.  Next, in phpMyAdmin on the new webserver, go to the import tab.  Now browse and find you hand-modified database file where it says “location of text file” and then hit go.  If all is right in the universe, you should get get a nice message that says that the import was successful.  If not, it might be time to bug tech support.

Next, you need to go to your website on your local computer.  You’ll need to find the file(or ALL the files) that contain references to your database.  On wordpress, this is easy.  They are all housed in wp-config.php. WordPress has done an incredible job of making it simple for you.  These lines are the only ones that should concern you when transferring a site unless you had an exotic configuration of some sort:

// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘john_oldwidgetsdb’);

/** MySQL database username */
define(‘DB_USER’, ‘john_oldusername’);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘password’);

Change the three items in question.  Upload your website via FTP and cross your fingers.  If all went well, you should be good to go.  Remember to redirect your host file or whatever you may need to do to make sure you are looking at the new site and not your old one.

If you are transferring something besides a WordPress site, you may have a LOT more hunting to do to find those database references.  One of my sites is rather poorly coded (I didn’t code it) and there are three files for the main site with database info hard coded into them and SEVEN more for the administration console for that site.

Hopefully this article has explained the process a bit even if you chicken out and just beg tech support to transfer your site for you.  MOST web hosting companies are glad to move your site over for free.  At least that has been my experience.

What is MacPorts?

Since getting my MacBook pro in early 2009 MacPorts has been one of the best and most useful tools I have discovered for it. MacPorts is a package management system similar to Debian’s apt-get. It allows you to install any of the 1000’s of packages that are available on other Unix platforms.  To use it, you’ll need Xcode which is Apple’s free integrated development environment.  Make sure you include both X11SDK and Unix Development when you grab the Xcode package.  Xcode is a huge package but it’s worth the space for ports and because it comes with Dashcode which is a nice little text editor that properly saves html, php, etc unlike text edit.

Once you have Xcode downloaded and installed, then grab the pre-built dmg file for your version of OS X from here.  One of the first commands you’ll want to make a note of is the update command.  That brings MacPorts itself up to date.  To run it you type:

sudo port -v selfupdate

More important is the package update command.  This one could take a while to run depending how many packages you have installed since it will download and recompile any outdated packages and dependencies you may have installed.  Be forwarded my computer took over an hour to upgrade.  To run it you type:

sudo port upgrade outdated

At the time of this blog post there are 6818 ports currently available.  You can see all of the ports right here.  The ports are categorized and searchable.  You can also search through all of the available ports right on the command line with these two commands:

ports list

ports search package

Once you find a package you want, installing it is a snap.  You just type:

sudo port install package

After you have installed a few ports, you can see a list of all ports and all dependencies that you currently have installed by typing:

port installed

Every time I look at the list I see new packages to install.  A few of my favorites are Perl, mysql, nmap & lynx.  You might laugh at Lynx but it really can be handy in a pinch.  Especially if you are SSH’ing into your Mac remotely.  Even if your package is not available, ports is really the best way to install dependencies for other packages that you may need to compile.  Things like gmake, autoconf & automake can be critical to running ./configure scripts and ports will make dependency hell a little less painful.

One final caveat is that when you upgrade to the next version of OS X, it will probably break some/most/all of your ports.  I haven’t had this experience yet but I’m guessing it won’t be much more painful than possibly upgrading Xcode, the MacPorts binary and running the upgrade command again.

iTouched an iPad

I was out shopping with the family at the mall today and quickly ducked into the Mac Store (not the same as the Apple Store). There were only three people in the whole store and they were all clustered at the three iPads that were displayed in the middle of the store. There was an older woman, a store employee and an off-duty cop. About as diverse as it gets. The employee backed off and I picked up the one in the middle.

I was surprised at how heavy it was. I was expecting it to be much lighter. I noticed they were set atop these custom stands. My first act with the iPad was to set it flat on the table. To my surprise, the wifi signal didn’t even flinch. From all I’ve heard, I expected just looking at it to kill the signal strength. I’m guessing this is another over-sensationalized problem that isn’t quite as bad as it was made out to be.

Next I picked it back up and started thumbing around with the apps. I don’t care for how much space is wasted by the icons on the screen. It seems that you have the same amount of icon space as you would for an iPod Touch. I’m not sure if this is a setting or if there is some other reason but my initial though is that it looks stupid to have tiny little icons with tons of space around them.

After the initial shock of the tiny icons, I decided to press one of them. To my surprise a tiny-sized app popped up. Don’t ask me what I was expecting for apps that have not been updated for the iPad but this was certainly not it. I’ll be damned if I’m going to run around with a gigantic iPod Touch with a beautiful screen that can only display most of the apps I care about at the same size as my current iPod Touch. What about the 2x button you say? What a joke. I haven’t seen pixelation that bad since my Atari 2600. Sorry, until all the app providers are on board, that’s a major show stopper for me. I’m really surprised that so many people can overlook this issue.

When the iPad was first announced, I was ready to buy it immediately. It looked like the perfect little computer to have around the living room and kitchen. Now that I have seen it however, I still think it has a lot of potential but more so as a niche device. Maybe it would be perfect for a professional photographer proofing with his clients or for an elderly person who’s eyesight isn’t good enough for an iPod Touch. It will be interesting to see what niches the iPad carves for itself but at the current price, it’s going to be a hard sell for a lot of potential buyers. The bottom model is more expensive than most netbooks and the top model is nearly $1,000 if you have to pay tax or shipping.

When the price drops and Tech21 releases an iBand shock absorbing frame for it, I’ll take another look at it.

Airtunes and the emu 0404

I’ve had my stereo system since 1994. For electronics that is getting old but I bought good stuff to begin with so I’ll continue to use it for many more years. It’s a Marantz system with the MA500 monoblocks that they made for years and years. It has a single cd player since that was the best I could afford as a teenager and I don’t mind changing the disc manually. All in all, it still sounds good but I was shopping in Canada with my wife’s uncle who is a real audio nut. We were at a store and I kept seeing these Sonos boxes everywhere so I asked for a demo. The salesman was really excited about it and I could see why. It basically allows you to stream audio from Napster, your pc or hundreds of Internet radio stations. The quality was entirely dependent on the bit rate of the source recording.

Needless to say I was very impressed with this setup. Of course the fact they had it hooked to a $2,000 Bryston DAC didn’t hurt I’m sure. After coming back home I did some research to figure out how I could set up something similar at home.

I hadn’t ripped my music collection yet so I had the opportunity to chose a format. I decided to go with Apple lossless. There are a couple of reasons for this. First off, it’s lossless. This means when it’s decompressed, it is bit-perfect when compared with the original wavform. The second reason is because of the transport mechanism I chose which is the Apple Airport Express. When the audio is sent across the network for playback, it is converted from whatever native format into Apple lossless anyways so I thought it would be prudent to save a step.

My “transport” the Airport Express looks just like the AC adapter for my Macbook Pro only without the cord. It has a network jack for setup and for certain uses and also has a 1/8″ audio jack that has analog and digital optical output. This is the key to my setup. With that digital output, I was able to feed the input on my new Emu 0404 USB DAC.

Is the DAC worth the extra $185 it added to my setup? YES! It made the sound noticeably clearer and crisper. Listening without the DAC, it sounds like hooking up an iPod direct to your stereo. It decent, not as bad as tape but definitely not as good as a CD. With the DAC the audio actually sounds better than my CD player. To be fair, my CD player is over 15 years old so it’s to be expected that DAC technology has come a long way since then.

The last piece of the puzzle is the interface. For this, I purchased a used iPod touch off Craigslist. There is a remote app in the iTunes store that allows you to browse your collection and playlists. It also allows you to turn on and off your speakers. This is cool because you can have several Airport Expresses in the house but choose which ones are playing at any given time. It also allows you to turn off the speakers on your computer if you desire.

There are a couple of caveats to my setup. First off, my Macbook has to be turned on, in the house and iTunes has to be open. Next, don’t try to hook anything else to the DAC. The inputs are not isolated even though it looks as if they should be. Lastly, wifi and wired networks are not perfect. I have not had many glitches and almost all have been when I’ve been downloading Linux ISO’s or something similar. Not a big deal but something to be aware of.

Overall, I’m totally satisfied with this setup. I’m confident it would sound good on a far more expensive setup than mine even. Furthermore, there is no reason someone couldn’t feed a $2,000 Bryston DAC with the Airport Express and theoretically have an even better system. I thought about it for a minute but then remembered that my wife would probably leave my if I spent $2,000 on something like that. The emu 0404 is a secret gem in the audiophiles community. It is not well respected because it look like pro audio gear instead of audiophile gear but don’t let that put you off. I’ve people spend way more for less true benefit. Cable stands and hospital grade power cords anyone?

Command line drum and bass

I was flipping through the latest winter 2009-2010 issue of 2600 magazine the other day on my way up to a family vacation and an article caught my eye. The author of the article, SigFLUP, had written a program to use your computer keyboard to manipulate a looping wav file. After installing SoX & libSDL I fired up the program with the test loop that was provided.  The author posted a demo of what kinds of variations could be made on one loop.

The program is packaged in the form of a one-size-fits-all shell script that has C embedded in it which compiles at run time. It took a little bit to start up in my Debian VM. I’d say 20-30 seconds.  Once it fired up, I was presented with a blank window that had spawned from the terminal.  That’s when you know it’s ready to run.

I’m not entirely clear to me how the program runs but from the article in 2600 it seems that it maps the 16-bits of the wav to QWERTYUI & ASDFGHJK with Q being the least significant bit and K being the most significant bit.  To use the program, you press two or more of these keys.  What the program does is replaces the values in all of the bits you are pressing with 1 if any of the bits you are pressing are set to 1.  In other words, if you press QWE and the values of QWE were 001, the values of those would then become 111.  All of the other values remain the same.  As you can imagine, this leads to sound crazy sounds.  Listen to the demo to see what I mean.  SigFLUP says in the article that the loop should be a multiple of 65535 samples in length but if you are just going for effects that you can export to your sound editor, that doesn’t matter too much.  Don’t miss the pitch bender keys which are “Z” & “X”.

The program understandably has a few glitches or I just don’t know how to use it right, but nevertheless it makes for a really cool proof of concept that I would love to expand upon someday.  You can download the program here from SigFLUP’s site.

Better wifi configuration for the Zipit Z2

I’ve been toying around with my ZIPIT Z2 Messenger since I received it on March 10th.  The first thing I did after un-boxing it was to hack it of course.  It’s a linux-based device at heart but by replacing the bootloader with the openzipit bootloader and imaging a micro sd card with Irongeek’s side-track distribution the Zipit shows it’s untapped potential.  It’s certainly not perfect in many regards but at the same time it’s quite usable.  One complaint I had was that the wireless configuration utility that is included with side-track is clunky and confusing.  I ran into rkdavis on the #zipit channel on freenode and he has been writing a small script to make it a bit easier to connect to a wifi network.  I played with the script a bit and he has updated it with some of my suggestions to make it more compatible with Debian-based distributions on the Zipit Z2 such as side-track.  It’s a neat little script that uses the dialog utility for a polished interface.  Anyone who has ever “make menuconfig’d” something is familiar with what dialog looks like.

We still have some hitches to work through but here is a link to the Easy Wifi Configurator a.k.a. EWoC.  Look around rk’s site though because he may have a newer version by the time you read this post.  Small word of warning, you will need to “apt-get install dialog” in order to run the script.

Powered by WordPress. Theme: Motion by 85ideas.