Free SNES Sprites? Yes Please.

Posted on 29th March 2011 in Something Daily

I discovered a site called nes-snes sprites a few days ago that has a huge collection of (you guessed it) NES and SNES sprites, often in all of their animation states, available for download. Right now it’s just great for nostalgia value for me, but I’m thinking about making some gifs with them, or maybe putting one on the header of my site. The site also has a decent collection of soundtracks from those two systems, which I’m almost inclined to put on my iPod and listed to for fun. I have a serious thing about chip music.

Posting daily starts to become difficult around the middle of the semester, for one reason or another. Sometimes it’s the increasing workload from classes, but it’s always the “stuff is happening” mindset that starts to kick in soon after midterms. Even if it’s not incredibly busy, there’s this feeling of having places to be and stuff to do. At least there is for me. Of course, I feel like I always have some project or another, and the more enthusiastic I get about whatever it happens to be, the less time I find myself having to do almost anything else. But that’s just me. Also, my living space is quite often much louder than it needs to be, mainly due to myself and my roommates all being close to 20 years old, fans of music, and owning big speakers. This sometimes makes it hard to concentrate on anything, which is a big reason that I’ve been spending more time in the courant library recently.

Speaking of my website, the design/development process is going well. The method I had been using to retrieve a Twitter feed via the Twitter API wasn’t working under Ubuntu, so I figured I’d at least attempt to make that better. As it turns out, I’m able to use a very similar method to the one described yesterday to get the tweet data from an RSS feed. Also, I’ve added some cool-looking stylistic elements to the homepage design, and given the header (my name) the Double Dragon treatment, which I was able to do with a font I found here and a bit of Gimping.

Also, my roommate gave me his GameBoy Pocket today! The stars have aligned in my favor! I was just starting to think about buying one, and then this happens. Seriously, that is awesome. I also picked up Street Fighter II Turbo yesterday, which is of course much harder than I remember it being. Ryu is quite annoying with the Haduoken.

PHP Howto: scrape an RSS feed

Posted on 29th March 2011 in Tutorials

Since I’m building my own homepage, I recently learned how to scrape an RSS feed in order to dynamically create content for a website. The idea is that I would have separate feeds from my twitter, tumblr, and this blog all in one place. The tumblr and twitter feeds are offered by those companies in the form of API calls, so using those two is very straightforward in both cases. When self-hosting a wordpress blog, though, as I do, there is no readymade option for a feed that one can just call and have ready to go. So I had to make my own.

An RSS feed is essentially just an XML markup document that browsers interpret and show you in some type of feed form. What I wanted to do with this document (which wordpress produces for me) is essentially the same as what the browser does with it when you click an RSS link – it parses the tags in the XML document and applies predefined visual styles to make the information accessible to humans.

PHP can perform this process quite simply, via the simplexml_load_file function, which provides a simple framework for parsing XML documents.


$feedUrl = 'http://emmettbutler.com/threestegosaurusmoon/?feed=rss2';
$ret = array();

// retrieve search results
if($xml = simplexml_load_file($feedUrl)) { //load xml file using simplexml
$result["item"] = $xml->xpath("/rss/channel/item"); //divide feed into array elements

foreach($result as $key => $attribute) {
$i=0;
foreach($attribute as $element) {
if($i < 3){
$ret[$i]['title'] = (string)$element->title; //assign the desired elements to array entries
$ret[$i]['timestamp'] = (string)$element->pubDate;
$ret[$i]['summary'] = (string)$element->description;
$ret[$i]['link'] = (string)$element->guid;
$i++;
}
}
}
}

After the initial call, this code examines each unit of the divided document and assigns the contents of certain tags to elements of the $ret array. For example, there is a line in each item of the feed that is denoted by the pubDate tag, which contains the date that a certain post was published. The line $ret[$i]['timestamp'] = (string)$element->pubDate; finds those tags and assigns their contents to the $ret array. Once this loop is complete, you’ll have an array full of all the pertinent data for your feed. You can loop through the array and print each element between the appropriate tags, style with a bit of CSS, and you have yourself a homemade and very professional-looking RSS feed widget on your website.

comments: 0 » tags: , , , , , , , ,