A Programmers Toolbox

I spend most of my time in Xcode working on iOS apps. I just finished updating them to iOS7 and thought it would be fun to log all of the different programs that I use in the next week or so.

I’ll start by backtracking a bit. When proofing one app, a blank spot appeared where a picture should be. The most likely cause of that would be a mis-named picture or one that was completely missing. The names of the pictures are read from a database so I needed to check the names in the database with the names of the pictures. The database is on my server so I could open phpMyAdmin and check the names there, but in case the problem was in the PHP script that I used to create the app database, I decided to open Firefox and use the SQLite Manager plugin to look at the file that I actually use in the app. It turns out that one of the pictures was missing. I had an extra picture in my app so the total number was correct. I swapped the picture and the sounds and the app worked correctly.

We put a frame around the drawings that show up on the screen in the apps. Most of the drawings are floating in space, so the size of the frame doesn’t matter. Sometimes the drawing comes to the edge of the frame and the size of the frame is slightly different than the size of the picture. There is a couple of pixel wide band of whitespace that is out of place. We decided to extend the drawing to get rid of the white space between the picture and the frame. Our drawings are done in Adobe Flash and exported as .png’s. We usually have hundreds of drawings in our apps, so we reduce the size of them by using ImageOptim. I processed the new drawings and added them to the game.

I had a minor issue in the app that I thought might be related to a change I had made earlier. I use Git for version control, so in Xcode I checked previous versions of the file to see if that was where the problem occurred.

Once everything was proofed and submitted to Apple for review, I opened GitX to commit any files that Xcode missed. Xcode often misses deleted files. Then I opened Terminal and ran the git push command to synchronize my copy of the apps with the copy on the server.

I use Apple’s iTunes Connect website to manage my apps and check on daily sales. I checked to make sure all of the apps were waiting for review and I hadn’t missed any uploads. App Annie lets me track revenue by product and over arbitrary time periods. I spent a couple of hours reviewing my sales and checking reviews.

Checking the App Annie website doesn’t require a lot of concentration so I decided to listen to some music. I’ve been copying some of my LPs to disk so I can listen to them on my iPod or stream them with iTunes on my AirTunes network. I have a turntable hooked up to my Mac Mini using an old Roland UA-30 USB interface. I opened Felt Tip’s Sound Studio and recorded a few LPs. Sound Studio is great for recording and cleaning up voice recordings and we use it all the time. It doesn’t have filters for cleaning pops on LPs, so I opened Audacity to get rid of the pops and noise. Audacity is a good recording tool, but its workflow is arranged around projects and doesn’t work well for cutting hundreds of sounds out of a recording session and saving them as .aiff’s. Sound Studio works well for our process. It’s also great for marking and exporting songs from an LP.

I often help other people with their websites and today I got a request to update some data in an SQL file on another persons server. I usually use phpMyAdmin to work with MySQL files, but they don’t have it installed on their server, so I needed to either work on the command line or find another way to work with the database. I can work on the command line, but I really don’t like to. Oracle now owns MySQL so I went to their website and downloaded MySQLWorkbench. It took a while to figure out how to use it but it works fine. The person giving me the data didn’t know how to get it out of his spreadsheet and into a flat file, so I opened the spreadsheet in LibreOffice and exported the worksheets as comma-delimited text. The format of the data wasn’t the same as the format in the database so I used BBEdit to clean up the data. BBEdit has a search and replace feature that uses grep and it only took a few minutes to rearrange the file into something that could be imported into MySQL. I documented that process in a previous post. Since I hadn’t used MySQLWorkbench before, I opened a database on a Digital Ocean droplet that my nephew is using for learning web development. That way if I did something really dumb to the database, it wouldn’t affect a production server. Once I got the update working properly—the handoff had some issues that needed to be fixed was ready to update the database. I always make a copy of every table before I update it and phpMyAdmin has a button to push to do that. I couldn’t find a menu item or button in MySQLWorkbench, so I duplicated my test table on the Digital Ocean server using phpMyAdmin and looked for the sql code that it used.


CREATE TABLE  `Customer1`.`values_Air_Temp_BAK` (
`id` INT( 8 ) NOT NULL AUTO_INCREMENT ,
 `datetime` DATETIME DEFAULT NULL ,
 `value` FLOAT DEFAULT NULL ,
 `source_type_id` INT( 11 ) DEFAULT NULL ,
PRIMARY KEY (  `id` ) ,
UNIQUE KEY  `datetime` (  `datetime` )
) ENGINE = MYISAM DEFAULT CHARSET = utf8;

SET SQL_MODE =  'NO_AUTO_VALUE_ON_ZERO';

