Skip to content

Instantly share code, notes, and snippets.

@dsager
Created September 14, 2014 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsager/4b819b27ca751bfc8a59 to your computer and use it in GitHub Desktop.
Save dsager/4b819b27ca751bfc8a59 to your computer and use it in GitHub Desktop.
Small script to fetch a list of a user's Gists on GitHub
<?php
/**
* Small script to fetch a list of a user's Gists on GitHub
*
* Copyright (c) 2014 Daniel Sager
* License: MIT, https://gist.github.com/dsager/0edcbf806b5b86e78455#file-2014
*/
date_default_timezone_set('UTC');
$url = 'https://gist.github.com/dsager.atom';
$feed_content = file_get_contents($url);
$feed = new SimpleXMLElement($feed_content);
$links = array();
foreach ($feed->entry as $entry) {
$time = strtotime($entry->updated);
$links[] = array(
'id' => (string) $entry->id,
'title' => (string) $entry->title,
'url' => (string) $entry->link['href'],
'time' => $time,
'date' => date('F jS, Y', $time)
);
}
usort($links, function ($a, $b) { return $b['time'] > $a['time']; });
echo json_encode($links);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment