Muschamp Rd

Been Building Stuff with PHP

February 28th, 2013
PHP logo

Although it hasn’t helped me find a job, I’ve continued to build stuff with PHP. I’ve also been brushing up on my Objective-C. After upgrading to use Version 2 of the GData (YouTube) API I had to upgrade to Version 1.1 of the Twitter API. This took a lot more work especially trying to meet the display requirements. I’m not sure it is perfect, it is close and I’m still not a PHP guy. Once again I’ve decided to include the key code snippets in a blog post as no one uses them if I just check them into GitHub. Plus the code is probably more useful without all the overhead of every other API I use regularly.

Been using JavaScript too

I’ve also been trying to use Masonry on top of my CD Cover Gallery but I have some bugs to work out. I have an open question on StackOverflow but it is plain I need to brush up on my JavaScript a lot more. I’m also not a JavaScript guy. The best code I’ve probably written of late is for searching Twitter and then displaying the tweets. My solution uses CodeBird and follows the same basic techniques as others.

Searching Twitter and Displaying the Tweets with PHP & CSS

  1. Register an app with Twitter, you will need a pair of keys and two more keys that represent your access token.
  2. Download and create an instance of CodeBird in your code. Instructions are linked to above.
  3. Borrow two functions from the web: relativeTime() and linkify_tweet().
  4. You need to include widgets.js in your client code, Twitter provides this.
  5. I created two methods, one for searching and one for displaying the returned tweets correctly. I put them in Pastebin in addition to GitHub.

You also need a whole bunch of CSS rules to make it look pretty:

Of course Pastebin always seems a bit wonky or at least their default embed code. I think it doesn’t like being previewed by WordPress. I’ve also been trying to build another news aggregator/Internet dashboard. I’ve include a screenshot of it. I leverage SimplePie, Topsy, as well as iFrames and JavaScript widgets. I may end up using some of the PHP code above too.

My code almost meets the Twitter display requirements

My latest CD cover gallery is not quite functioning as intended

My WIP Internet Dashboard

Blocker iPhone Game Screenshot

If you love PHP or JavaScript or leaving comments you know what to do. I once again will have to upgrade all this PHP code, but my number one priority is finding a job, I’m even trying to leverage this albatross of a blog by improving old posts and pointing people in the direction of newer more relevant information.

3 Comments

  • Ross Wintle says:

    Well done for getting to grips with this. I’m amused by your comment (in the code) about return values in PHP. It’s true that you don’t have to return anything. You don’t even need to assign the value of a function to anything. After working with more formal languages (I used to do safety-critical software engineering using a safe sub-set of Ada) PHP seems more like an advanced templating system than a real language. It is growing up, but you can certainly code fast-and-loose should you want to.

    Well done and glad my code was some help.

    • Muskie says:

      When I was a professional software developer we were very rigourous. We used design by contract, unit tests, naming conventions, and design methodologies stringently. PHP seems to be cobbled together, it has no naming conventions as far as I can tell. It is a me too language. It seems to have started out being the Perl for the web/linux world but then it decided it wanted to be object oriented. I had little to do with it until WordPress came out.

      Most PHP developers don’t seem to actually know how things work, they seem to mainly Google and cut n’ paste. You can’t Google or cut n’ paste during an exam or a job interview. Kids have it so easy today, when I taught myself to program it was from a book. We didn’t have Google, or an IDE, or a debugger, I remember using computers before there was mice. Using a text editor without a mouse is a lost skill. I had to learn a lot of programming languages the hard way, over the weekend so I could do an assignment the next week. Now maybe I’m old and bitter.

      I probably was considering some sort of error condition or error message, but I never put anything in but the comment then I got it working and I was like, I guess I don’t need to bother even returning null. I generally write the documentation (and in the olden days the unit tests) before I write the code. I generally write out in comment form what I want/need to do. I then after I test that my code works, I go back and clean my comments up before putting them in the source repository but occasionally a comment will remain that I perhaps should have removed…

      I was just getting used to having an IDE and a debugger before I was forced to revise some old PHP. I’ve had to write way more PHP than I ever intended and it just hasn’t helped make my life better. It hasn’t helped my career, apparently I should have gone into iPhone programming or even stayed in Java rather than doing a Masters degree…

      Thanks for your help. I don’t mind giving back, I just wish people would document there code better before going on the Internet and saying how great it is and insisting that you should download it and use it, when really it full of problems and not only did you not test for them, they don’t know or care how to fix them, and if someone else fixes them and sends them the fixes they don’t even bother updating their blog/code/repository… There is a lot of that in PHP land, also a lot of “I don’t maintain that anymore”. If you’re not going to maintain it, take it down and get it out of Google instead of letting it be linked to by the corporation that owns the data and API as the recommended means to access their api using a given programming language.

      See old and bitter.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Posts on Muskblog © Andrew "Muskie" McKay.
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.