Posts tagged Programming

Shortened URLs should be treated like a Codec …

Codecs are used to compress data to send over the wire, but when it gets to the other end it is decoded back to its original form for display.

Shortened URLs are used to compress long URLs to send over Twitter.

So why aren’t they expanded again on the other side? Why do Twitter clients show short urls instead of expanding them back out to a long URL, or at least a display that tells you what the real web site is.

This has implications for reducing attacks hidden in short URLs and for allowing you to see at a glance that “Check out http://bit.ly/a567as” is actually the same site you’ve already read once today from another Tweet.

So for my own Twitter client I decided to expand all shortened URLs as far as I could go. Here’s a code snippet to do that:-

        /// <summary>

        /// Follow any redirects to get back to the original URL

        /// </summary>

        private string UrlLengthen(string url)

        {

            string newurl = url;

 

            bool redirecting = true;

 

            while (redirecting)

            {

 

                try

                {

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(newurl);

                    request.AllowAutoRedirect = false;

                    request.UserAgent = “Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 4.0.20506)”;

                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                    if ((int)response.StatusCode == 301 || (int)response.StatusCode == 302)

                    {

                        string uriString = response.Headers["Location"];

                        Log.Debug(“Redirecting “ + newurl + ” to “ + uriString + ” because “ + response.StatusCode);

                        newurl = uriString;

                        // and keep going

                    }

                    else

                    {

                        Log.Debug(“Not redirecting “ + url + ” because “ + response.StatusCode);

                        redirecting = false;

                    }

                }

                catch (Exception ex)

                {

                    ex.Data.Add(“url”, newurl);

                    Exceptions.ExceptionRecord.ReportCritical(ex);

                    redirecting = false;

                }

            }

            return newurl;

        }

A great site for developing and testing regular expressions

Came across this one today and found it very handy for checking some complex regular expressions (regex) I was developing: http://www.gskinner.com/RegExr/

This alternative was recommended by a friendly recently:- http://www.ultrapico.com/Expresso.htm

A better Tail program for Windows

‘Tail’ is a program that monitors the end of a log file, keeping the view at the end of the file. In the past I’ve used MTail to monitor log files but recently I switched to Baretail because it does a better job at monitoring multiple log files at the same time.

Agile Software Development is Like Sailing

Agile software development is like sailing

Photo credit Patrick Doheny

Software development is a lot like sailing: unless you are sailing downwind you can’t get there directly and you have to tack; so you pick a tack and set off. You hold the tack for a ‘sprint’ and then you go ‘go about’ and head in a slightly different direction for another ‘sprint’ until you reach your destination. Just like sailing if you change direction too often you go nowhere (this is why agile insists no changes in direction during a sprint). Just like sailing, currents and wind can change during your trip causing you to adjust your tacking (sprints) to get there. Just like sailing, you can’t say exactly when you will arrive unless you know every single current and wind change that will happen during the trip.