2013-05-08

How to get directions from Google Maps into Gaia Maps for iOS so you can use them offline

I wanted a way to download directions from Google Maps onto an offline mapping program on the iPad so that I could use the iPad for navigation even when I don't have my cellular service.  I have an iPad with 3G, but because I am a tightwad I only turn the 3G service on when I am on long trips. Also, we go plenty of places with little or no cell service out here in the west, so even if I wasn't a cheapskate I would want this capability.

It turns out that it is not that hard transfer directions from Google Maps into Gaia GPS as a route (not turn-by-turn directions, sorry) that you can view as a colored line on the map.  These days my favorite iOS offline maps app is Gaia GPS.  It can do offline street maps (Mapquest using Open Street Maps), satellite view, and topo maps.

  • Sign in to Google on your computer browser, since you will need to work with the "My Maps" feature in Google Maps.
  • Go to Google Maps and get directions to the place you want to go.
  • At the bottom of the list of directions click the "Save to My Maps" link
  • Select "Save to a new map" from the drop down that asks which map you want to save to.
  • You will be taken to your new map in My Maps.
  • Find a link called KML on the left sidebar, just under the title of your map, and click it.
  • This will open a save file dialog for a KML file. Save it to your desktop.
  • Now transfer the KML file from your computer to your iPad.
  • One way to transfer the KML file to Gaia GPS is via email.
    • Email the KML file to yourself.
    • Open the Email on your iPad and open the attachment using Gaia GPS.
  • Another way to transfer the file is via iTunes
    • Plug your iPad into your computer
    • Go to the tab for your iPad in iTunes and click the Apps button to get to a list of your apps
    • Find Gaia GPS in the list of File Sharing apps
    • Click the Add button at the bottom of the file list for Gaia GPS. This will open a dialog where you can select your KML file.
    • After you have selected your KML file in iTunes, open Gaia GPS on your iPad. It should pop up a dialog saying there is a KML file waiting to be imported and asking you if you want to import it now. Do so.
  • Once you have imported the KML into Gaia GPS it won't automatically show up on the map.  You have to first tell Gaia GPS to display the route on the map.
    • Go the the Saved screen in Gaia GPS
    • On the Saved screen click the button on the top left for saved routes (it looks like two amoebas with stringy appendages)
    • Your KML file should be listed at the top of the list of routes with an on/off switch next to it. Turn it on.
    • Go back to the Map screen in Gaia GPS and your route will show up as a colored line. 


How to keep a Costco six pack of romaine hearts from going bad

The big drag with many Costco fruits and veggies is that unless you have a huge family or a restaurant you aren't going to use all of the big quantity Costco sells before it goes bad.  I have, however, found a way to make the romaine hearts Costco sells in six packs last for weeks:

  • Fill your sink with cold water and put the romaine hearts in to soak for about 30 minutes.  This re-hydrates them.
  • Let the romaine hearts dry for about 20-30 minutes after you soak them.
  • Put each romaine heart in its own gallon sized zip loc bag, removing excess air before you seal, and then put them in the refrigerator.
  • Every few days eyeball all of the bags and remove any leaves that are starting to brown. Typically the leaf on the bottom starts to brown after a few days, maybe because the weight of the romaine heart is resting on it.
I have no idea whether or not this is considered a good practice from a food safety point of view, and I also have no idea whether or not this ruins some aspect of romaine lettuce that foodies feel passionate about.  I do know that I have been doing this for months without getting sick and that the lettuce is still  fine by my standards after up to three weeks.

2013-03-14

How to escape from the View designer in MS SQL Server Management Studio (SSMS)

I started working with SQL Server, and MS SQL Server Management Studio about a year ago, and I quickly got frustrated with the View designer module.  If you click on "New View" in the object explorer, or if you right click on an existing View and choose "Design," it opens up this multi-pane view designer with a graphical representation of the View on top, followed by some table listing the View elements, followed by the SQL for the view formatted as nearly impenetrable blocks of code.  For simple Views the View designer was fine, but for complicated Views I came to hate working with it.  I especially hated the fact that if I tried to format the SQL in a more readable layout, the View designer would throw out my formatting the next time I opened the View in Design mode.

