Monolithic PHP
November 21, 2009I’m suffering from a temporary insanity that I may pursue: putting all the helper PHP I’m writing into a single monolithic PHP file: obremsdk.php. Crazy, right? Well, hear me out … and I mean me (talking to myself via blogging is another layer of psychopathy I’m sure).
I started the PHP for ObremSDK as I do with any framework in the past: separate files for discreet sections of modular logic. Theoretically that is the right way, but as time goes on I wonder if I use this more out of habit than anything else. Like my early obsessions with OOP, am I over-abstracting? Is a single file going to far? In general, I end up including everything because I need bits and pieces from everywhere. Modules can’t have too much high-level logic or they start becoming more tightly bound to each other.
For example, my latest “tiny” addition is to add some quick RSS/Atom parsing. I started a file called xmlfeed.php then rss.php and now I’m staring at xml.php where much of the common logic is ending up. Okay, so I put all the abstract XML stuff into that file, but then what’s left in rss.php? Now in order to use this code I need to include two files, and that’s just for the high-level part of the logic. For HTTP requests, I’ll need my http.php module and then there’s the file access stuff I built in fileio.php. Decisions for where things go and why start piling up as this thing slowly grows and I wonder why I’m taking the time to divide it as I go.
What if I start with one file and then divide it later if certain pieces become obviously separate from the common scenarios? I like to think of this as an evolution of sorts. I start with the body of code that I’m using and as things go into disuse they get pruned into separate legacy files. The maintenance there is updating old code to include those separate files, but then they’re probably stuck on a particular version of my code base anyway. There’s no reason why I can’t put a major version number into this big blob (obremsdk1.php) and then backport nasty bug fixes as needed (if ever).
It should be pointed out that I’m not trying to build up a gigantic framework like Zend for every situation. This is merely the code I’ve written that I like to share between projects. Well, I think I’m going to play with this idea some more.
From New Zealand
November 19, 2009It initially shocked me to get this oddly-wrapped envelope from New Zealand, since it contained no indication of who it was from. I have a friend named Ewan who’s a Kiwi — was it from him?
Actually, it was a couple of CD’s from Rudy Adrian whom we did an interview of on FanSiter a couple weeks back! He does atmospheric electronic music and it was a pleasure to kick back and listen to some of his most recent work, called “Distant Stars”. He also included a signed copy of Twilight.
I have been finding this genre to be very useful as a backdrop when I’m reading, playing video games, or writing code. It doesn’t demand my full attention, but instead tugs at the back of my mind.
Feed Me
November 14, 2009Wow! I am typing this into the “Visual” tab on WordPress in FireFox 3.5 and dang is it noticeably faster. To clarify, I installed Ubuntu 9.10 (Karmic Koala) on my EEE 901 and thus have gone from Firefox 3.0.X to 3.5.X. Browsing seemed snappier, but now I know it’s magnitudes better based on how this is performing. Previously I could practically watch the characters appearing, now they feel like they’re there before I finish hitting the keys. This is awesome!
I’m also trying AdBlock Plus instead of NoScript to see how well it fairs. NoScript is great, don’t get me wrong, but sometimes it takes me a moment to notice I’m missing something on a web page. Some sites require JS for form submissions and things and you won’t know until clicking a button does nothing. So I’m hoping ABP will use up less of my brain cells.
It’s the end of another week, this one kinda fell off the edge at contracting job. That is, I started to run out of things that needed doing and didn’t feel like wasting my time and their money by sitting in a cubicle sopping up their cash. Instead I mostly worked half-days and played Dragon Age or read The Gathering Storm in the evenings. No programming, but I have been adding posts to Bikini BOP here and there (always a fun activity).
What I’ve been meaning to do, as a smallish activity, is rip out the last of the PHP code I have that requires Zend Framework, specifically the Feed classes. In true perfectionist fashion my biggest stumbling block has been what to name the class and its file. Dumb, right? Well, I started with XmlFeed (xmlfeed.php) but that sounded too generic and you wouldn’t necessarily know what it does at a glance, so I’ve switched to Rss (rss.php). Too obvious? Oh well, I tried. It will read Atom feeds to an extent as well, but it will basically boil it down to the same components as RSS.
Another quirk, since I’m writing this for myself, I found myself designing all the property names (these will be array keys) as 4 characters. What’s that called? Not OCD, well not really. My mind was more of in a puzzle-solving and creative mood: how can I make these mostly apparent but keep them in 4 characters? It’s a little crazy too, I admit, but here’s what I came up with:
- name: <title> This one isn’t great, but it still makes sense.
- uuid: <guid> I could have gone with the latter, but other parts of my code (GData class) had already used UUID and I thought I’d keep it the same. In fact, I copied all these except “from” from their usage in my GData class.
- body: <description> Following a sort of “email message” motif, huh?
- date: <pubDate> I’m working exclusively with published dates so all others are ignored.
- href: <link> Specifically the HYPERTEXT reference (e.g. link to a web page). For Atom feeds this will find that HTML link which for my purposes is what I always want.
- tags: <category> Nothing much to say here except that I drop all the fluff around categories and just keep their names.
- from: <author> This is my favourite one! I didn’t want to use “auth” for fear it would be confused with “authorization” or “authentication” (as I commonly use that abbreviation). Since a name and/or email address goes in this field, it continues that email motif I mentioned earlier.
So as soon as I have the urge, I’ll be plopping this into ObremSDK and get FanSiter running on this netbook where I don’t have (and didn’t want to download) ZF.
CSS Insert Content
October 31, 2009On the FanSiter blog I wanted to take advantage of the footer area which, for WordPress and Google Sites alike, is completely off limits to hosted customers. Luckily for users, and probably a pain for admins, CSS3 allows us to generate and replace content.
A disclaimer before we begin: don’t abuse this for spammy purposes and don’t rely on it for indexing within search engines like Google (it probably isn’t and won’t be for a long time). This is another, purely-cosmetic modification to your pages. Which, for the purposes of SEO, is fantastic because you can also reduce redundant content from taking up space, showing up in search engines, etc. It is relatively easy to detect by service administrators and I have no doubt your banning is imminent if you try to use this to avoid their normal content filters / rules. WordPress, for example, already automatically removes HTML tags so you can’t use it for links, images, etc. — just text.
.footer_content:before {
content:"Created by Neil C. Obremski • ";
}
That’s all I had to add to my custom CSS in WordPress. What this says is: go inside any tag using the “footer_content” class and insert the content string at the beginning. Let’s see what that does …
It works pretty dang well and it shows up in Chrome (and therefore Safari I’m sure), IE8, and FireFox 3.5; e.g. the modern trifecta. I didn’t try in older browsers, but if it doesn’t show up then it’s not a big deal. I wanted to start with something rather mundane and actually I tried linking my name to my website which is when I found out that WP strips out HTML tags. It’s possible I could find someway around that, but I don’t want to break their trust (and TOS) and lose my blog.
And as noted in the caption, the CSS-generated content does not show up in FireBug, which can provide a bit of mystery to web developers when they’re trying to track down a bug. This made me think it might be a funny practical joke to play on a designer: use it to insert some rogue content and watch while they freak out trying to figure out where it’s coming from. In order to hide from file searching functionality, you could use Unicode escaping.
Silence PHP’s Magic Quotes
October 12, 2009Here’s a nifty snip of script you can prefix your PHP with to reverse the effects of the “magic” quotes. Thankfully, PHP 6 will no longer have these awful things, but in the meantime:
if (get_magic_quotes_gpc()) {
foreach ($_GET as $nm => &$s)
$s = stripslashes($s);
foreach ($_POST as $nm => &$s)
$s = stripslashes($s);
}
You may have seen the effects of magic quotes and not even known it. A script processing a form is giving you quotes where every apostrophe and/or double-quote character is preceded by a backslash. The original idea, and who knows how the language designers got it approved (no QA?), was to prevent newbie programmers from inadvertently creating SQL injection security holes. What it ended up doing was open up worse problems as noobs struggled to reverse the effects without quite knowing what they were doing.
Goodbye Zend, Hello cURL
September 29, 2009cURL you know it’s true … ooh, ooh, ooh, I love you.
Well, we’ll see at any rate. I spent a significant amount of hours today delving into both the Mechanical Turk API (REST) and cURL. Up to this point I’ve been relying on Zend_Http, but it’s been rocky. cURL seems to be a solid, long-running library that has been accessible to PHP since the first 4.x series. The former has a very clean, but limited API. The later is super arcane, but immensely more powerful. Again, that’s the theory!
Much of what cURL does is automagic in the best and worst possible ways. For example, to send POST parameters you can simply call:
curl_setopt($handle, CURLOPT_POSTFIELDS, array('name' => 'value'));
Fantastic! However, that also sets the content type to multipart/form-data automatically and you can’t change it. Likewise, if you did this:
curl_setopt($handle, CURLOPT_POSTFIELDS, 'name=value');
It’ll configure itself to send application/x-www-form-urlencoded. Yikes, what a weird way to choose.
That Darn Name
September 28, 2009An hour ago at Starbucks I happily tweeted my first experience with a FINE Sharpie Pen on my Moleskin. “Hmm,” I thought afterwards. “I wonder if loveatfirstwrite.com is taken?” It’s only somewhat clever but is also rather long for a domain name, so there was a good chance. Moments ago I navigated to that web site and it exists … sort of. It goes directly to a page selling the domain. Doh! Okay, so it’s only $97, I’m still interested so I dig further.
I immediately opened three tabs to Archive.org, DNscoop, and StatBrain. Existed back in 2007 for a book called “Love @ First . Write”, has a PR1, and a couple dozen visitors a day. That’s not terrible, but I’m in no rush so I checked the WHOIS to see when it would expire …
Domain Name: LOVEATFIRSTWRITE.COM
Registrar: THAT DARN NAME, INC.
Whois Server: whois.intrustdomains.com
Referral URL: http://www.intrustdomains.com
Name Server: NS1.INTRUSTDOMAINS.NET
Name Server: NS2.INTRUSTDOMAINS.NET
Status: ok
Updated Date: 28-sep-2009
Creation Date: 28-sep-2009
Expiration Date: 28-sep-2010>>> Last update of whois database: Mon, 28 Sep 2009 22:35:51 UTC <<<
Wha-wha-what? It’s a bit fishy. Either there’s a massive coincidence here, entirely possibly, or that registrar is using Twitter as a domain tasting source. Yes, it all sounds very conspiracy theory, but imagine they come up with domain names and then only purchase them if they already once existed and have backlinks. My tweet would have been perfect to generate this name. Darn them!

Posted by Neil Obremski
Posted by Neil Obremski 

Posted by Neil Obremski 




