Simple scripts always ship.

2009 July 1

Simple needs, simple deeds.

A need for a simple one-off occurred Monday evening at work. Some non-engineer coworkers needed to be shown how to make some non-Latin-1 text into html entities.

Basically, they needed a 5 line php script.

Right before sending them to any number of sites that already do this 5-line operation, I decide: what the hell, I’ll just make one of my own. And so, that night after unwinding, I did.

Here’s my HTML Entitizer. Suitable for all your HTML entitizing needs, large or small!

PHP in Escape from L.A.(jokesfornerds)

One of the reasons PHP is so popular is the fact that it’s got so many handy little functions. In this case, htmlentities() is the blade of PHP’s swiss army knife that we’re using. Of course, indiscriminate use of functions like this cause problems like double-escaped characters (&) showing up in databases.

PHP, the swiss-army knife.PHP’s solution to this sort of thing is generally to throw new corkscrews and toothpicks onto it’s ever-growing pile of tools on it’s knife. If you look at the documentation page for htmlentities(), you can see that as of version 5.2.3 of PHP, another optional parameter was added: double_encode. Which will

Getting the right escape order can be hard, especially for novices or small teams inheriting code from other small teams. To date I don’t think I’ve inherited work on a webapp whose database wasn’t littered with extraneous &’s and rogue \\’s. It’s only by virtue of verge-rpg.com having a single developer who is really, really annoyed by this problem the the point of neuroticism that & never appears in the database except in posts that actually wanted to display &.

Although even this level of OCD-database-cleansing didn’t prevent escaping-related errors on the first go-round.

Teh (sic) Implementation.

So, the only time-consuming part of getting this script into my wordpress site (other than me taking a bloody half hour to blog about a 2-minute job) was convincing wordpress that it should allow <?php fragments into my posts.

Luckily, other people before me have wanted this very thing. Wordpress’s biggest strength is again one of PHP’s: if you want it, it’s already been made for you. In this case the Exec-PHP module will let admin-level users of your blog post for-reals, actual PHP into your posts! You’d better hope your admins don’t have their accounts compromised! (…one moment. Changing my password.)

In PHP’s case, the code that you want that’ already been written for you is in every single function’s talkback thread. These functions may not be hyper-optimized or the best solution for any given problem, but they generally are what you want to prove a point. You scan the docs, you grab the code, you put it in your site, and you move on to the next problem in your own app.

Quick and dirty, the way PHP likes it.

For the curious, here’s the solution I spat out (copy included):

<h1>Escape html</h1>
<p>This is a simple script to give the escaped codes for some html. Useful
for making foreign languages play nice with html, regardless of how the
server handles string encoding.</p>
<?
if( isset($_POST['escape_me']) ) {
echo('<h2>Your escaped html</h2><div'.
     'style="background-color: #ddd; padding: 8px;">');
echo(str_replace('&','&amp;',htmlentities(stripslashes($_POST['escape_me']),
     ENT_NOQUOTES,'UTF-8')));
echo( '</div>' );
}
?>
<form action='/html-entitizer/' method='POST'>
Text to escape:
<textarea name='escape_me' style='width: 550px; height: 200px;'></textarea>
<input type='submit' value='Create my html entities'>
</form>

(weird formatting so it doesn’t run off the side of the screen; I don’t actually code like that. Mostly. ;)

Coda

It is of note that this tiny amount of effort got me two really sincere “thank yous” from the non-engineers. It’s important to note that things that are mindlessly trivial to a programmer can be tedious tasks to someone without the power to bully the computer into doing labor for them. One of the guys, a computer saavy guy who had access to lists of what each escaped character translated to, insisted that he’d just search/replace the offensive characters by hand.

Ostensibly, this was offered to save me work.

How much time did my 2 minutes of code save him?

(Don’t forget a google for “html entity converter” would’ve saved even that, had I cared to not make the tiny toy script of my own. I’ll ramble on about re-using other people’s work more later, but it’s key to remember even what little work I did end up doing was extraneous and largely an exercise in vanity.)

beta is the new gamma

2009 June 29
tags:
by mcgrue

Work continues apace on beta.verge-rpg.com.

Actually, it’s quite brisk now. Almost 60 revisions have passed in the last week.

Gayo and crew have banged on the forums, and I patched several oversights. Locally I’ve moved on to the new downloads section, which I’m looking forward greatly to finishing. Mainly so there can be an upload script that works for most users and gives progress feedback.

Are all webapps 98% mundane crap? I’ve been doing them for almost a decade now, and I think I have an answer.

(The answer is “yes”.)

Gruedorf: boards done.