INSERT INTO  `Customer1`.`values_Air_Temp_176_BAK` 
SELECT * 
FROM  `Customer1`.`values_Air_Temp_176` ;

I pasted this code into MySQLWorkbench on the production server and had my backup.

I updated the data in the backup and had the user check it for egregious errors. Once it was validated I again used the test server to get the code to rename the backup.


RENAME TABLE  `Customer1 `.`values_Air_Temp` TO  `Customer1 `.`values_Air_Temp_OLD`;
RENAME TABLE  `Customer1 `.`values_Air_Temp_BAK` TO  `Customer1 `.`values_Air_Temp`;

I had the user double check that everything looked right and I was done with that task.

By the way, this blog is hosted on my server using WordPress. I host several blogs and they need updated from time to time. I can never remember the exact steps to do it (I should write a bash script to update them) so I keep the instructions and code in a wiki on our server. Trac is good for keeping notes on procedures and processes and we use it for bug reports when we are testing the software.

I’m managing four servers now and I’ve been meaning to automate some of the process. Since I had some down time, I decided to refresh my bash skills and write some scripts. I especially wanted to automate the login process to different servers and color code the prompts so it was clear where I was. I’ve also been trying out iTerm2 as a terminal.

I just got a call from my nephew about his server. He’s been playing with PHP, CSS, and JavaScript and messed up a couple of files. I have the originals on my machine, so I opened Cyberduck and uploaded them to his server. Cyberduck is an OSX only program, so he uses Filezilla on his Ubuntu Linux machine. It works on OSX, but the Cyberduck interface is more “Mac like”. I showed him how to use the W3C validator tools to check his code for errors. It’s a lot easier to figure out why your HTML and CSS isn’t doing what you want if you don’t have any errors in it.

After I wrote the script to log me in to all the machines I use, I set up SSH authorized keys so that I don’t have to type the password each time. I’m not sure that I would do this with a laptop that I carry around, but I’m using a Mac Mini and it rarely leaves the house. I need to copy my public key to a file called authorized_keys in my .ssh directory on each machine. I could use Cyberduck, but the scp command works better.


scp ~/.ssh/RSA_KEY.pub me@192.168.102.113:/home/me/.ssh/authorized_keys

I updated my .bash_config script so that I have a function that copies my config files to all the machines I use. It uses the same scp command, except that it copies the file from my mini to all of the servers. Since I just updated all of them to use secure authorization, no passwords are required for it to work.


id=$(who am i | cut -d\  -f 1)
server='192.168.194.220'
dave='192.168.201.11'
don='192.168.102.113'
purple='purple.someserver.com'

# Update the list of servers if you add one. It is used on connect and scp functions
servers=(server dave don purple)

# Share .bash_config. Requires . ~/.bash_config in .bash_profile
share() {
    
    # This works if you want to list out each server
    # But if you add new servers, you need to remember to update this list
    # scp .bash_config ${id}@${server}:.bash_config
    # scp .bash_config ${id}@${dave}:.bash_config
    # scp .bash_config ${id}@${don}:.bash_config
    
    # This is better because the list of servers isn’t hard coded in the script 
    for serv in "${servers[@]}"; do
        echo "Connecting to $serv"
        scp .bash_config ${id}@${!serv}:.bash_config
    done
}

Every morning, I open my php_error.log file with BBEdit to see if I have any php or MySQL errors. I started getting lots of weird errors a while ago and it turns out they are MySQL injection attacks. I fixed the code and tracked the attempts for a while, but since it seems to be working now, I no longer log them.

I just took some pictures of unusual cloud formations, and posted them on a flying blog that I run. I like to use Image Capture to grab the images from the camera and then crop and resize them in Acorn. Though it’s not related to work right now, we often we often use the same process to get images for apps. Some of the members of the team use Adobe PhotoShop to fix the images, but my version doesn’t run on OSX Mavericks, so I only use it when I’m using my laptop.

I also use some apps that are not directly related to programming. I just got a couple of orders for CDs so I opened the FileMaker Pro database on my laptop to process the order. This is a really old version of FileMaker that won’t run on Mavericks. But it still works fine and I don’t need any of the newer features. We used to use FileMaker more for developing the wordlists and text for our games, but we moved most of that to the web using PHP, MySQL, and a bit of JavaScript. That way people can work on the database without having to use sneaker-net to get the correct database. One of my goals for the year is to update the database so that it runs in LibreOffice. I use Square on my iPod to process credit cards and Stripe to process cards from international sales.

Our CD burning robot is also very old and runs on a PPC Mac Mini using PTPublisher.

So that’s about it for a fairly normal week.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.