<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>jwo&apos;s tech tips</title>
      <link>http://blog.lib.umn.edu/jwo/jwotechtips/</link>
      <description></description>
      <language>en</language>
      <copyright>Copyright 2011</copyright>
      <lastBuildDate>Fri, 18 Apr 2008 00:40:27 -0600</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/?v=4.31-en</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

      
      <item>
	
         <title>Unix Time for ASP.NET 3.5 (VB 2008)</title>
         <description><![CDATA[<p>I'm a little new to ASP.NET, so maybe I'll figure out later that I didn't need to do this...but I badly miss PHP's date functions.  Working with dates in PHP is so easy that I sometimes play with it for fun.  </p>

<p>The date object in PHP used Unix Time, which is the number of seconds since midnight GMT on 1 January 1970.  Right this second, that number is 1208466537.  From what I can tell, ASP.NET does not use this number &#8212; the date right now is 04/17/2008 04:09:12 PM.  That's alright if you're in a locale that is compatible with that format (i.e., the US), but if you're somewhere else, you've gotta mess around.  Furthermore, you have to be cognizant of the time zone.  There <em>is no time zone</em> in Unix Time.  PHP figures out the local time based on your time zone environment variable.  Besides all that, Unix Time is simply an integer, which is easy to store in a database, and easy to manipulate.  ASP.NET's date object is ultimately a string, which takes up more space and is harder to work with. (To be fair, ASP's date functions seem quite capable of parsing and manipulating that string.)</p>

<p>I can't do anything the easy way, so I whipped up some code to generate and read Unix Time in VB 2008.  First, create the number from the current date and time:<br />
<pre>	<br />
Dim DTDate As Date = DateTime.Now<br />
Dim Epoch As Date = "01/01/1970"<br />
Dim TZone As TimeZone = TimeZone.CurrentTimeZone<br />
Dim TimeZoneOffset As String = TZone.GetUtcOffset(Now).ToString().Substring(0, 3)<br />
Dim TZORaw As Integer = Convert.ToInt32(TimeZoneOffset) * 3600</p>

<p>Dim TZO As Integer</p>

<p>if TZORaw < 0 Then<br />
	TZO = 0 - TZORaw<br />
Else<br />
	TZO = TZORaw<br />
End If</p>

<p>Dim UnixTime As Integer = DateDiff(DateInterval.Second, Epoch, DTDate) + TZO<br />
</pre><br />
You wind up with an Integer called UnixTime which will contain your number.  I'd much rather store that number in a table.  This will work for any time zone that is based on a whole-number hour.  Those wacky zones over in India and elsewhere will fail.  I also just realized that if your local date format is different than "MM/dd/yyyy" it won't work, so you'd need to change that string.  A bit of code is needed to convert it back to a human-readable format:<br />
<pre><br />
Dim Today As Date = Epoch.AddSeconds(UnixTime - TZO)<br />
Format(Today.ToSting(), "MM/dd/yyyy hh:mm:ss tt")<br />
</pre></p>

<p>This will basically get it back to ASP's "natural" date format.  Wonderful.</p>]]></description>
         <link>http://blog.lib.umn.edu/jwo/jwotechtips/2008/04/unix_time_for_aspnet_35_vb_200_1.html</link>
         <guid>http://blog.lib.umn.edu/jwo/jwotechtips/2008/04/unix_time_for_aspnet_35_vb_200_1.html</guid>
         <category>ASP.NET</category>
         <pubDate>Fri, 18 Apr 2008 00:40:27 -0600</pubDate>
      </item>
      
      <item>
	<enclosure url="http://blog.lib.umn.edu/jwo/jwotechtips/UMCal_Palm_Conduit.jpg" length="54533" type="image/jpeg" />
         <title>Oracle Calendar with Palm conduit won&apos;t sync</title>
         <description><![CDATA[<p>Once in a while I'll encounter a PalmOS device that's lost its ability to sync with Oracle Calendar (UMCal).  In some cases, the conduits are missing from HotSync.  This is how I've fixed it:</p>

<p>Make the sync user an administrator, then log in as that user. Reinstall the  <a href ="https://www.umn.edu/umcal/download/software/umcal_syncpalm_win_10.1.1.0.2.exe">UMCal Palm Sync</a>.  In my experience, if you don't install it as the sync user (i.e., Run As...), you'll get at least a couple errors which are totally cryptic, undocumented, and misleading.</p>

<p>Now open HotSync, click Applications, and you should see something like this:</p>

<p><img alt="UMCal_Palm_Conduit.jpg " src="http://blog.lib.umn.edu/jwo/jwotechtips/UMCal_Palm_Conduit.jpg"  width="640" height="512"  /></p>

<p>For reasons I don't understand, there will be multiple entries for the data types that Oracle uses (two each for calendar, tasks, contacts).  You want to use the second name for each of those: Calendar, Tasks, Contacts.  Check whichever of those three you need and make sure to  <i>uncheck</i> Date Book, To Do List, Address.  I also recommend unchecking any of the other unneeded applications further down the list -- it will sync much faster.</p>

<p>Now create a test event in Oracle Calendar and try syncing (initiate the sync from the Palm device).  You should see the test event.  Repeat for tasks and contacts if necessary.</p>

<p>Finally, don't forget to remove admin rights for the user.</p>]]></description>
         <link>http://blog.lib.umn.edu/jwo/jwotechtips/2008/03/oracle_calendar_with_palm_cond_1.html</link>
         <guid>http://blog.lib.umn.edu/jwo/jwotechtips/2008/03/oracle_calendar_with_palm_cond_1.html</guid>
         <category>Handhelds</category>
         <pubDate>Thu, 20 Mar 2008 14:47:10 -0600</pubDate>
      </item>
      
      <item>
	
         <title>Inserting multiple rows in SQL Server and moving data from MySQL</title>
         <description><![CDATA[<style>.CodeBox { color:#9FF; font-size:8pt; }</style>
Inserting multiple rows of data in a single SQL statement should be easy.  <a href="http://www.mysql.com">MySQL</a> makes it easy.  You simply separate your rows with commas:

<span class="CodeBox">
<pre>
INSERT INTO MyTable (FirstName, LastName, BirthYear)
  VALUES ('John', 'Johnson', 1980), ('Pete', 'Peterson', 1981), ('Pradeep', 'Pradeepson', 1982);
</pre>
</span>

Naturally, you can't use this syntax in <a href="http://www.microsoft.com/sql">SQL Server</a>.  That'd be too easy!  Maybe someday Microsoft will get around to supporting it.  For now, you have to do something like this:

<span class="CodeBox">
<pre>
INSERT INTO MyTable (FirstName, LastName, BirthYear)
SELECT 'John', 'Johnson', 1980
UNION ALL
SELECT 'Pete', Peterson', 1981
UNION ALL
SELECT 'Pradeep', 'Pradeepson', 1982
</pre>
</span>

The first version of this query would be especially useful if you're moving from MySQL to <a href="http://www.microsoft.com/sql/editions/express">SQL Server Express</a>, which doesn't offer any built-in way of importing data (which even Microsoft Access supports).  Why would you want to do this?  My motto is, "if it ain't broke, break it."  Maybe you want to <a href="http://www.amazon.com/Beginning-Server-2005-Express-Developers/dp/1590597206/ref=sr_11_1?ie=UTF8&qid=1206034742&sr=11-1">learn SQL Server</a>.  So instead, you could try a <a href="http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html">mysqldump</a> on the table you want to export:

<span class="CodeBox">
<pre>
mysqldump -u root -p MyDatabase Names > Names.txt
</pre>
</span>

You'll wind up with a complete catalogue of the structure and contents of the <b>Names</b> table.  Assuming the table structure already exists in MSSQL, the only part of the file we're interested in is the <b>INSERT</b> statement, which looks like this:

<span class="CodeBox">
<pre>
INSERT INTO `Names` VALUES 
  (1,'John','Johnson','1980'),(2,'Pete','Peterson','1981'),(3,'Pradeep','Pradeepson','1982');
</pre>
</span>

But as noted earlier, this won't work in MSSQL.  Rather than attempting some nasty find-and-replace tactics, I think there's an even better and easier solution: the INTO OUTFILE function.  This is used in a SELECT statement and will write the results of the query to a file.  We can get very close to the SQL statement that MSSQL needs using this technique.  Once again, we'll assume the table structure already exists, and that you've created your auto-incrementing and primary key ID column.  In other words, we won't be importing the ID column; MSSQL will create that data for us.  Here's the query I developed:

<span class="CodeBox">
<pre>
USE MyDatabase;
SELECT FirstName, LastName, BirthYear
FROM MyTable
ORDER BY FirstName, LastName, BirthYear
INTO OUTFILE 'DataOutput.txt' FIELDS ESCAPED BY '' TERMINATED BY ', ' 
  ENCLOSED BY '''' LINES TERMINATED BY '\r\nUNION ALL\r\nSELECT ';
</pre>
</span>

Save this as a file called DataOutput.sql in MySQL bin directory and execute it like this:

<span class="CodeBox">
<pre>
mysql -u root -p < DataOutput.sql
</pre>
</span>
This will write the file where the MySQL's data files are stored.  It will return this data:

<span class="CodeBox">
<pre>
'John', 'Johnson', '1980'
UNION ALL
SELECT 'Pete', 'Peterson', '1981'
UNION ALL
SELECT 'Pradeep', 'Pradeepson', '1982'
UNION ALL
SELECT
</pre>
</span>

Not bad!  Obviously it isn't exactly what we want, but it would be pretty easy to make the corrections.  Just add the INSERT INTO statement, add a SELECT to the first record, and remove the last SELECT.  Then execute the query in MSSQL.  Easy!]]></description>
         <link>http://blog.lib.umn.edu/jwo/jwotechtips/2008/03/inserting_multiple_rows_in_sql_1.html</link>
         <guid>http://blog.lib.umn.edu/jwo/jwotechtips/2008/03/inserting_multiple_rows_in_sql_1.html</guid>
         <category>Database</category>
         <pubDate>Wed, 19 Mar 2008 21:49:21 -0600</pubDate>
      </item>
      
      <item>
	<enclosure url="http://blog.lib.umn.edu/jwo/jwotechtips/ThunderbirdError.png" length="18810" type="image/png" />
         <title>Apple application error</title>
         <description><![CDATA[<p>This error will appear sometimes when you launch software that has been downloaded: "<strong>[Program] is an application which was downloaded from the Internet.  Are you sure you want to open it?</strong>"</p>

<p><img alt="ThunderbirdError.png" src="http://blog.lib.umn.edu/jwo/jwotechtips/ThunderbirdError.png" width="421" height="163" /></p>

<p>It is caused by extended attributes on the application and it can happen on many programs, including Firefox and Thunderbird.  Here's how to fix it:</p>

<p>1.  open terminal<br />
2.  su to admin<br />
3.  cd /Applications<br />
4.  xattr -d com.apple.quarantine Thunderbird.app<br />
5.  repeat for other applications that have extended attribs</p>

<p>You can check which apps contain these attribs by doing an ls -lsa.  You'll see "@" on the far right of the file's permissions listing.  Additionally, you can check the attribs on each file by doing a xattr -l [file/dir].</p>]]></description>
         <link>http://blog.lib.umn.edu/jwo/jwotechtips/2008/03/apple_application_error.html</link>
         <guid>http://blog.lib.umn.edu/jwo/jwotechtips/2008/03/apple_application_error.html</guid>
         <category>Apple</category>
         <pubDate>Thu, 06 Mar 2008 11:52:19 -0600</pubDate>
      </item>
      
   </channel>
</rss>
