Android ISO8601: How to Convert a Date to call APIs

I have needed to get a date in java converted to ISO8601 on android for awhile and struggled through a few different issues on my way to a working solution.

Since it’s an app that I’m asking people to download, I don’t like to increase the download size by even a few MBs. So even though Joda Time is great, I need a different way. In researching, I had to piecemeal a solution from various blogs and stackoverflow posts.

If you’ve ever been wondering,
– Does android have a standard way to convert to iso8601 format?
– Why isn’t it easier to get a UTC date that follows iso8601 so I can just call the APIs?
Then hopefully I can save you some time.

Android ISO8601: UTC SimpleDateFormat

The following is a straightforward way to get a UTC ISO8601 string of a date object without using any external libraries.


SimpleDateFormat ISO8601DATETIMEFORMAT = new SimpleDateFormat("yyyy/MM/dd 'T'HH:mmZ");
TimeZone  tz = TimeZone.getTimeZone("UTC");
ISO8601DATETIMEFORMAT.setTimeZone(tz);
String isoDate = ISO8601DATETIMEFORMAT.format( dtobject);

Android ISO8601: APIs Don’t like Arabic Chars

But wait, sometimes this still sends over Arabic characters like:

\u0662\u0660\u0661\u0666-\u0660\u0662-\u0662\u0665T\u0660\u0664:\u0665\u0661Z 

We don’t want that.  The solution turns out to be fairly simple.  Make sure that the SimpleDateFormat is always converting using the English language locale.

SimpleDateFormat ISO8601DATETIMEFORMAT = new SimpleDateFormat("yyyy/MM/dd 'T'HH:mmZ",Locale.ENGLISH);

**Credit goes to this StackOverflow Comment Suggesting Locale.English

Android ISO8601: A Convenience Class

To wrap it all up, here’s a convenience method.  It can be dropped in without adding any major overhead to your app in terms of size or performance.


public class AndroidISO8601Util{

      static SimpleDateFormat ISO8601DATETIMEFORMAT = new SimpleDateFormat("yyyy/MM/dd 'T'HH:mmZ",Local.ENGLISH);

      //Note: this method is not thread safe because SimpleDateFormat is not thread safe
      public static String getISO8601forAPI( Date dt){
      TimeZone tz = TimeZone.getTimeZone("UTC");
      ISO8601DATETIMEFORMAT.setTimeZone(tz);
      return ISO8601DATETIMEFORMAT.format( dtobject);
    }
}

Export Unsigned APK with Android Studio

For years I developed with eclipse and used the Android Tools option to Export Unsigned APKs.

Eclipse Android Tools had an easy option to Export an Unsigned APK
Eclipse Android Tools had an easy option to Export an Unsigned APK

I could then take the unsigned .apk file and upload it to Amazon’s developer console.

This was one of the last items I was still using eclipse for after over a year of Android Studio development.  I finally spent some time figuring out how to make the same thing happen without needing eclipse any longer.  I found many of the questions and answers on stackoverflow to be confusing and inaccurate.  For example, many seem to think that using the debug apk is the same as using the unsigned release apk…which is not accurate.

This is the comment that ended up helping me get it right:  http://stackoverflow.com/a/32202274/966122

Here’s How to Export Unsigned APK in Android Studio

1. Edit the gradle build file for the project to specify an unsigned release signing.

buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}

releaseUnsigned.initWith(buildTypes.release)
releaseUnsigned {
signingConfig null
}

}

2. Generate Signed Apk using the releaseUnsigned Build Type.  This is on the 3rd or 4th screen in the flow of version 1.4 of Android Studio.

Release unsigned apk in android studio
Release unsigned apk in android studio

Enjoy the Unsigned APK

Once the build finishes, there will be an unsigned apk in the location you specified. You can then upload that apk to an emulator or to Amazon to start the process of letting amazon sign the app.

Fix: part of the process of setting a preferred domain is to verify that you own error

