Skip to main content

Posts

Android http request crash fix executing getInputStream()

The Problem: In my Android app, I needed to make a simple call to a REST endpoint. I created a separate class extending the AysyncTask class like I am supposed to and as far as I was concerned, my code was clean and compiled just fine. Unfortunately, a runtime error occurred when getInputStream() was executed.  It jumped right to my “finally” block and the process ended suddenly. My Research: I added printStackTrace() to my finally block. When I caught and examined the stack trace, this is what I found: SecurityException: Permission denied (missing INTERNET permission?) The Solution: After extensive googling, I realized I needed to add a setting to my AndroidManifest.xml file:      <uses-permission android:name="android.permission.INTERNET" /> After running debugger, I finally made a successful htttp request. Here’s my code.      String json = "";          ...

Capturing Enter-key click event via Javascript (JQuery)

The Problem: The website I work on has a search submit button inherited on all pages.  Some pages have forms with submit buttons.  the result:  Enter-key click event chaos! Currently, when a user fills a form and clicks the enter key to submit it, the search box submit button is triggered rather than the form button. Therefore, user gets pissed. The Solution: I captured the enter key click event on page load and set what button to be triggered when enter-key is pressed.  If a form buttons is visible, click that submit button first.  If not, let the enter key trigger the search box submit button as usual. The Code: $(document).bind('keypress',function(e){ if(e.keyCode === 13) { var buttons = $('.continue-button:visible'); if(buttons.filter('#formSubmit').length > 0) buttons.filter('#formSubmit').click(); else if (buttons.filter('.next').length > 0) buttons.filter('.next').click(...

Large Data and JSONP - Dealing with IE's Cross Domain Headaches

The Problem: I created dynamic form generating application which sends form data (json object via JQuery ajax call) to an endpoint which then stores data to a database.  I’m using a third party service which appends more data to the object (company data by email address/IP address) which makes the object HUGE!  Posting the data to the endpoint works perfectly (Chrome and Firefox ), but IE, not so much.   Here’s the issues: The form generator app is used on cross-domain sites, which IE isn’t too happy about.   In other words, No Posting! JSONP works with GET requests, but the 2083 char limit in IE chops the request, resulting in No Transport or json call fail. Json = Error: jQuery was not called The Idea: What if I did the following: Create a new endpoint called “ThanksIE” Chop the json object every 1500 characters and sent multiple jsonp requests to  new endpoint. Each request will also have a similar guid, and index parameter ...

Return JSON straight up (not a string) in ApiController

The Problem: Had a hard time returning a plain JSON object from an ApiController (MVC4).  Instead, I'm getting the JSON object as a string. For example: "{\"dobSP\":\"90.25\",\"latestSP\":\"2025.9\",\"dobStampPrice\":\"0.15\",\"latestStampPrice\":\"0.49\",\"dobStampImage\":\"http://media1.s-nbcnews.com/j/msnbc/Components/Photos/051207/051207_stamp_news_hmed.grid-4x2.jpg\",\"latestStampImage\":\"http://media1.s-nbcnews.com/j/msnbc/Components/Photos/051207/051207_stamp_news_hmed.grid-4x2.jpg\",\"dataUpdated\":\"1/8/2015 11:27:48 AM\"}" What I've Learned: My Get method (in the controller) was specified to return a string object.  What I needed to return was a HttpResponseMessage type.   The Fix: I simply created a method that created the response for me:         private HttpResponseMessage ConvertToHttpResponse(string t...

Linq to DataTables - The Easy Way

The Problem: Couldn't easily read an excel file and query it programmatically. Using JSON.Net took a little longer than I thought it would. Wanted to brush up on my Linq skills. This was a rush job The Solution: Utilized "Excel Data Reader", which allowed me to read Excel data and converted it to a DataSet Used Linq to query the data easily, and produced manageable code (for me anyway) Used JSON>NET to serialize my code and write to the DOM Code Samples:             DataRow dr = ds.Tables[0].Rows.Cast<DataRow>()                 .Where(row => row["Column1"] == DBNull.Value)                 .FirstOrDefault(); In this example, I'm wrote a simple Linq query which returned all rows in the DataTable what has any data in the first column. Not the most sophisticated, but you get the point. What I've Learned: Origina...

Completely Remove a Commit in a Github Branch

I had a hard time trying to find a straight forward way  to completely remove a commit in Github.  I installed a plug-n that was suppose to make my life easier, but did the complete opposite. With no further adieu, here's the commands: git reset --hard <the commit you want as HEAD> git push origin HEAD --force Done and done. More reading: http://stackoverflow.com/questions/1338728/delete-commits-from-a-branch-in-git

Resolved Sitecore "If you publish now, the selected version will not be visible on the web site" warning

The Problem:   Unable to publish any Sitecore item within a particular site, even out of the workflow. Rather, a warning reads " If you publish now, the selected version will not be visible on the web site " What I've Discovered: I couldn't publish any item in the site, not just one or two I viewed all parent items of the items in question The main home page displayed a different warning " This item will never be published because it's publishable option is disabled " Another sitecore developer reminded me of the standard fields option View --> check standard fields to show all standard page fields Found out that somebody checked Never Publish within the publishing section The Fix: After I unchecked the checkbox and saved the change, I was able to publish again.  :) Conclusion: Looks like another Sitecore user thought the children items would not be affected by this change.  Lesson  learned.