2009 June 21
tags:
by mcgrue

Even though I’ve been lax in posting, I’ve been working (when I can) on finishing the beta.verge-rpg.com boards.

As of revision 237, the section is good to go for this run-through.  I’m going to now move on to the file section

Captain’s Blog: Frontier Psychiatry

2009 June 12
by Jonas

Mission Date: 0 years, 231 days

UN Mission Command has been alarmingly silent on the the events of last week. I suppose this is protocol, until they have a solution they don’t want to worry us. At least I imagine that was the thinking when whatever contingency plan they’re following was written, but in the meantime their procedural consideration for our psychological states is driving us insane. Best thing to do is ignore it, because up here our highest priority has to be figuring out why everyone on board is so miserable. It is ultimately our problem.

I’ve been meeting with Dr. Saratoga, ship’s head psychiatrist. She says the problem is that everyone on this ship is disgusting filthy racist, and a narcissistic egomaniac to boot.

Some background. When choosing from candidates to crew of the UNSS Ennui and be the future colonists, there were several important criteria: They had to be able, willing and ready to have children, be a distinguished and successful professional in a field useful to the colony, and have passed a thorough screening for mental illness. Some self selected characteristics (found in anyone who would volunteer to be a colonist) are a lack of close friends, family, spouses or children, and a degree of impulsiveness.

I think Group G needs to get over A

I think Group G should get over A

Maybe you’re getting the picture. The ship is full of self-absorbed workaholics whose biological clocks are becoming increasingly prominent parts of their personalities. They think the only reason they haven’t yet started happy families is because they haven’t met any equally “serious” people. What do you think happens when these people are confronted by thousands of other people exactly like themselves and confined in a ship with them?

The mirror is very unkind.

Our population is a rich tapestry of statistically enforced and algorithmically maximized genetic and cultural diversity, which leads to the second half of the problem. Have you ever done a calculation of how many single people of the opposite sex, who are roughly your age group, who you find attractive and would find you attractive, and not currently in relationships exist in the population of, say, your city? Well that’s your city, where the cultural gap between you and other people is somewhat limited by geography.

Dr. Saratoga has teamed up with statistician Dr. Minoh and computer modeler Dr. Hakeem to identify 200 unique cultural groups that are only willing to date within two or three other groups in any significant numbers, and over 500 smaller groups that absolutely refuse to date outside of their own group. The largest group, about 7% of the ship’s population, is the group who will only date in a cultural group other than their own. While this group has the shortest relationships on average, they also have the most and are (so far) the happiest. We’ll see how they do over time.

For everyone else, once all criteria has been factored in, for the average person the number of acceptable mates is fewer than three people.

I’m not even considering the possibility of sending these findings to UN Mission Command.

Captain Richards out.

Captain’s Blog: Blue Marble

2009 June 7
by Jonas

Mission Date: O years, 224 days

We’ve hit a milestone today! Due to complex nature of gravitation slingshots, we’re passing Earth for the second time today, more than half a year into our journey. Today’s flyby is much faster than the last. About half of the crew gathered in the observatory to watch it fly by over the course of about fifteen minutes or so. Truly a majestic sight, passing between the moon and earth. At these speeds you aren’t able to judge distances, the planet doesn’t feel any further away than a mountain on the highway. It’s the last time any of us will see the blue marble with our own eyes. Simply breathtaking.

Maybe I should get some introductory stuff out of the way. I’m the captain of a colony ship en route to Alpha Centauri, the UNSS Ennui. It should take roughly eighty years to get there, which makes this a generation ship. I, however, fully intend to still be alive when we arrive to bring humanity to the stars!

Aside from our last flyby, an odd thing happened today. About 15% of crew members called in sick, and another 10% simply didn’t show up for duty. Normally I’d be concerned about some sort of space-plague, but we have a sort of explanation: over the last two days, every last one of our escape pods has gone missing. When about half of them were gone, security was ordered to put the remaining pods under guard. Now all of the pods are missing, along with a disproportionately high number of security personnel.

Oddly enough, none of this would have happened if anyone had read the memos. Our velocity in relation to the Earth was very, very high. Far higher than the delta-v escape pod thrusters can achieve. This was all in a crew wide communique, which apparently nobody reads. Apparently nobody payed any attention in the mandatory orbital mechanics classes either. I think there may at least be a silver lining for the eventual human population of Alpha Centauri, in a Darwinian sense.