I was trying to set naked domain as preferred domain in google webmaster tools and it showed an error “Part of the process of setting a preferred domain is to verify that you own http://example.com/. Please verify http://example.com/.”

If you’re not familiar with the terminology, a naked domain is the domain name without anything preceding it.  So no www., blog. or anything.  Just plain example.com is a naked domain.  I prefer this setup to the www. prefix when I can because it makes urls shorter and easier to read.  There’s still debate about it’s impact on SEO.

Fix the “part of the process of setting a preferred domain is to verify that you own” warning

First, create both the www.example.com and example.com versions of your site in google webmaster tools.  This is exactly the step I had skipped which led to the confusing error.

Make sure that both versions show up as verified sites in google.

Then, navigate into the www.example.com version of the site and change the site’s preferred domain to be example.com.

Add both sites to Set Naked Domain as Preferred Domain
See that both versions of site are verified

From there, things are straightforward and you shouldn’t see any errors.

Just go into each sites site settings.  Tap the site name, then Settings->Site Settings in the top right and choose to have the preferred site domain be naked domain.

More Information

For more information and tips about the whole process of setting your preferred site, there are many good detailed posts out there.  For example, this one.  However, I couldn’t find a clear answer to the problem I was running into while getting the “part of the process of setting a preferred domain is to verify that you own” error which led to this post.

Untangled Christmas Lights: How to avoid detangling

If you use mini-lights and mini-light icicles, use zip ties to make sure you have untangled Christmas lights when they come out of the box next year.

I love the “Little knot here” scene from Christmas Vacation where he just hands Russ a huge ball of tangled lights.

Storage Methods I’ve Tried

I am talking about strands of 200+ outdoor mini-lights.  If you have the huge kind that line the roofline, I would use the method on the following post for storing  with cardboard for large C7 or C9 bulb strings.  For shorter strands like most indoor ones, I like this method to pack short indoor mini lights.

I’ve tried using the cardboard from inside paper towel rolls, wrapping into a ball, coat hangers and for awhile I liked using the plastic bags from the grocery store was my favorite method until I discovered zip ties.

Use Zip Ties for Untangled Christmas Lights

Here’s all you need to do.  Wrap the lights around your elbow by making a hook around your thumb similar to how most people wrap up an extension cord.  Once you’ve got the strand wrapped up, snap a zip tie around it.  A second zip tie on the other side makes it nearly impossible to get a tangle.  I normally just do a single zip tie and place things into the storage bin neatly.

So that’s the easiest way to have untangled christmas lights when you go to put them up next year.

Here’s what a strand that’s ready to go in the storage bin looks like:

Untangled Christmas Lights using a zip tie

 

Advice for Next Year

To keep from getting tangles, I take the zip tied strands out and set them next to where I plan to use them.  Then I only snip the zip tie when I am going to use that strand of lights.

If you like my tip for having tangle free Christmas lights, check out these links to advice for making it easy to put them up next year:

Putting Up Christmas Lights: 3 Tips to Save Time

Hang Christmas Lights In Outdoor Trees

Hang Christmas Lights In Outdoor Trees

Our neighborhood has professionals come in and install lights in the trees on the way in and out of the subdivision and they look fantastic. My wife wanted the same thing at our house but I didn’t know how to hang Christmas lights that high in the trees.  I also didn’t want to pay the steep price for the pros.  I’ve given other advice on how to make the whole job easier at Make Putting Christmas Lights Up Easy.  Since I’ve had others that live near me ask me quite a few times how I hang Christmas lights up in the trees, I thought it’s worth sharing.

Here’s what one of our big trees looks like this year:

Hang Christmas Lights in a Big Tree

Hang Christmas Lights in Your Trees

Here’s how I did it. We got a ton of lights from Target in and after Christmas sale. These trees use up the lights really quickly. For the tree in that picture, I used 4 strands of 200 to make 800 lights. Only 200 are down on the base.

I made a basic tool from a $15 pole extension at Lowe’s, the top of a wire closet hanger, and some duck tape.  This thing doesn’t require any instructions.  I have an 8 foot step ladder, am 6 foot tall, and with this extension tool I can get the lights up about 30 feet into the tree.

ChristmasLightsPole

The Story Behind the Tool

I grew up with my dad climbing the step ladder and using the neighbor’s limb cutting extension to get the lights up.  Repurposing the tree trimming tool was cumbersome and he even cut a strand of lights at one point.  The tool also didn’t extend far enough to get a professional look.

Since I couldn’t recall what to do from childhood, I just went up to the local hardware store and started looking around for things that might work.  The window washer’s extension pole was a good price and looked like it would work so I grabbed it.

Hang Christmas Lights in Trees


cURL Example: Post a JSON File with Basic Auth

The web was missing a clear example that showed how to POST a JSON file with Basic Auth.  I love using cURL for it’s simplicity when trying out api’s and other services that I might want to use and have spent a decent amount of time figuring this particular usage out more than once.  If nothing else, I’ll be helping myself next time.

cURL JSON + Basic Auth Samples

In this case, I have a file locally that’s contents are the JSON which I want to be the payload of the POST.  Note that I do not want to POST the file as with a multi-part form upload.

curl -X POST -d @pathtofile https://user:pass@www.samplesite.com

Depending on the service you are calling, you might also need to set the Content-Type and encoding.

curl --header "Content-Type: application/json;charset=UTF-8" -X POST -d @pathtofile https://user:pass@www.samplesite.com

Finally, for troubleshooting, I’ve found it useful to either use the verbose -v for inspecting headers or –trace-ascii /dev/stdout for seeing the content of the request

curl -X POST -d @pathtofile https://user:pass@www.samplesite.com -v
curl -X POST -d @pathtofile https://user:pass@www.samplesite.com --trace-ascii /dev/stdout

Sample Output of –trace-ascii /dev/stdout command

