Top

Why I’m Developing for iPad

June 6, 2010

ipad_story.jpgI have been pretty vocal in the past about my issues with the app store, Apple, Apple’s development tools, the app market, and so on.  Leading up to the release of the iPad, I goofed on it with everyone else, and scoffed at the idea of developing anything for it.   And yet, here I am, developing apps for it.

Read more

Shortening URLs on the fly in PHP

May 1, 2009

For a project I’m currently working on, I wanted to parse input strings looking for URLs and convert them to shortened URLs.  The best service to do this in is CR.AM, which is like competing URL shortening services but with some extra features like phishing/spam protection, Twitter integration, and more.  If you are doing anything involving Twitter, I highly recommend using cr.am for your URL shortening, as they’ve got some really neat things on the horizon involving Twitter.

More importantly, though, getting it set up was easy.  There are two functions: one tokenizes the string to search the string for URLs (in my case, I’m looking for a string that begins with http:// or www. but your needs may vary). Many people would use regular expressions here, I didn’t.   My strings are short and easy to parse this way. This post isn’t about how to find URLs in a string, it’s about how to shrink them.

The second function calls up cr.am and requests a hash for the URL.  To convert URLs in a string to cr.am URLs, you just pass the string to cramify() and use the output.

  1. function cram ($url) {
  2.     $cramHash = @file_get_contents(‘http://api.cr.am/create/’ . $url);
  3.  
  4.     list($httpVersion, $statusCode, $message) = explode(‘ ‘,$http_response_header[0], 3);
  5.  
  6.     if ($statusCode == 200) {
  7.         return "http://cr.am/".$cramHash;
  8.     } else {
  9.         return "";
  10.     }
  11. }
  12.  
  13. function cramify ($string) {
  14.     $tokens = explode(" ",$string);
  15.  
  16.     foreach ($tokens AS $t) {
  17.         if (substr($t,0,7) == "http://") {
  18.             $string = str_replace($t, cram($t), $string);
  19.         } else if (substr($t,0,4) == "www." && substr($t,4,1) != " ") {
  20.             $string = str_replace($t, cram("http://".$t), $string);
  21.         }
  22.     }
  23.  
  24.     return $string;
  25. }

Making an iPhone game using only Interface Builder

April 14, 2009

clownce_link_image.jpgCan you make an iPhone game using only the interface builder and no additional libraries? Yes, and I’ll show you how. Read more

Fixing .NET Installers

August 28, 2008

Another ridiculous failure on the part of Microsoft to understand how small developers need their tools to work.

You’ve finished your .NET project and are ready to distribute. Visual Studio has spit out two files for you: a setup.exe which makes sure the user has the requirements (the targetted version of .NET, as well as Windows Installer), and a .msi file containing your product.

So what happens if your user doesn’t have .NET?  Well, setup.exe fetches it, and installs it (in a process that can take an are-you-freaking-serious 20 minutes) and then, more likely than not, reboots.

This is not a big deal if you don’t mind making your users download either both of these files, or a zip file containing the two.  But if you want to make the install process as easy as possible, you would like to have a single installer that handles all of that.  But Visual Studio, for some unknown reason, doesn’t handle this very basic requirement.

What we need is something that does the following: unpack setup.exe and YourApp.msi to a temp directory and launch setup.  But what happens after the reboot?  It is crucial that both files still exist, or you’re doomed.  Installation will fail.

There are a couple options people might suggest –  iexpress is one of them.  Skip it.  iexpress isn’t going to work here.  For whatever reason, iexpress creates an installer that deletes its temp directory as soon as setup.exe is launched.  Consequently, YourApp.msi is missing when setup.exe launches it.  Not persistent enough.

I found other, free programs that almost do what we need.  I won’t name them here, because they don’t work.  The best of the bunch deletes the temp directory on the next reboot, but that doesn’t work because the .NET installation requires a reboot before your app is installed.  Again, this results in a missing .msi and a failed install.

So here’s the solution: download NSIS.   This is the Nullsoft installer you may have used in the past.   We need to build a simple script, stick it in the same directory as setup.exe and our .msi file, and compile it.  The output will be a new .exe which unpacks our two files to a temp directory, launches setup.exe, and keeps all of our files around as long as we need them.

Here’s the script:

  1. # define the name of the installer
  2. outfile "MyApp_Setup.exe"
  3. SilentInstall silent
  4.  
  5. # define the directory to install to, the desktop in this case as specified  
  6. # by the predefined $TEMP variable
  7. installDir $TEMP\MyApp
  8.  
  9. # default section
  10. section
  11.  
  12. # define the output path for this file
  13. setOutPath $INSTDIR
  14.  
  15. # define what to install and place it in the output path
  16. file setup.exe
  17. file "MyApp Setup.msi"
  18.  
  19. Exec "$INSTDIR\setup.exe"
  20. sectionEnd

PHP Scripting in Win32 Apps

March 22, 2008

This is a repost of something I put together a couple years ago, and as such it may be out of date. There are much better ways to add scripting support to your apps these days, but if you are dead-set on using PHP, this may help you do it.

In order to use the cli version of php for scripting in your win32 app, you’ll need to connect your app to PHP, send it PHP code, and read the processed output. Read more

C++/Win32: Context Menus

March 2, 2008

Context menus are the little popup menus that appear when you right-click on certain areas in an application. They’re called context menus because the menu and/or menu options you see depend on the context. If you right-click in an edit box, for example, you might get options to cut, paste, copy, clear, etc. If you right-click on a list view, in the same application, you might be presented with options to sort the list. Read more

C++/Win32: Sounds

March 2, 2008

This might be the shortest lesson of all. All I want to do here is play a sound. Why? Well in the cast of a port scanner, the user is probably looking for open ports on a system. The majority of the ports scanned will be closed, and he/she might be looking over 8000 ports for the few that will be open. The user might better occupy his time doing something, anything, besides staring at our application. So a sound alert might be a nice option. Read more

C++/Win32: List Views

March 2, 2008

At this point, we’ve done a lot. Over the past sixteen lessons, we’ve made our app do what it’s supposed to do, and just recently we made it print and save its output. For some strange reason, we’re still not completely bored and over this thing, so we’re trying to figure out how to make it better. Read more

C++/Win32: Working With Files

March 2, 2008

If you’ve made it this far, you’ve been introduced to some pretty hectic stuff. The nice thing about that is that by comparison, working with files is going to seem ridiculously easy. And part of that is because Microsoft has done a lot of the hard work for you. And why shouldn’t they? Almost every program you use works with files in one way or another. Read more

C++/Win32: The System Tray and Balloon Tips

March 2, 2008

Good news! We are going to again break away from the standard Win32 stuff and explore something fun. Actually, two fun things: minimizing to the system tray, and creating balloon tips. Balloons are those little comic book style dialog bubbles that popup in the lower right of the screen telling you information you don’t necessarily need to react to (”There are updates ready to be installed,” “New Hardware Found,” “The program is still running in the system tray,” etc.) Read more

Next Page »

Bottom