Challenges that each developer faces every day

Wednesday, June 27, 2012

Android: AndroidRuntime android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

Have you seen this ugly error where is is totally not supposed to be there?

Error: AndroidRuntime android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

I was working on an app about local restaurants in Niagara and had an about window.

Solution:

error
...
private static Context context;
....

MainActivity.context = getApplicationContext(); // this was causing some nasty errors.

correct
MainActivity.context = this;


Related
http://www.mkyong.com/android/android-alert-dialog-example/
http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext

 Digg  Del.icio.us  Reddit  SlashDot

Wednesday, June 20, 2012

curl: (3) [globbing] error: bad range specification after pos NN

This is an error when you try to call a URL containing {} or [] at NN position.

curl: (3) [globbing] error: bad range specification after pos NNN

how I used it

/usr/bin/curl -s http://somesite.ca/api?filter[date]=last_12_hours

solution: by using --globoff

/usr/bin/curl -s --globoff http://somesite.ca/api?filter[date]=last_12_hours

Credit:
https://bbs.archlinux.org/viewtopic.php?id=74675

 Digg  Del.icio.us  Reddit  SlashDot

Monday, May 14, 2012

quiet git log: How to get shorter version (one line) of git logs

Do you want to see shorter log messages from git ?


example
5441641 fixed support.php : wasn't validating
25af6d5 updated background
a3v0a49 enabled the backup

solution
git log --pretty=oneline --abbrev-commit

if you want to logs to be between certain date you can do this
git log --since=2012-04-20 --until=2012-04-30 --pretty=oneline --abbrev-commit


Credit:
Gauthier - http://stackoverflow.com/questions/4479225/how-to-output-git-log-with-the-first-line-only


Keyword: git, git-log, git log --quiet

 Digg  Del.icio.us  Reddit  SlashDot

Wednesday, April 25, 2012

$("#qfileupload").fileupload is not a function, $("#qfileupload").qtips is not a function

Have you seen this annoying JavaScript error message ?

$("#some_id").someplugin is not a function

I bet you have!

in most cases the plugin is not loaded but when everything is loaded fine then you should check if jquery is loaded more than once.

It turned out that if there are multiple copies of jquery loaded this causes the jquery extensions not to work.

Just lost a few hours troubleshooting this.


 Digg  Del.icio.us  Reddit  SlashDot

Thursday, March 1, 2012

How to detect old browsers in PHP and show a obsolete browser notice



put this in a file called common.
Class App_Util {
    function is_old_browser() {
        $old = 0;

        if (!empty($_SERVER['HTTP_USER_AGENT'])) {
            // IE <= 7
            // User Agent: Opera/9.80 (Windows NT 6.1; U; en) Presto/2.10.229 Version/11.61
            if (preg_match('#msie\s+(\d+)\.(\d+)#si', $_SERVER['HTTP_USER_AGENT'], $matches)) {
                if ($matches[1] <= 7) {
                    $old = 1;
                }
            }
            // Firefox <= 7
            // User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2
            elseif (preg_match('#Firefox/(\d+)\.(\d+)[\.\d]+#si', $_SERVER['HTTP_USER_AGENT'], $matches)) {
                if ($matches[1] <= 7) {
                    $old = 1;
                }
            }
            // Safari < 5
            // User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.52.7 (KHTML, like Gecko) Version/5.1.2 Safari/534.52.7
            elseif (preg_match('#Version/(\d+)[\.\d]+ Safari/[\.\d]+#si', $_SERVER['HTTP_USER_AGENT'], $matches)) {
                if ($matches[1] < 5) {
                    $old = 1;
                }
            }
            // opera < 11
            // User Agent: Opera/9.80 (Windows NT 6.1; U; en) Presto/2.10.229 Version/11.61
            elseif (preg_match('#Opera/[\.\d]+.*?Version/(\d+)[\.\d]+#si', $_SERVER['HTTP_USER_AGENT'], $matches)) {
                if ($matches[1] < 11) {
                    $old = 1;
                }
            }
        }

        return $old;
    }
}

How to perform the check
file: block_old_browser.php

<?php if (App_Util::is_old_browser()) : ?>
    <div class="app_old_browser_notice">
        <h2>Old Browser</h2>
        <p>Please consider upgrading your browser. Doing so will improve experience with the site. <br/>
        Please click one of them below.</p>
        <ul>
            <li><a href="http://www.mozilla.org/en-US/firefox/fx/" target="_blank">Mozilla Firefox</a></li>
            <li><a href="https://www.google.com/chrome" target="_blank">Google Chrome</a></li>
            <li><a href="http://www.apple.com/safari/" target="_blank">Safari</a></li>
            <li><a href="http://www.opera.com/download/" target="_blank">Opera</a></li>
            <li><a href="http://www.microsoft.com/windows/ie/" target="_blank">Internet Explorer (Windows)</a></li>
        </ul>
    </div>
<?php endif; ?>

Include the file above in all the files that you need to the noticed displayed.
<?php include('block_old_browser.php'); ?>

css styles
<style>
.app_old_browser_notice {
    background-color:#ff0000;
    color: white;
    margin:20px;
    padding:10px;
}

.app_old_browser_notice a {
    color: white;
}
</style>

 Digg  Del.icio.us  Reddit  SlashDot

Wednesday, February 22, 2012

Internet Explorer offers/prompts JSON output for download

I playing with jQuery and ajax stuff and tried to test my app in Internet Explorer.

this is the function I have for emitting JSON.
Iinitally, I had Content-Type: application/json but IE 9 started started prompting me to save the file that was called by the Ajax.
Replacing the content type with Content-Type: text/javascript seems to work in IE, Firefox, Opera, Safari.

// slavi: links // links preceeded by space i.e. no http prefix
function json($struct) {
    header('Cache-Control: no-cache, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Content-Type: text/javascript'); // IE doesn't like application/json content type
//    header('Content-Type: application/json; charset=utf-8');

    echo json_encode($struct);

    exit;
}


Related
http://stackoverflow.com/questions/6114360/stupid-ie-prompts-to-open-or-save-json-result-which-comes-from-server
http://stackoverflow.com/questions/2483771/how-can-i-convince-ie-to-simply-display-application-json-rather-than-offer-to-do
http://stackoverflow.com/questions/425854/jquery-ajax-request-failing-in-ie

 Digg  Del.icio.us  Reddit  SlashDot

Wednesday, February 15, 2012

Confusing input boxes for GoDaddy Nameservers During Registration

I know that GoDaddy is a big company but I am still trying to understand how do those people can allow this kind of UI to be live.

I am a programmer and I find it super confusing.
On my domain registration step I find 3 boxes per name server.
what's that ?

there are multiple options and I don't know how to interpret it.

[ns1] [mydomain] [com]

[ns1] [mydomain.com] [____]

[___] [ns1.mydomain.com] [____]

So strange.

 Digg  Del.icio.us  Reddit  SlashDot