Hi, I'm Chris Moyer's Blog.

GitHub has an API -- Adding your Repos to Your Site

(This post is pretty old, found it in my tumblr drafts folder, but the code still works.)

So, I was showing Mike Canz my shiny new homepage, and what was his reaction? “How come the list of github projects doesn’t automatically update like twitter and the blog feed?” “I don’t know,” was my reply.

A bit of reading about the github API and a bit of hacking, and Voila!

<script type="text/javascript">
var nongithub_projects = [
	{ "name": "jThrottle",
	  "homepage": "http://inarow.net/static/jthrottle/",
	  "description": "Throttled jQuery.each() to prevent locking the browser on huge loops",
	  "fork": false

var projects_to_skip = {"cdm-s-kol-greasemonkeys": true };
function github(user) {
	var repos = user.repositories
		.sort(function (a, b) { return a.name.toLowerCase() &gt; b.name.toLowerCase(); });

	$('#projects .loading').replaceWith('<ul />');
	$ul = $('#projects ul:first');
	for (var i = 0; i &lt; repos.length; i++) {
		var rep = repos[i];
		if (rep['fork'] == 1 || projects_to_skip[rep.name]) continue;
		var url = rep['homepage'] || rep['url'];
		$ul.append('<li><a href="'+url+'">'+rep['name']+'</a>; - '+rep['description']+'</li>');
<script src="http://github.com/api/v2/json/repos/show/cdmoyer?callback=pageapp.github" type="text/javascript"></script>

I’m not going to claim that this code is beautiful, but it’s a fun snippet for a few minutes work.

Back to Blog Home »