I need to decide what to tell the remaining crew members. Since this was our last Earth flyby, we don’t need to worry about this happening again. What we do need to worry about is keeping morale up. Which explanation for their disappearance would be worse for your personal morale, that a large number of your coworkers escaped successfully, or that all of the escapees certainly died and the beautiful meteor shower you witnessed this afternoon in the observatory was thanks to their sacrifice?

I think I’ll go with space-plague.

Captain Richards out.

Blogkeep

2009 June 1
tags:
by mcgrue

Hello fellow Bloodpact Bloggers!

This is just a maintenance post.  Ben Mathes asked me to remove him from the aggregator a while ago (so that he may journal more), and I just got around to doing it.

And in so doing, I got to wondering: does anyone else still really use this rss?

And after a smashing meal last night with several of the old ‘pact, I was also wondering in the complete opposite direction: does anyone want to go another round?  Either with the old grindmill once-a-day rules, or perhaps a more leisurely variant on the gruedorf rules?

Poetry Moment

2009 May 15
by mcgrue

A limerick’s structure’s sublime
its formula will, every time 
make you groan while you groan 
with a poem in your poem 
Because yo dawg we heard you like rhymes

(source: this guy)

Forever Forums.

2009 April 28
by mcgrue

I foolishly regret saying the end of my work on the beta.verge-rpg.com forums was, in fact, nigh.

I am getting close to done.  It’s just that the management of forums also requires work on the teams/games sections of the website that I was hoping to put off until later.

Here’s a list of things accomplished since my last post:

  • Added uservoice to the layout of beta (and production!) for feedback.
  • Generalized forum displaying.
  • Added forum url_key setting.
  • added /forum/find (so you can find forums you’re allowed to see, and add them to your main listing)
  • added breadcrumbs to the forums.
  • created functions to list all visible forums to the current user.
  • Added SEO stuff to the template.
  • Added nofollows to links that performed actions rather than showing pages.
  • Updated to YUI 2.7
  • fixed an annoying bug where a forum with no messages (ie, a newly created forum) wouldn’t render at all.
  • Created a service to look up usernames that was integrated with a YUI autocomplete widget.  This’ll mainly be of use moving forward with the team creation page.

Currently on revision 225 in the SVN repository.

The good news is that I have more time to work on this, as my train-based commutes now let me think and hack!

The bad news is I am like a week late with this Gruedorf post :(

Collected writings of disease

2009 April 24
by Jonas

A few things that’ve been percolating nicely in the drafts repository.


It hurts where I LIVE

You know you’re retarded sick when your eyes hurt. That’s right, retarded sick. I’ve been sleeping all day, my nose is stupid red, an entire roll of toilet paper is crumpled up into little wads next to my bed, and my body can’t make up its mind what temperature it wants to be. Right now I feel hot AND I’m sweating, a rare bit of consistency from an otherwise barely functioning wreck of a thing. Too high, you say? Well fuck you, body. You wanted it hot, and that’s what you’re going to get you son of a bitch.

I catches me off guard that I can’t talk. If you go a good 12 hours without speaking to anyone it suprises you when you try and find you can’t.

It occurs to me that this might seem like I’m begging for pity so let me explain how my life is still better than yours.

a smile and an erection

First off, location, location, location. I get to be sick as a dog in NYC. If there were a place in the world to not be able to enjoy, NY is the one you’d get the most non-enjoyment from. The awesome job I’m staying home from, and that isn’t paying me while I do, is also awesome.

The one time I left my house today I went to the grocery store and bought about $25 of canned soups. Why? Because my mommy isn’t going to make soup for me on account of being thousands of miles away. She doesn’t even have to know I’m sick. You know what freedom from parental nagging tastes like? It tastes like Progresso Vegetable Minestrone. High in saturated awesome.

So don’t cry for me Argentina. The truth is I wrote this months ago and I’m healthy as all fuck now. The cans of soup that once filled my cabinets are a distant memory, and instead of a painfully dried out mouth in the morning I wake up to a smile and an erection.
  read more…

A Whole New Paradox!

2009 April 23
by mcgrue

I’ve been watching a lot of Disney’s Aladdin this week for someone who’s pushing 30 and has no kids.  I rented the special edition and watched all of the comentary tracks.

Even though A Whole New World won the best song oscar for 1992, it’s not my favorite song by far from the movie (One Jump AheadPrince Ali, and the Prince Ali Reprise (the only time Jafar sings) are all clearly ahead).

The thing that always annoys me when the song comes up is in the following line:

Unbelievable sights
Indescribable feeling

…You just described the feeling as indescribable! This feeling wasn’t as indescribable as first advertised, was it, Jasmine?

I really do wonder if this would’ve annoyed me before I’d read Gödel, Escher, Bach, though.