Tag Archives: php

Justin Kan’s first programming experience

May 22nd, 2012

Justin Kan about his first experience using programming on the job:

A couple more hours of applied effort and I had a macro that looped through all the images in a directory tree and laid them out in Excel. I spent the next four days surfing the web and handing out files.

The first time I did any programming it was more than likely a “Hello World” script in ASP. However, I do remember doing something very similar to what Kan did to automate a process which a fellow employee spent hours a day doing.

I worked for a brokerage and each and every day a fellow employee had to take about 100 stock ticker symbols and run reports on them and input that data into an Excel spreadsheet. This was circa 2000. This went on for nearly a year before I caught wind of what they were doing. On a break or at lunch I was talking to this person and they explained to me what they did nearly every morning for two hours. I was astounded.

When I got back to my desk I fired up my code editor (EditPlus I believe) and in about an hour I had built a very simple PHP script to pull the relevant information for all 100 stock tickers using Yahoo! Finance’s CSV creator. Then a simple Excel macro formatted the data the way that this person had been doing. In all it took the script and macro about 45 seconds to run and create an email with the new data as an attachment.

It wasn’t long after I shared this workflow with my boss that the person that had been doing that job needed to figure out something else to do or they’d probably be of little use to the company. Whoops. Not my intention.

Another co-worker and friend at the time bought me a sticker from Thinkgeek and stuck it to the side of my computer. It read “Go away or I’ll replace you with a very small Shell script.” (Now available in T-shirt form.)

There has been a lot of hoopla lately about the fact that people believe that everyone should learn to code. Some are taking that quite literally to mean that everyone should learn how to build applications or websites. I don’t take it that way. I think everyone should learn the “languages” that their applications speak so that they too can take advantage of working smarter rather than harder. If you are tasked with using Excel all day become the very best at it you can be. And that means being able to program macros. If you are asked to use multiple applications on a Mac learn how to use Services or Automator to do some of your reoccurring tasks for you.

This type of programming won’t put you out of the job. It will free you up to get more work done. To use your time to do other things rather than the same thing every single day. If you do the same task more than once a week you should seriously consider learning how to automate it.

PHP is like scrapple

April 12th, 2012

Paul Ford, of NYMag, about Facebook:

The company is also technologically weird. For example, much of the code that runs the site is written in a horrible computer language called PHP, which stands for nothing you care about. Millions of websites are built with PHP, because it works and it’s cheap to run, but PHP is a programming language like scrapple is a meat. Imagine eating two pounds of scrapple every day for the rest of your life — that’s what Facebook does, programming-wise. Which is just to say that Facebook has its own way of doing things that looks very suspect from the outside world — but man, does it work.

I use PHP. Which makes sense because man do I love scrapple.

RSS to Twitter using PHP

December 6th, 2009

Update January 19, 2010: This script is now available on GitHub. Go forth and fork.

Today I noticed that my now ancient PHP script to update Twitter automatically using PHP/cron needed to be updated. It turns out that Twitter stopped recognizing URLs with ? in them as clickable links. Here is an example tweet where you’ll notice this happening.

I could have told Twitter and asked that they update the way they handle URLs but in reality my script was old, slow, too long, and shouldn’t include ? anyway so I figured I’d write a new one from scratch that included my short URL scheme.

So, here is the PHP script to parse an RSS feed and send the posts to Twitter. It includes a caching mechanism so that you won’t have duplicate URLs posted to Twitter. If you want it, take it. However, if you are better than I am at PHP (most 6yr. olds are better than I am at programming) then I ask that you fork the script on Gist and try to improve it.

Update Dec. 6 @ 5:34p: Kyle Slattery, follow Viddler team member, loves him some Ruby on Rails. As such he’s offered up this version of the script rewritten in Ruby.

Next up we have Anthony Sterling, self-proclaimed “PHP addict”, who has rewritten the script to make the configuration a bit easier. He also changed the way the cache is saved. He’s using a hashed version of the title for each post as his key. I do not believe this to be the best way to go, since post titles can easily change after publishing – but I do like that the script is about 20 lines shorter and the code is arguably cleaner.

Thanks to both Kyle and Anthony for their versions. Lets keep this going and see if we can get this script much more succinct, stable, faster, and usable by others?

How to: Use the Viddler API with CodeIgniter

August 4th, 2009

Me, on The Viddler Developers Blog:

“The Viddler team is using CodeIgniter more and more for our internal PHP projects. Obviously we need to use CodeIgniter with the Viddler API quite a bit so we figured we’d share with you how easy it is to include PHPViddler, the open source PHP API wrapper class for the Viddler API, in your CodeIgniter application.”

Read more in the blog post titled How to: Use the Viddler API with CodeIgniter.

Add a progress bar to your Viddler uploads

June 18th, 2009

We get this question a lot at Viddler: How can I add a progress bar to my uploads using the Viddler API? We’re always asked if this is something included in our API wrappers. Until now, it hasn’t been. That’s where phpViddlerUploadify comes in. This extension to phpViddler, our PHP wrapper for our API, makes it pretty easy to use the open source JavaScript library jQuery and the extension Uploadify to add progress indicators to your Viddler uploads.

Go forth, and hack! Oh, and its completely open source too. (More on this later.)

Recording live video on the iPhone with Qik and Viddler

November 21st, 2008

Sometimes I just can’t help myself. I’m a hacker. Not the type of hacker that wants to break into a bank’s records and steal your personal information or anything – the type of hacker that just likes to make up fun solutions to interesting problems.

Viddler’s current lack of any way to record video on a mobile phone, for instance. More specifically the iPhone. I take a lot of mobile photos (more here) on my iPhone. I’ve wanted to shoot videos on my iPhone too. Now I can.

The first step I had to take was to jailbreak my iPhone. Qik’s iPhone application, while not perfect, allows me to shoot video on my iPhone and have it be recorded, live, on Qik’s servers. In fact, if the connection is good enough you can watch me recording the video only a few seconds delayed.

Viddler bagels! Recorded with iPhone.

But I wanted my video on Viddler. It is my player of choice. Qik’s player is great, especially since it allows you to watch the video as it is being recorded. It also has some interesting interactive features like chat. But, like MTV – I want my Viddler.

So my second step was to build a bridge from Qik to the Viddler. Once the live session has been saved as an FLV Qik creates an RSS feed with a link to the video file. I’ve built a dead simple PHP script that reads that RSS feed, downloads the FLVs, and then transfers them to Viddler. I then took the liberty of creating a quick bit of code that then Twitters the link to the video on Viddler. I do this for my mobile photos posted to Flickr so I thought why not do that for mobile videos as well.

After talking with Qik about this bridge we’ve both decided to do something a little bit better than what I have hacked together using nothing more than what I had access to. So stay tuned.  Until then, you may have my script that I wrote in an hour to play with.