• Hi, I’m Patrick. I post experiments and articles of interest here. Sometimes I post on Twitter as @preynolds and more rarely on GitHub.

Node.js, and OAuth, and flickr! Oh, my!

About a month ago, I finished a small utility application that connects flickr to a twitter account. It allows users to update their twitter status with a shortened Flickr URL of a public image. I call it TwitFlick. It was my first attempt to build something useful in node.js.

In this post, I’m going to go into detail about some of the painful parts of the development, and offer up a few tips that might help someone who finds themselves in similar situations.

Continue reading

Hosting Private Git Repositories

It is easy to setup your own private Git hosting. I’ll provide you with a quick walkthrough so you can start hosting and backing up your repositories in minutes. This walkthrough only covers installation on Ubuntu 10.04 (Lucid), but as long as you have Git installed on the server, you should be able to follow along even if your flavor of Linux is different.

Continue reading

Expression Engine and Broken Links

Let me guess. You created a custom field in your template for a Link or URL, then you created an entry in that Channel and put a URL in your Link field. http://google.com for example. Then you noticed this on the rendered page.

<a href="&lt;a href=">http://google.com </a>"&gt;Link Text

“But I’ve already changed the Default Text Formatting for This Field to None! And I ticked the box for Update all existing channel entries with your new formatting choice. What Gives?”

Continue reading

Empty Safari cache without restarting Safari

Safari > Empty Cache… not working for you unless you close and reopen Safari? And Develop > Disable Caches not doing anything for you either? Here’s a handy hackaround.

Open Terminal and paste in the following command.

defaults write com.apple.Safari IncludeInternalDebugMenu 1

Restart Safari and Presto! You should now have a new Debug menu item. Under Debug > Show Caches Window, in the WebCore Cache section you should see a button titled Empty WebCore Cache. Use that to clear your cache instead of using the not-work-so-good Safari > Empty Cache… method.

Hardware Acceleration for Safari and iPhone

Once in a while when developing sites for iPhone and mobile Safari, I implement CSS3 animations, transforms and other rich content. Sometimes, I notice a screen flicker, or glitch in the rendering of my content. There is a quick and dirty workaround that should help alleviate these woes if you are in the same boat. What we are doing here is letting the GPU do some of the heavy lifting by putting the object in 3d space. Of course, you should probably test it on a range of devices first, and you should probably know that it uses more memory.

  -webkit-transform: translate3d(0,0,0);

There is a good write up over at webkit.org that talks about optimizing transitions. For example, you will get smoother transitions and animations if you transform position with the following.

Cross browser compatible, and slow.

$('element').tween('left', [0, -250]);

Chrome and Safari and fast.

-webkit-transform: translate(x,y);

toDecimal in JavaScript

Yesterday I was trying to format some numbers. More specifically, truncating decimals in JavaScript. Here’s an example of what I was trying to do.

RAW: 45.49654765
FORMATTED (to 2 decimals): 45.49
RAW: 45.49654765
FORMATTED (to 1 decimal): 45.4

I was using Math.round(bytes*100)/100 which was rounding up when my requirements specified no rounding. Since JavaScript lacks a built-in toDecimal method, I had to either roll my own or find an example of a function that did what I wanted. This is what I ended up with, with some help from here.

var truncDigits = function(inputNumber,digits){
  var fact = Math.pow(10,digits);
  return Math.floor(inputNumber*fact)/fact;
//returns 45.49
//returns 45.4