I finally decided that there had to be a better way, and thanks to some discussions on Stack Exchange (natch) I pieced together the following:

  • You can edit a View in plain SQL, and have your layout and formatting preserved when you save, by doing the following:
    • Right click the View
    • Select Tasks -> Script View as -> ALTER To -> New Query Editor Window
    • Make your edits in the resulting Query Editor window
    • Hit Execute when you are done to save your changes.  The ALTER TO command replaces the current version of the View with your edited version.
  • You can quickly clean up the brain dead SSMS formatting of the SQL of existing Views using the free poorsql.com website. You block and copy the ugly SQL into the window, choose from various formatting styles, and then the site instantly prepares a properly formatted version of the SQL.


2013-02-20

How to make an inexpensive magnetically mounted green laser pointer finder for your telescope

I wanted to start using a green laser pointer (GLP) as a supplement to my 9 x 50 finderscope on my Orion XT8 telescope, but I didn't want to spend a lot of money or time on it, and I didn't want to deal with drilling any holes in my optical tube assembly (OTA).  I wanted the GLP finder because while the 9 x 50 finderscope is great for zeroing in on a faint fuzzy once you are in the right area, getting to the right area can be a pain with a Dobsonian.

I was able to find a very inexpensive (less than $10) green laser pointer on Amazon.  There are more expensive varieties out there, but I figured that at such a low price it wouldn't be the end of the world if it didn't work well.  As it turns out, the inexpensive GLP has worked fine for a while now.