== Info: Trying aa.xx.dd.bb…
== Info: Connected to xyz.abcd.com (aa.xx.dd.bb) port 443 (#0)
== Info: TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
== Info: Server certificate: xyz.abcd.com
== Info: Server auth using Basic with user ‘admin’
=> Send header, 241 bytes (0xf1)
0000: POST /demo HTTP/1.1
0031: Host: xyz.abcd.com
004f: Authorization: Basic Z3JlZW5oYXRhZG1pbjoxMjNBZG1pbiE=
0086: User-Agent: curl/7.43.0
009f: Accept: */*
00ac: Content-Type: application/json;charset=UTF-8
00da: Content-Length: 596
00ef:
=> Send data, 596 bytes (0x254)
0000: { “Students”: [{ “MIS_ID”: 201073, “Forename”: “Test”, “Surname
0040: “: “Tester”, “Email”: “xyz.abcd@gmail.com”, “YearGroup”: “6
0080: “, “Gender”: “M”, “Password”: “Ab@12” }, { “MIS_ID”: 161201, “Fo
00c0: rename”: “Tester”, “Surname”: “Test”, “Email”: “xyz.abcd@gm
0100: ail.com”, “YearGroup”: “6”, “Gender”: “F”, “Password”: “Ab@12
0140: ” }], “Staff”: [{ “TeacherID”: 220380, “Title”: “Mrs”, “Forename
0180: “: “Test”, “Surname”: “Tester”, “Email”: “xyz.abcd@gmail.
01c0: com” }], “Groups”: [{ “GroupID”: 63, “GroupName”: “6A Science”, ”
0200: GroupType”: “Class”, “GroupDescription”: “6A Science”, “PrimaryS
0240: taffId”: 220380 }] }
== Info: upload completely sent off: 596 out of 596 bytes
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 52 bytes (0x34)
0000: Cache-Control: no-cache, no-store, must-revalidate
<= Recv header, 47 bytes (0x2f)
0000: Content-Type: application/json; charset=utf-8
<= Recv header, 37 bytes (0x25)
0000: Date: Wed, 09 Dec 2015 16:02:52 GMT
<= Recv header, 40 bytes (0x28)
0000: Expires: Thu, 19 Jun 1980 19:19:19 GMT
<= Recv header, 18 bytes (0x12)
0000: Pragma: no-cache
<= Recv header, 15 bytes (0xf)
0000: Server: nginx
<= Recv header, 45 bytes (0x2d)
0000: Strict-Transport-Security: max-age=31536000
<= Recv header, 23 bytes (0x17)
0000: Vary: Accept-Encoding
<= Recv header, 20 bytes (0x14)
0000: Content-Length: 25
<= Recv header, 24 bytes (0x18)
0000: Connection: keep-alive
<= Recv header, 2 bytes (0x2)
0000:
<= Recv data, 25 bytes (0x19)
0000: {“i”:”4T7hz8tz8KU7ms2rz”}
== Info: Connection #0 to host xyz.abcd.com left intact
{“i”:”4T7hz8tz8KU7ms2rz”}%

Access ENOM DNS panel for Google Apps domain

I was unable to access the ENOM DNS console for a domain I bought through google years ago when they were still giving away google apps for free.

I was beating myself up for not being able to figure this out and the advanced DNS settings that used to be in Google Apps admin console have since been removed.

A quick call to enom ( after a not so quick wait time) got me exactly what I wish I had been able to find on the interwebs.  If you forgot your password or just cannot access enom DNS control panel from Google Apps dashboard, this should help.

How to Access ENOM DNS Console

If you’re trying to get in to change your nameservers, it’s easy.

  1. Visit https://access.enom.com
  2. Put your domain name and any password in along with the captcha.Get the password from your email.
  3. Change those nameservers or A records.  If you use google apps with the domain, only change the A records or the email and other functions of google apps will break.  Hopefully your hosting provider makes it easy to find the correct ip address to point the A record towards.

access enom DNS panel for google apps domain

 

Brine in a Milk Jug – Kitchen Hack

Many are still debating whether or not to brine.  I’m convinced that it helps keep chicken or poultry juicier no matter how it’s being prepared.  It’s especially evident when the meat is going on the grill.

This is the easiest way I’ve found to make brining a part of my dinner prep because it doesn’t make any extra dishes, it’s simple to do and you still just recycle the jug when you’re done.

All you need is a milk jug, a funnel, and some kitchen scissors.

 

chicken in brine in jug

Brine the meat in the jug

Thaw and flatten meat.  I like to try and get the meat to be of similar thickness so that cooking times are similar.

Put the water, salt, and whatever else you like in your brine into the jug, put the cap on and shake it up.  The basic brine in the picture is 1/4 cup of salt, 1/4 cup of sugar and 1/4th of the gallon jug with water.  The ingredients that people use vary considerably, but I’ve found this is effective for my primary goal of getting a juicier piece of meat on my dinner plate.

Cut off a piece of the jug and put the chicken in.

20151208_131953Shake up the brinechicken in the brine

 

Use the jug to drain with ease

drain the brineAfter the time is up, drain the fluid out the remaining side and dry off the meat with a couple of paper towels.

 

Voila!  Cook the meat with your favorite method and you’ll get all the greatness of the brine without much work.

iHome iBT74 Bluetooth Speaker: Why I bought

I bought an iHome iBT74 Bluetooth Speaker 2 months ago after doing quite a bit of comparison shopping online and then in the store. I ended up choosing this and so far I couldn’t be happier.

  • Price: The iHome bluetooth speaker is reasonably priced against the competition and with a little digging can normally be found for under $50. For the features it comes with, the price is very competitive.  It has a long battery life, you can answer phone calls, and the bluetooth connectivity with my phone has been more reliable than my previous speakers.
  • Sound: For a smallish speaker, the sound is quite good. You won’t ever be able to get a ton of base from little speaker like this, but for the size and mobility, I’ll take the sound quality.
  • Old School Cable: While I love the wireless bluetooth connections, sometimes I just need the reliability that of the old cable. I bought a few bluetooth speakers previously that only offered bluetooth connectivity and wished many times that I could plug in.

Biggest downside: For awhile I thought that there wasn’t any way to turn off the lighting. Even though the lights are pretty cool, there are times that I don’t want my speaker blasting out a bunch of light. There’s a button to cycle through different light schemes and one of the schemes is to have all the lights off.

In summary, if you’re looking for a pretty inexpensive but high quality bluetooth speaker that’s great on portability and reliable for connectivity.  Buy the iHome and carry the cable just in case the weather acts up.

Putting Up Christmas Lights: 3 Tips to Save Time

It’s been over 4 years now since I’ve moved into my current home and really started to try and do a great job on the Christmas lights out in our yard. We went from a condo where it didn’t take long at all to having a bunch of huge trees and roofline that I’ve only got a ladder tall enough to get up to the top of the garage roofline. In other words, putting up Christmas lights and taking them back down took forever the first year we were here. Now I can get them up and down well enough to think I should share some advice.

If I haven’t mentioned it before, I am constantly thinking of strategies to make everything easier. These tips make it easier to get your lights up and down without the headaches and frustration.

So here are the tips.

1. Start from the power

As you put the lights up, or even prior to, plan out how the power is going to make it to all of the various parts of the yard that you’re going to have lights in.  The easiest way to make this job take forever is if you have to redo things or run to the store for more extension cords.  As much as I love Christmas vacation, I do everything I can to avoid a moment like Clark’s problem with the power!

Tips:

    • Save a few strands of old broken lights to make running the power easier short distances between things like bushes or trees.
    • Put the lights up with the power on so there are no surprise outages.
    • Get the timers that turn on automatically at dusk.
    • Measure beforehand to make sure the extension cords and sets of lights you have will get the job done.

2. Get the right tools

Here’s all the things I use to make getting the lights up easier.

  • Get an extension pole with a hook on the end. I make my own out of an old coat hanger and a 16ft extension pole from the hardware store. I also made one for my dad and he reminds me every year that it’s one of the best gifts he’s ever been given. I have more info about this pole over in my post on hanging Christmas lights in trees.
  • Use shingle/gutter plastic hooks to hang on roofline or gutters. When I was a kid, we used to use nails and a staple gun to get the lights on the roofline. Not anymore, using the right hooks on the roofline makes the lights go up and come down a whole lot easier. Ditto for getting them on the gutters. Here’s the ones I use:

  • Have plenty of replacement bulbs on hand. While I am putting up Christmas lights or taking them down, I replace broken bulbs. Being diligent about this has kept me from having a strand out the last three years. Last year, I even had my kids take all the good bulbs remaining off a strand of lights that had been heavily damaged by the wind.
  • Get the Swiss-Army knife for Christmas Lights Tool. This tool is a lifesaver. Whenever a strand of lights looks like it’s going bad, I can use this tool and replace a few bulbs to bring it back to life. I’ve even been able to bring an old nativity set back to life where most of the pieces in the set didn’t have a single working light on the first time I plugged them in.

3. Keep the lights tidy

Finally, keeping things organized and untangled is key to making this job easy. To streamline this piece of the job, I find the following to be very useful:

  • Get the right storage bin(s). Think it through for your house. Having the right storage can save a ton of time. I bought one really large storage bin on wheels for all the strands of lights. I keep it in the garage under my workbench and wheel it out when it’s time for them to go up or down.  I also throw a couple pieces of cardboard in just to make sure too much moisture doesn’t get in the lights.

  • Use zip ties to keep the lights from getting tangled. I read all kinds of tricks for how to keep the lights from getting tangled. I even used plastic grocery bags one year. Those weren’t bad; but for my money and time, zip ties are worth the few cents for how much easier they are to secure to the lights and snip off when it’s time to put them back up.  I’ve got more on using zip ties to avoid tangles.

Summary: Putting Up Christmas Lights Gets Easier

There you go. If you follow these tips, getting lights up and down each year will just keep getting easier.
Please do me a favor and if you have any tips for me that make putting up Christmas lights or taking them down even easier, be sure to comment below.