Announcing Open Source MTG API

Announcing Open Source MTG API

Hey, this weekend I built an API and DB solution for Magic: The Gathering cards. It’s now open source on github (where you can read the documentation), and you can use it by sending a query string like this:

http://stegriff.co.uk/host/magic?name=Doorkeeper

OK, have a great day!

Advertisements

PHP Conditional Markup

It can be hard to find the right result when you search for “PHP conditional markup”, so I’m helping myself (and maybe others) by posting this up here!

You can make document content conditional by enclosing it in a regular PHP if{}

<?php if ( $errorMsg ){  ?>
<div id="message">
<?php echo $errorMsg; ?>
</div>
<?php } ?>

But, for the sake of readability, the alternative syntax is often used, where the opening brace changes to a colon (:) and the closing brace changes to the keyword ‘endif;’

<?php if ( $errorMsg ):  ?>
<div id="message">
<?php echo $errorMsg; ?>
</div>
<?php endif; ?>

For more information, see the PHP documentation for Alternative syntax for control structures.

Hope that’s helpful! :)

Slabs dot TV

Slabs.tv logo

Slabs.tv logo: The square is a slab, and it's tilted because we're tilted.

My friend Ben and I had been musing on making a comedy site for a while; videos are to Ben what code and… sonnets… are to myself. So, naturally, I was conscripted into hours of unpaid web design and admin duties, and we have emerged — I, scalded from working over a hot DNS — with Slabs.tv.

I could probably do a whole post on the branding and the tribulations of trying to procure an occupied dot-com domain, and that is outside the scope of this discussion. So, take a look at the website; it is herein appraised!:

Site design and accessibility

The first thing you notice if you’re a design-y sort of person is League Gothic. Try and escape this typeface. You cannot! It is not possible to evade the clutches of it and its bold, tall, gothic brethren, unless you entirely sequester yourself from the graphical web. If you highlight the text of the logo, imagining for a second that it is not an image, you will notice that it works! This is a trick I learned from Erica Greco’s website, and it aids accessibility for people with screen readers or text-based browsers like eLinks.

Blue is the easiest colour for which to design. Well known fact, that. I set it off against a sandy background and used a Photoshop tutorial on torn-paper edges to get the horizon at the top and the tabs. Ben said from day one that we should have a torn paper design, and I agreed. Rightly? You decide!

The site is much tidier than I had planned, quite sober, but I don’t think it loses out for that reason. An advantage is that if you zoom your browser in or out 5 steps (CTRL + Mouse scroll wheel, then CTRL + zero to return to normal) all of the content panels stay in proportion, so the site shows well on very big – or very small – displays. This is key to web design.

Financial and technical

As for the hosting, the whole shebang is on the same server as SteGriff.co.uk (which you might have used to get here today), and Ben pays 40% of my hosting costs. This is “reselling”, and does not contravene my host’s term and conditions (which is strange, I thought, but I’m not complaining). The Slabs.tv domain would cost £30/year from my host, so I got it from a different provider (123-reg.co.uk) for £10/year and messed with the nameservers until it pointed in the right direction.

Conclusion

Things like this are what I do. I am nowhere near pro at web design, but I have experience and problem solving skill. If you want to pay me to make you a website, that would be great! I design sites with accessibility and low-download size in mind, without compromising aesthetics (I hope).

Here are some other sites which I want to talk about in the near future:

Le Game – IP Shortening

Cloud Tools

In closing, I make no apology for the length of time between blog posts. You do however, get this nice lampshade.

BASS

Scenario: My friend Ben and I need to exchange links to web resources on a regular basis.

Problem: I do not have Facebook. Ben does not have Twitter. Ben does not use email. Lastly, Ben does not have a rich-web capable phone with which to receive links via SMS. As you can see, this is mostly his fault.

Solution: Ben And Ste’s Social, or BASS.

While it now has 3 users — and should more accurately be called BLASS — my latest PHP experiment remains a minimalist text-and-links sharing site. It has hardcoded user data, meaning you only need to enter a password in order to post. That is obviously ‘fail’ in several ways, but it is also super secure. It has its problems, but at the moment it does the job perfectly under the load expected.

I learnt to use flock() instead of the time consuming process of restoring from backups, and a major revision is underway which will queue and batch-manage messages rather than allowing each client to modify the master log.

The tagline, and even the name of the service (“Bass”) can be changed by any of the priveleged users in their Config options at any time, which adds fun. Messages stack in a way which I am beginning to realise is what is generally acknowledged as “backwards”. I will fix that.

Bass will also have support for an embedded HTML document for each user which gives them tabbed access to their favourite websites search facilities. It automagically recognises links, even those which lack protocol prefix.

BASS is private and has no signup system.

OK. Good. I’m glad we had this chat.

More PHP Fun

2 PHP-solvable problems presented themselves to me this week, both, as it happens, on Minecraft Forums. I imagine that just happens to correlate to the amount of time I spend there.

In the first case, I wanted to be pretentious about making a tally chart. This was because in just ONE topic (albeit a very controversial one) it had been necessary for the mods to ban a total of 6 people. That needed tallying. There was a sense of urgency to getting my post out, and as such I ended up just making an ASCII rendition. The problem remained, and eventually, tally chart generator happened.

I want to make very, very simple web apps which take minimal input (not a whole form) and give minimum output (not a glossy translucent .png) because I think that kind of thing is cool. The novelty of this sort of programming hasn’t worn off.

As such, the next thing to emerge was an image resizer. Despite the wealth of code snippets out there to do this, I decided to write from scratch using the PHP docs. The problem came around when, in a Pixel Art thread, a contributor excused his tiny image because the ImageShack variety had failed him. It works with all .pngs but I plan adding non-animated .gif support.

The image resizer doesn’t have a nice introduction text like the tally, but is documented in the thread to which I linked above.

~

That is all of my PHP productivity for this week.

Pokémon Synchronisation Server

Recently, I have gotten my sister all mixed up in that darkly addictive universe that the kids call “Pokeemans”, coincidentally a topic which I blog about alarmingly frequently. She is 29.

Now, we are playing Pokémon FireRed and LeafGreen version at the same time and (hopefully) speed, allowing us to battle and trade at regular intervals. To co-ordinate this effort, I took it upon myself to put my fingers to keys and write some PHP.

Pokémon Synchronisation Server represents the sum of my efforts at this. It is specialised to us, but is still a landmark as the most complex thing I have achieved with PHP. Since the game will be over in the far future, and the page gone or transformed, here are some pictures of how it stands as I look at it today. Click an image to enlarge it.

The publicly viewable index page:

The edit page, after having entered the password:

It’s quite limited in some ways, and the interface is sloppy; I’ll admit to that. I would have liked to have an [Evolve] button and such, but this way was reasonably simple, does the job, and took me the shorter half of an evening. As such, I’m very happy with it.

Ste