But how to mount it on my Orion XT8 telescope?  I didn't want to spend money on a real mount, and I didn't want to deal with drilling holes in my telescope (I know it's not really that big of a deal but I just wanted to avoid it if possible).  Inspired by the way Apple uses magnets to secure things like the iPad cover, I looked on Amazon and ordered a package of 50 1/4" x 1/10" Neodymium rare earth magnets for less than $10.

When the magnets arrived I confronted the fact that I still didn't have a plan for exactly how connect them to the GLP. After mulling over a few possibilities that I rejected because they felt like too much work, I hit on the idea of simply taping four of the magnets to a popsicle stick using black electricians tape, a pair at each end, and then rubber-banding the GLP to the opposite side of the popsicle stick, like so:



Then it was time for a test drive.  I was apprehensive about how hard it would be to align the GLP, but I quickly discovered that it was pretty easy. Just click the GLP on the tube, look through my 9 x 50 right angle correct image (RACI) finderscope, wiggle the shining laser beam back and forth until I see it in the finderscope, and then put the beam more or less close to the crosshairs.  Using this method it takes literally only about 2 seconds to align the GLP.  For vertical (for lack of a better word) alignment of the beam I just wedge stuff as needed between the GLP and the popsicle stick.

I quickly became addicted to using the GLP.  It makes it a breeze to get the telescope pointed to within a degree or two of the target, and from there I use the RACI finderscope to hone in on it. No more contorting myself to get to the right spot behind a red dot finder, and seeing where a big green laser beam is pointed on the sky is a lot easier than correctly placing the red dot on an inexpensive red dot finder.

When winter came along I found another advantage to a magnetic GLP mount: it makes it easy to keep the GLP warm.  I discovered that my GLP quickly dims when it gets cold, so to keep it usable I keep it in my pocket (or when it is really cold inside my pants against my skin) until I need to use it. Then I click it on the tube, quickly align the beam using the RACI finderscope, use the beam to put the telescope on the target, and then pop the GLP off and put it back in my pocket.



2012-10-25

Recursively copy all PDF files from a directory tree to a single directory

Someone gave me a bunch of PDF files spread out through multiple subdirectories and I needed to get them all into a single directory.

In Mac OS X (and probably Linux) this will scan through the directory specified and its subdirectories and copy all of the PDF files to the target directory:

find /Users/joedokes/Desktop/source_directory -name "*.pdf" -exec cp {} /Users/joedokes/Desktop/target_directory \;


2012-09-20

How to export a table as a SQL script using Microsoft SQL Server Management Studio

I come from the PHP-MySQL world, so I am used to being able to quickly generate a backup of a table as a SQL script (CREATE + INSERT) using the easy to find Export function in phpMyAdmin.  When I had to  use SQL Server for a project I was a bit puzzled when I couldn't find a similar feature in Microsoft SQL Server Management Studio (MS-SSMS).  However, a bit of Googling revealed the (cumbersome) solution:

  • In the Object Explorer in MS-SSMS right click the database that has the table you want to export.
  • Select Tasks from the right-click menu.
  • Select Generate Scripts from the sub menu, which will open a pop-up called Generate and Publish Scripts.
  • Click Next on the Introduction screen, which takes you to the Choose Objects screen
  • On the Choose Object screen select the "Select specific database objects" option
  • Expand the Tables object by clicking the little plus sign
  • Select the table(s) you want to export
  • Click Next, which takes you to the Set Scripting Options screen.
  • Choose where you want the output to go (file, clipboard or new query window)
  • Click the Advanced button, which launches a pop-up window called "Advanced Scripting Options" with a list of options
  • Scroll down to the "Types of data to script" option, which is at the very bottom of the set of options called  "General."
  • Change the "Types of data to script" option from "Schema only" to "Schema and data."  This is what will make the SQL include the data from the table.
  •  Click OK to close the Advanced Scripting Options pop-up.
  • Click Next on the Set Scripting Options screen.
  • Click Next on the Summary screen where it says "Review your selections."  This is what triggers the actual export of the table.
  • Click Finish to close the Generate and Publish Scripts pop-up.

There, was that so bad? Well, yes, it was a lot of clicking for something that people probably do relatively frequently, but that is Microsoft for you.

2012-06-18

How to simulate the MySQL group_concat function in MS SQL Server

The issue: I am writing a web app to track agreements where each agreement can have one, or multiple,  account numbers associated with them, like so:

Agreement No. 1: Account Numbers = XYZ-123-123-123; XYZ-123-123-456; XYZ-123-123-789
Agreement No. 2:  Account Numbers = XYZ-123-123-333
Agreement No. 3: Account Numbers = XYZ-123-123-123; XYZ-123-123-789


I quickly decided to store the account numbers in a separate table so that each agreement could have a variable number of account numbers associated with it:

Agreement_Account_Numbers table
Agreement_ID   Account_Number
1                         XYZ-123-123-123
1                         XYZ-123-123-456
1                         XYZ-123-123-789
2                         XYZ-123-123-333
3                         XYZ-123-123-123
3                         XYZ-123-123-789

But then I ran into the problem of how to display all of an agreements account numbers in a table listing a number of agreements. I wanted an SQL query that would return one agreement per line, with all of the account numbers for each agreement concatenated in a single field.  In MySQL this would be easy: do JOIN query with the agreements table linked by Agreement_ID to the  on the agreement ID and then GROUP BY Agreement_ID and use the group_concat function to concatenate the Account_Number field.  However, for this project I have to work with MS SQL Server and it apparently does not have any such function.  Googling around led me to this excellent question on stackoverflow:

Simulating group_concat MySQL function in MS SQL Server 2005?

It took me a while to sort out which answer to this question was easiest to implement, so I am writing down what worked for me for my own future reference.  Here is what I ended up with:

 SELECT
     Agreement_ID,
     STUFF(
         (SELECT '; ' + Account_Number
          FROM agreement_account_numbers
          WHERE agreement_id = a.agreement_id
          FOR XML PATH (''))
          , 1, 1, '')  AS Account_Numbers
FROM Agreement_Account_Numbers AS a
GROUP BY agreement_id

The result of this query is:

Agreement_ID      Account_Numbers
1                           XYZ-123-123-123; XYZ-123-123-456; XYZ-123-123-789
2                           XYZ-123-123-333
3                           XYZ-123-123-123; XYZ-123-123-789

This query uses a sub-select clause to retrieve all of the account numbers for each agreement by linking the Agreement_Account_Numbers table back to itself (by giving the table the alias "a") and then putting sub-select results in a string using the MS SQL Server specific command FOR XML PATH ('').  Then the STUFF function replaces the first character in the sub-select result string with a zero length string ('') to strip off the leading semi-colon that would otherwise be in front of the first account number.

The command is actually FOR XML with the PATH option specified, and then the tag to surround each row specified to be nothing ('').  I tried figure out exactly now FOR XML works, and what the PATH option means, but as usual I found the MS documentation to be completely cryptic so I just accepted that it works.

2012-06-13

Always Google your problem first

If you have a problem that you don't know how to solve, or you need to do something you don't know how to do, the first thing you should always do is just google it.  There are web pages and/or discussions describing how to do or fix just about everything these days, and a large part of the time you can get specific instructions from experts just be googling whatever it is you want to do.

For example, this morning I wanted to put a list of file names from a directory into a document.  Instead of asking someone how to do it, or poking around and trying to figure out how to do it, I just googled "mac os x get copy list of file names to clipboard" and one of the top results was specific instructions on how to do just that.

Another example.  The other day my spouse bought some fresh corn, and we wondered if you could microwave it instead of boiling it.  We googled "microwave corn" and had specific instructions in seconds (it works great; I am never boiling another ear of corn).

This tactic works especially well for computer issues. If you get an error message, the first thing you should do is google it. The majority of the time you will have the solution in seconds.

You can stumble your way through a complex project that you have no idea how to do by using this tactic for each little step.  I taught myself how to write web applications in PHP-MySQL this way.

Many people don't know this trick, so once you know it you can impress your friends and family as an expert on just about everything by using this tactic to instantly finding solutions for their problems.

2012-06-08

Don't get it until you really need it

The principle: Don't create or buy something until you know from actual practice exactly why you really need it.
 
This is also known as "You Aren't Gonna Need It"

When people are starting on some endeavor they often put significant effort or money into buying or making things that they think they will need.  However, when it comes time to actually using these things it often turns out that you don't really need it after all, or it's not nearly as useful as you thought it would be, or you need something very different than what you thought you would need. And all the time, money and effort put into acquiring the thing turns out to be wasted.

On the other hand, if you wait until you know from experience that you actually need something, you can acquire exactly what you really need, and you will know how badly you really need it, which will give you a good idea how much time or money you should spend on it.


An example from hiking. I used to spend a lot on hiking boots because I thought I needed them because, by gosh, everyone else used them so they must be neccessary.  Then I experimented with hiking in tennis shoes and sandals, and found that it was more comfortable, I got zero blisters for a change, I suffered fewer twisted ankles, and it was cheaper.  I would have been much better off if I had started out hiking in just whatever shoes I had, and only purchased different shoes when and if I experienced actual problems.

2012-05-18

How to get MS SQL Server nvarchar() field to sort correctly using ORDER BY

I had an nvarchar field in MS SQL Server that wasn't sorting correctly when I did an ORDER BY on it.  For example, 10 would be put before 9 if I sorted ASC.  It turns out that MS SQL Server considers the position of each character in the field in sorting, and since the field is nvarchar (variable width) the digits of a number are not in consistent positions in the field.  I found the solution in this post on stackoverflow.com:

Order By Clause for NVARCHAR column in SQL Server

The specific code is:

ORDER BY RIGHT(REPLICATE(N' ', 50) + the_column_you_want_to_sort_by, 50)

What this does is virtually add enough leading whitespaces to each entry to make the column look like a fixed width column for the purposes of the query.




2011-12-13

How to get a route from Google Maps on to an iPad so you can follow it offline

I wanted to find a way to download a route from Google Maps onto my iPad 3G so that I could follow the route on a map offline.  I know that with the iPad 3G data plan turned on you can just use the Maps app to find and follow directions, but I am a frugalista and I like to keep the 3G data plan on my iPad turned off except when I am on long trips.

Here is the procedure I worked out, which requires that you own the $3.99 (as of Dec 2011) MotionX GPS HD app.

  • Go to Google Maps and look up directions to the place you want to go.
  • At the bottom of the directions click the Save to My Maps link.
  • Go to Google My Places (fka My Maps) and select the map with directions you just saved.
  • Click the KML link to download a KML file of the directions to your computer.
  • Go to http://www.gpsvisualizer.com/ select the KML file to upload and pick GPS format for the output and click Go.
  • Email the resulting GPX file to yourself.
  • In Mail on your iPad open the email, tap the attachment, and select open in MotionX GPS HD app.
  • This will open the MotionX GPS HD app where you can complete the import of the GPX track.
  • This will just import the track into the MotionX GPS HD app.  You need to separately download OpenStreetMaps for the relevant area in MotionX GPS HD in order to have the maps available offline.
This doesn't give you turn by turn directions, but it does give you a simple line on a map that you can follow while offline.


2011-11-10

How to manage iOS Newsstand subscriptions auto downloads

The screen where you manage automatic download settings for subscriptions in the new iOS  Newsstand is hard to find (at least it was for me!) Here is how to get to it on your iPad, iPod Touch, or iPhone.

  • Tap on the Settings app to get to the Settings screen
  • Scroll down list of settings until you see the icon for the Store and tap that
  • There will be a section of the Store settings called "Automatically download new content when on Wi-Fi" and all of your Newsstand subscriptions should be listed there with an on/off slider for each one.
Incidentally, the wording of this screen seems to imply that automatic downloads of subscriptions only happen when on Wi-Fi (i.e. not on cellular), which I hope is true because one issue of the New Yorker would blow more than half my cheapskate 250 MB cellular plan.


2011-11-02

Save money using Google Voice plus a prepaid cellphone

A lot of prepaid mobile phone plans charge you only for the minutes you actually use, and if you don't use a lot of minutes each month it can save you a lot of money (I spend on average less than $10 a month on my T-Mobile prepaid service).  If you get a Google Voice account, and set it up to ring not only your prepaid cell phone but also your home and office phones, then you can give everyone your Google Voice number as your mobile phone number, but answer calls to it on your house or work phone when you are not on the road.

2011-10-11

How to prevent sessions from expiring too quickly on PHP applications


When I started using sessions for authentication in a PHP web application I discovered that users were being logged out after a very short time.  After some research I discovered how sessions work in PHP.
A unique session ID is stored on a cookie on the users computer.  When the user connects to the server the server looks for a file with that unique session ID in its temp folder, and if one exists it pulls variable values from that file.  Every time any user connects to the server and starts a session the server generates a random number and then looks at some settings in php.ini to determine whether or not to clean out the temp folder. When it cleans out the temp folder it throws out session files older than the session.gc_maxlifetime setting in php.ini (set in seconds).  In order to enable keeping users logged in for long periods I set session.gc_maxlifetime = 1814400 in the php.ini.

This works on MAMP installations also. Just edit to /Applications/MAMP/conf/php5.3/php.ini

How to configure Apache in MAMP to only be accessible from the machine it is installed on

For a number of reasons I wanted to run a web application locally on my MacBook.  After some research I decided that the path of least resistance was to install the free MAMP app, which runs an Apache-MySQL-PHP stack on a Max OS X machine without having to do a complex install process.   I got my web app working on MAMP pretty easily, but then I discovered that other machines on my local network could also access the web app if they connected to the right port of the IP address of my MacBook.  That isn't a problem when I am at home or work, but I didn't want the web app exposed when I was on public networks like at a coffee house or the library.  After some research I discovered the solution was to edit the /Applications/MAMP/conf/apache/httpd.conf file to change:

Listen 8888

to

Listen 127.0.0.1:80

This did two things. It changed the port that MAMP uses from the MAMP default of 8888 to 80 (the normal web server port) and specified that only traffic from the local machine would be accepted.  After I made this change and restarted the Apache server I was no longer able to access the web app from other machines on the same network.

2011-01-25

How to automatically mount external hard drive at boot in Ubuntu Lucid Lynx

I have an external USB hard drive connected to my Ubuntu laptop home server that I used to store MythTV recordings and videos.  Ubuntu would mount this USB drive to the mount point I had created when I logged in as my regular user, but not at boot.  I wanted the drive to automatically mount at boot so that after a power failure, or a reboot, I wouldn't have to log in as a user in order to have MythTV work.  After doing some research using Google I tried the following:

  • After logging in as my regular user to make the USB drive mount, I ran mount in a terminal which gave me a listing of all the mounted disks and their mount settings.  I copied down the mount settings for the USB drive and noted which device the USB drive was mounted as (sdb1 in my case).
  • Then I ran ls -l /dev/disk/by-uuid which gave me a listing of the UUID of each mounted partition and I copied down the UUID for the sdb1.  This is the unique identifier for the USB drive.
  • Then I made a backup copy of the fstab file: sudo cp /etc/fstab /etc/fstab.bak
  • Then I opened the fstab file in an editor: sudo nano /etc/fstab
  • Then I added a line to the bottom of the fstab file like this, putting a tab between each value, and using the UUID I noted, the filesystem type I noted, and the mount options I noted:
  • UUID=07955830-0d54-443c-bdba-f111121f6bd3   /media/myth_data    ext4    rw,nosuid,nodev,uhelper=udisks 
  • Then I rebooted and the disk was automatically mounted without me having to log in.

2011-01-03

A Mac OS X app to wake a Mac and then open screen sharing

I have a Mac Mini hooked up to our TV and stereo as a HTPC which has a hard-wired Ethernet connection. To save a bit of energy I have it set to go to sleep when it isn't used. My wife wanted to be able to play internet radio stations over the stereo, but she didn't want to have to turn on the TV, get a keyboard, etc. just to start one playing. I showed her how to use one program to wake the Mac Mini, and then how to launch screen sharing through Finder, but it was a lot of clicking. So I started googling for a way to set up a one-click icon that would (1) wake the Mac Mini, and (2) then connect to it by screen sharing.

As to waking the Mac Mini, I found this page that gives an Automator workflow to send the wake on lan magic packet (which will only work if the target computer has a hard wired Ethernet connection) and also open screen sharing:

Wake sleeping Mac with AppleScript and Automator

The guts of this is a PHP script written by Mark Muir to send the magic packet that wakes the sleeping computer. The version of this PHP script at the link has comments explaining how it works. Since I have zero experience with Automator I decided to adapt this to be an AppleScript. Here is what I ended up with:

on run
set command to "/usr/bin/php -r " & quoted form of ("$mac = \"a4:6a:19:d8:d2:24\";
$ip = \"10.10.10.255\";
$mac_bytes = explode(\":\", $mac);
$mac_addr = \"\";
for ($i=0; $i<6; $i++)
$mac_addr .= chr(hexdec($mac_bytes[$i]));
$packet = \"\";
for ($i=0; $i<6; $i++) /*6x 0xFF*/
$packet .= chr(255);
for ($i=0; $i<16; $i++) /*16x MAC address*/
$packet .= $mac_addr;

$port = 9;
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, TRUE);
socket_sendto($sock, $packet, strlen($packet), 0, $ip, $port);
socket_close($sock);
")
do shell script command
delay 3
tell application "Screen Sharing"
open location "vnc://MyComputersBonjourName.local"
end tell
end run


To use this yourself do the following:

  • Make sure screen sharing is configured on the target computer and verify it works when you manually connect from the source computer.
  • Go to the target computer and open Network Utility and look up the Hardware Address of the target computers Ethernet network interface. Change the $mac value in the Applescript to be this value.
  • Look up the Bonjour name of the target computer (System Preferences -> Sharing : Computer Name) and substitute it for MyComputersBonjourName in the Applescript.
  • Change the $ip value in the Applescript to be the IP address of your router with 255 substituted for the last digits. For many people this would be 192.168.1.255. Also, 255.255.255.255 should work.
  • Open AppleScript Editor on the source computer (the one you want to connect from) and paste the script in it and then click Compile and then click Run to test it. It should wake the target computer and open screen sharing for it.
  • Save the AppleScript as an app by selecting File -> Save As and then picking application as the file type in the dialog box.
  • Double click on the app to verify it works.
  • Drag the app to the Dock or wherever you want it to live.

2010-12-15

How to run a Python script from Mac OS X Finder

Here is how to run a Python script from the Finder:

  • Make this the first line of your Python script "#!/usr/bin/env python"
  • Change the extension of the script file to ".command" i.e. my_python_script.command
  • In Terminal make the Python script file executable by running "chmod +x my_python_script.command"
  • Now when you double click the Python script in Finder it will open a terminal window and run.

2010-12-08

Checklist for making a home file, print and web server using Ubuntu and an old laptop

A couple years ago I did a detailed set of posts on turning an old laptop into a Ubuntu file, print, and web server. That laptop started having hardware problems so I decided to decommission it and replace it with another recently retired Dell Inspiron 1521 laptop. Here is a checklist of all the steps I did to convert the Windows Dell Inspiron 1521 laptop into a home file, print, and web server. If you are new to Linux you should read my original posts since this checklist assumes you have done stuff like this before.

  • Downloaded and burned CD for Ubuntu LTS 10.04 standard desktop
  • Installed Ubuntu standard desktop 10.04 on Inspiron 1521. I followed the prompts and used the default options.
  • Wrote over existing Windows file system rather than doing dual boot.
  • After Ubuntu was installed I started Synaptic and updated packages
  • Installed openssh-server and samba using Synaptic
  • Opened terminal and ran sudo tasksel to start program that offers a number of options for installing groups of packages for different functions.
  • Selected install LAMP server and followed prompts to install.
  • Using Firefox on new server I went to truecrypt website, downloaded latest Linux version (7a) to the Desktop, extracted file, double clicked it, and followed the prompts to install Truecrypt.
  • Edited /etc/network/interfaces (sudo nano /etc/network/interfaces) to make computer use fixed IP address by adding:
auto eth0
iface eth0 inet static
address 10.10.10.123
netmask 255.255.255.0
gateway 10.10.10.1
  • Rebooted new server to put new static IP address in effect
  • sudo aptitude install ntp (ntpdate was already installed)
  • Set up mount points for encrypted external hard drives:
  • sudo mkdir /media/encrypted1
  • sudo mkdir /media/encrypted2
  • Changed owner of mount points to match what smb.conf will use for them
  • sudo chown nobody:nogroup /media/encrypted1
  • sudo chown nobody:nogroup /media/encrypted2
  • Created directory for my custom scripts for new server: sudo mkdir /home/andy/scripts
  • Mounted new server as volume on remote MacBook using MacFusion (SSHFS)
  • Copied backup of custom scripts over to new server from MacBook
  • Checked ownership and permissions of custom scripts and changed them as needed.
  • Ran my custom script to mount truecrypt volumes (/media/encrypted1 etc)
  • Made these changes to /etc/samba/smb.conf (sudo nano /etc/samba/smb.conf)
  • workgroup = MYWORKGROUP
  • removed semi-colon before interfaces = 127.0.0.0/8 eth0
  • removed # before security = user
  • Added these under Share Definitions
[public]
comment = Public Share
path = /media/encrypted1
read only = No
force create mode = 777
force directory mode = 777
force user = nobody

[backup]
comment = Public Share
path = /media/encrypted2
read only = No
force create mode = 777
force directory mode = 777
force user = nobody

[pictures]
comment = Public Share
path = "/media/encrypted1/Documents/My Pictures"
read only = Yes
guest only = Yes
guest ok = Yes
  • sudo adduser spouse
  • sudo smbpasswd -a andy
  • sudo smbpasswd -a spouse
  • Rebooted new server
  • Ran custom script for mounting truecrypt volumes
  • Mounted samba share from remote MacBook and opened file to make sure everything was working properly.
  • sudo aptitude install phpmyadmin
  • From remote MacBook browsed to http://10.10.10.123/phpmyadmin and logged in as user root
  • Using phpmyadmin created a new user and gave this user all possible privileges on the MySQL database.
  • sudo adduser www
  • sudo nano /etc/apache2/sites-available/default
  • Changed the DocumentRoot value to /home/www/public and saved the file
  • Restarted Apache: sudo services apache2 restart
  • From remote MacBook did SSHFS mount as user www using MacFusion
  • Copied all html/php files from backup to /home/www
  • Used phpMyAdmin to create new user web_app_user with all data (but not structure or database administration) privileges. This is the MySQL user used by the web apps.
  • Used phpmyadmin to create new MySQL databases with same names as were used on the old server (including wordpress).
  • Used phpmyadmin to go into each database and then import the SQL file backup of that database.
  • Edited /etc/php5/apache2/php.ini to change session.gc_maxlifetime = 1440 to 1814400 (this prevents web app users from being logged out of web app shortly after they sign in)
  • Edited blank /etc/apache2/httpd.conf to add "ServerName myserversname". This prevents the annoying "Could not reliably determine the server's fully qualified domain name" message when you start apache2.
  • Restarted apache: sudo service apache2 restart
  • Tested that web applications work.
  • Got crontab setups from old server by doing contab -e as all users that had crontabs and writing down what was there.
  • Changed permissions on custom scripts that would be run by different users via crontab: chmod a+rwx scriptname.sh
  • Created logs directory in /home/andy: chmod -R a+rwx logs
  • Tested all backup scripts on new server.
  • Setup crontabs on new server using crontab -e
  • Configured CUPS for printer (not sure all of this is necessary)
  • sudo nano /etc/cups/cupsd.conf
  • In , and and
  • add:
  • Allow all
  • Commented out "Require user @OWNER @SYSTEM" where ever it appeared except for administrative tasks.
  • Changed:
  • Listen localhost:631
  • to:
  • Listen 631
  • Added the line: DefaultEncryption Never
  • sudo service cups restart
  • Browsed to 10.10.10.120:631 from remote machine
  • Add printer
  • Select HP LaserJet 1012 (HP LaserJet 1012), not the 1012 printer with USB in the name.
  • Name: HP_Shed
  • Description: HP LaserJet 1012
  • Location: Shed
  • Select Model: HP LaserJet 1012 - CUPS+Gutenprint v5.2.5(en)
  • Select default default options
  • Select modify printer just created
  • Click Select Another Make/Manufacturer
  • Select Make: Raw

2010-11-30

Specifying different CSS for landscape and portrait orientations on the iPad

I have a web app that uses jQuery UI buttons. I noticed that on my iPad the buttons worked fine in portrait orientation, but in landscape orientation the buttons, and even regular links in a table, would not work properly when pressed (a different button or link than the one pressed would fire). I determined that this problem was caused by the following tag in my HTML:

<meta name='viewport' content='width=device-width' />

Using this tag causes Safari Mobile (the iPad browser) to zoom in on the page a bit in landscape orientation, making the fonts a bit bigger, which would be fine except that it apparently breaks link and button functionality in some cases. I got the buttons and links to work properly by using this tag instead:

<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />

This locks down the page so it doesn't (and can't) zoom in or out.

That fixed my broken buttons and links in landscape orientation, but I had really liked the way the fonts got bigger in landscape orientation. It gave me a way to have two different zoom levels in may app. If I wanted to see more content in a small font I used portrait; if I wanted to see less content in a bigger font I used landscape.

So, I figured out how to get the exact same effect using CSS "media queries." Here is some CSS that first sets styles for the iPad regardless of orientation and then specifies different styles for portrait and landscape orientation:

@media only screen and (max-device-width: 1024px)
{/* This block specifies CSS that only applies to an iPad
max-device-width: 1024px seems to only select the iPad*/

body
{margin-left: 0px;
margin-top: 0px;}

}

@media only screen and (max-device-width: 1024px) and (orientation: portrait)
{/* This block provides CSS that only applies to the iPad in portrait orientation */

body
{font-size: 16px;}

}

@media only screen and (max-device-width: 1024px) and (orientation: landscape)
{/* This CSS kicks in only when an iPad is in landscape mode. It makes the font bigger, the table rows taller, etc */

body
{font-size: 18px;}

}


You can put this block of CSS at the end of the regular stylesheet for a page and it will apply different CSS when the page is viewed on the iPad, allowing you to have a completely different layout on the iPad than you have on a regular browser. What is remarkable to me is how smoothly the styles change when I switch orientation on the iPad; I was afraid there would be lag while the page reformatted but I can't detect any.