Wednesday, October 10, 2012

Solved: Difficulty Pairing Apple Wireless Keyboard

I have an Apple MacBook Pro, and an Apple Wireless Keyboard.  From the very first day the keyboard has been difficult to pair with things.  Changing it from the computer to an iPad, or iPhone was always a confusing hassle.  The keyboard has only has one button and one status light, and gives almost no feedback.  I am surprised at the trouble it has given me as this is not an inexpensive keyboard.  Lately this hasn't been a problem as I have just left it paired with the MacBook Pro

Recently I paired it with an Android phone.  When I tried to unpair it from the phone, and repair it with my MacBook Pro, nothing worked.  I tried holding down the button, pressing the button and different key combinations, etc.  Most of the time the MacBook couldn't even find it, and if it did, the pairing would fail.

Then I tried to repair it to my Android phone, that didn't work either.  I tried pairing it to another Android phone.  Nothing.  I changed the batteries for new ones (twice).  Most of the time the green light would come on for about two seconds, and then turn off.  This was all very aggravating, since pairing is the must fundamental thing that the keyboard needs to do.  It is unusuable if you can't get it to pair.

Finally I found a good idea online.  I am documenting it here so that if I ever have this problem again, I will remember the steps that I had to take to repair.  I have tried this with both the Android phone, and the MacBook Pro, and it seemed to work with both.


  1. Turn on Bluetooth (if it isn't already turned on).
  2. Begin scanning for devices.
    • In Mac OSX, click on the little Bluetooth icon at the top of the screen.  Click "Setup Bluetooth Device...".
  3. After the computer or phone begins scanning, press and hold the power button on the wireless keyboard.  This is important.  When I tried pressing button first, then scan, nothing happened.  You have start the scan first, then press and hold the button.
  4. At some point the green light usually starts flashing (although not always.  weird).
  5. After a few seconds, it will (finally) notice the keyboard.  You may have to click on the keyboard to tell it to pair.
  6. It will ask you to type a few numbers to verify the pair.  At this point you can release the power button.
  7. Type in the requested numbers.
  8. The pairing should complete.
Hope this helps someone else out there.  I know that at some point in the future I will need to know this information again.


 

Wednesday, February 29, 2012

Identifying data type in literals without casting

Learning c#. When declaring literals, it turns out there is are some special suffix characters you can use to declare data type. They are:

• M (deciMal)
• D (Double)
• F (Float)
•L (Long)

So, for example, if you do the following:

decimal salesTaxRate = 6.5;

The compiler will interpret the literal "6.5" as a double, and you're going to have problems. But, just append a"D" and you're good. Like so:

decimal salesTaxRate = 6.5M;

Now the compiler interprets 6.5 as a fixed-point decimal, instead of a floating point double.

Why the compiler can't just assume that the double literal needs to be cast to a decimal, I can't say. Maybe one of the C# experts out there can say?

Friday, July 15, 2011

Saving XML to Database By Way of HTTP Post

I'm not sure how to articulate this one in an interesting manner, but for the few people who come up against this, this is important information to know.  Here is how to receive XML in an HTTP Post, and put it into the database.  Once you know how to do it, it is pretty easy.  However, getting it set up is trickier than you'd think.

  1. I am processing information from a third party. They hit a specific ColdFusion cfm page with some HTTP Post parameters.
  2. One of those Post parameters contains some XML.  The XML contains the data that I am interested in.
  3. I get the XML from the HTTP Post parameters using GetHTTPRequestData().  This takes the information from the Post, and puts it into a struct.
    1. <cfset variables.parameter_raw="getHTTPRequestData()">
  4. I take the XML and pass it into xmlParse().  This parses the XML, and dumps the XML into a very usable struct.
    1. <cfset variables.parameter="xmlParse(variables.parameter_raw)">
  5. Then, before doing anything else, I dump the XML into a log file.  This way, even if everything else goes wrong, I still have a copy of the XML for debugging or whatever.
    1. <cflog file="foo" text="#serializeJSON(variables.parameter)#">
  6. Then I extract the variables I need from the XML, and pass them into a CFC.  This is the tricky part.  For some reason, if you try to pass the parameter into the CFC only by name, it will add a bunch of invisible XML stuff to it, making it too long for the database column I want to save it to.  So, in order to just get the value, without all the other wacky XML added on, add ".xmlText" to the end.  See example below:
    1. <cfset data_access_object.save_data(data_id="variables.parameter.data_idb.xmlText,
                    data_value=variables.parameter.data_value.xmlText,               data_code=variables.parameter.data_code.xmlText)>
  7. That should do it.  That ".xmlText" is really hard to debug in this context if you don't know about it.  Hopefully this will help somebody else out there.

Sunday, October 03, 2010

Simple Java to make sure a directory exists before doing a cffile upload

Simple Java to make sure that a directory exists before doing a cffile upload:

<cfset CreateObject("java", "java.io.File").init("C:\Inetpub\wwwroot\myNewDirectory\images").mkdirs() />

So, for example, you might do something like this:

<cfset CreateObject("java", java.io.File").init("c:\uploads\#dateformat(now(), 'yyyymmdd')#") />

You can just do the above before every upload.&nbsp; The first time it will create the directory, and every time after that it will just do nothing.

Thanks to cfgears for reminding me how to do this:

http://www.cfgears.com/index.cfm/2009/5/19/Tapping-in-to-ColdFusions-underlying-Java-capabilities

Thursday, September 30, 2010

listFind vs. listContains

ColdFusion has two functions for finding things in comma-delimited lists, but they behave very differently, and I can never which is which.  Today I needed one of them, and so I did a test to figure out which I needed.  If figured I would document their usages here, so that I wouldn't have to go thru this testing process next time.  Here are the functions:

listContainsNoCase(list, substring)
This function just finds the substring, and tells you which item contains that sub string.  It is important to understand that this item is not searching for a list item, just for a sub string.  Consider the following example:
listContainsNoCase("Date,Decimal,Image,Integer,Long Text,Rich Text,Simple Text", "Text")=5
Notice how it found that item number 5 has the word "Text" in it, even though "Text" is not the complete item.

listFindNoCase(list, value)
This function finds a value in a list, and tells you which item matches the value.  It compares the value to the list item, and only accepts complete matches.  So, consider the following examples:
listFindNoCase("Date,Decimal,Image,Integer,Long Text,Rich Text,Simple Text", "Text")=0
listFindNoCase("Date,Decimal,Image,Integer,Long Text,Rich Text,Simple Text", "Simple Text")=7
Notice how in the first example above, no item was found.  This is because there is no single item with value = "Text".  However, it did find "Simple Text" in the second example above.

Of course the same is true for listFind, and listContains, but those are case-sensitive.

Incidentally, I put this one in the "duh" category, because I think that the names are reversed.  The first usage should be named listFind, and the second should be named listContains.

Hope this helps.

Monday, September 13, 2010

Resolving Samsung Captivate Windows 7 (64 bit) connection problem

------ NOTE ------

See the updates at the end of this post. Although many people have reported in comments that this fix worked for them, it actually stopped working for me after a few days. Consequently I have actually returned my Captivate in favor of a different phone that actually works.

------ END NOTE ------

On Friday I purchased a new Samsung Captivate from Costco. Before I get into the USB connectivity issues, let me just say that this is a great phone. Great speaker, great microphone, great ambient-noise management, great processor speed, great camera, outstanding screen, tons of memory, the list goes on. However, I encountered some serious problems getting it to connect to my computer. It took two days to get the problems resolved. Amazingly, neither this problem nor the solution is documented online. So, here is what I learned. I don't make any recommendations that you should try this, or any guarantees whatsoever that any of this will work for you, or that it will not damage your phone, etc, etc. Try it at your own risk, you have been warned. However, I did eventually get it to work for me, and am now much happier with my phone. Here's what I did.

First, the computer is a newish, capable, reliable laptop running Windows 7 Home Premium (64 bit). It is a pretty new install of Windows, and there are no known hardware problems. When I complained to the guy at the AT&amp;T store, he admitted that other customers have complained about the same problem. So I don't think that the problem was with my computer.

When I first attempted to connect my phone to my computer, Windows quickly reported that the driver install failed. I made several attempts, all of which failed. Next I tried on a Vista (32 bit) box. The driver install seemed to work OK, but it kept reinstalling over, and over, and over again. Like every 3 minutes, over and over again, times infinity. Weird.

So, after two days of research, and trial and error, and visiting 2 AT&amp;T stores, here is what I learned.

Samsung Captivate (and I believe other Galaxy class phones) use a software package called Kies to manage your phone's connection to your computer. By default, when you connect the Captivate (and probably most Galaxy class phones) to a USB port on Windows, it is only willing to talk to Kies. If you don't have Kies on the computer, then the connection will fail.

The bad news is that Kies is not available in the U.S. (!?). I had to download it from Samsung's Singapore website. Worse, Kies is kind of lame. It looks nice, is user friendly, and is a good effort, but isn't very useful and just got kind of got in the way.

The good news is that installing Kies also installs the drivers. After installing Kies, Windows immediately recognized my phone. So that's good.

The better news is that it turns out you may not actually have to install Kies at all. You can change the default USB setting on the device (which I have done). If you go to settings &gt; Applications &gt; USB settings, you will see that the default USB behavior is set to "Samsung Kies". I changed mine to "Mass Storage". Now when I connect my Captivate to my computer, it doesn't try to talk to Kies. Instead, it just pretends to be an "External Mass Storage" device which Windows has no problem recognizing (think external hard drive, or thumb drive).

Next, when I connect my Captivate to the computer, Windows makes that happy little two-tone chime that means something has successfully connected. Then on the Captivate, I just have to tell it to mount on my computer. There is a little status bar along the top of the screen. If you touch that bar and drag it down, there are some useful toggle buttons and a section called "Ongoing". Under ongoing there is a "USB connected" entry. When I click "USB connected", it asks me if I want to mount my phone on Windows. If I click "Mount", then I can access my phone just like an external hard-drive. I can copy music or pictures directly onto or off of the phone. Easy-peasy.

So, at least now I have a way to get stuff onto and off of my phone, and I don't have to use Kies. This is good. Also, I reformatted the internal SD card (read somewhere online that this helps).

Again, I don't promise or guarantee or warranty or say that any of this will work for you. Just that it worked for me. Good luck!

Now I would just like to take a moment to talk directly to Samsung.

Samsung, listen, you are a big company. You are a respected brand. You make good products. You spend millions of dollars advertising them. But even though your phone is widely available for purchase across the U.S., it cannot connect to Windows 7 without your users going to extensive lengths to research and troubleshoot, and the software for your phone isn't even available in the U.S. This is a problem. It's not like this is a special advance order phone direct from Japan. This is a widely advertised, commercially available phone that consumers can buy at any AT&amp;T store, Costco, Sam's Club, Best But, etc. Yet they cannot connect their phone to their computers, unless they download software from Singapore, or change unfamiliar settings.

Please fix this. Either release your software in the U.S., or include instructions in the packaging or on your website on how to change the USB settings. Better yet, on your phones sold in the U.S., just default them to "Mass Storage" mode, and include a quick-start paper on how to mount the phone as an external hard drive.

Ok, that's all for now. Will report if the situation changes.

------ UPDATE 10/3/2010 ------

Unfortunately, the fix described below stopped working for me a few days ago. That was the last straw. Although I liked the Samsung Captivate, I decided that I wasn't going to keep a phone that lacks basic driver support and can't even figure out how to connect to a computer. So, I returned my Captivate to Costco, and bought an iPhone instead.

------ UPDATE 10/4/2010 ------

On 10/2/2010 Anonymous commented: "I cannot believe this phone has been out for now over 3 months and no fix. Shame on Samsung; this is why people turn to macs and iPhones, lazy companies."

I agree. Putting the time, effort, and R&amp;D money into building a fabulous phone, and then failing to deliver basic USB drivers (even just simple Mass Storage drivers) is absurd in the extreme. That's like spending months building a fabulous house, and then failing to include something simple like a door. Eventually no matter how great the house is, the owner will get tired of climbing into the house through a window, and just buy a house--any house--with a door.

------ END UPDATES ------

Thursday, September 09, 2010

ORM is not configured for the current application

Working on a little app in ColdFusion 9.  Was consistently getting a phantom ColdFusion error (especially containers loaded by the built-in ColdFusion.navigate function):
ORM is not configured for the current application

Very mysterious, and took a while to troubleshoot.  In my Application.cfc, in the onRequestStart method, there was a <cfset ormreload()> .  I had put it there thinking that while I was doing some development it would be nice to have the ORM reloading all of time as I make changes.  However, it looks like it was interfering with the ORM's sequencing, and on Ajax page loads it was causing ColdFusion to erroneously report back that the ORM was not loaded.  I simply moved the ormReload to onApplicationStart, and the problem seems fixed.