Archive for February, 2013

22/02/2013

UK to MySQL Date in C#

A C# snippet that will allow a function to be written where a string is passed in, containing a date in the format dd/mm/yyyy, and have that replaced by yyyy-mm-dd:

// Matches 2 digits forward slash 2 digits forward slash 4 digits e.g. 22/02/2013
Match m = Regex.Match(input, "\\d{2}/\\d{2}/\\d{4}");
// could use @"\d{2}/\d{2}/\d{4}" instead of the double backslash escape
if (m.Index > 0)
{
    string dd = input.Substring(m.Index, 2);
    string mm = input.Substring(m.Index + 3, 2);
    string yyyy = input.Substring(m.Index + 6, 4);

    input = input.Replace(dd + "/" + mm + "/" + yyyy, yyyy + "-" + mm + "-" + dd);
}

Advertisements
20/02/2013

Displaying your latest Tweet in PHP – updated

Back in 2011 I posted a method for displaying your latest tweet in php. However times change, and the twitter API has been changed beyond all recognition. I have updated my script to interpret the JSON response from the latest iteration of the API:

$username = "cytedesign";
$feed = "https://api.twitter.com/1/statuses/user_timeline/" . $username . ".json?count=1&include_rts=1&callback=?";

function parse_feed($feed) {
$stepOne = explode('"text":"', $feed);
$stepTwo = explode('","source"', $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = htmlspecialchars_decode($tweet,ENT_QUOTES);
$tweet = str_replace("\/", "/", $tweet);
return $tweet;
}

$twitterFeed = file_get_contents($feed);
echo('"'.parse_feed($twitterFeed).'"');

I have been very busy with a brand new job that has been keeping me very busy, with more of a focus on developing desktop applications. I intend to start blogging a little again here as I get more comfortable with my new job.

Tags: , ,