Archive for the ‘code’ Category

Amazon CloudFront: Configuring a CDN in under 5 minutes

Tuesday, November 18th, 2008

I was very thrilled to hear about the public release of Amazon’s much awaited CDN service dubbed CloudFront. It took me 5 minutes to configure and start using it to serve static content off it (I used S3 for static content until now, so the transition was easy).

  1. Prepare an .aws-secrets file to store your AWS access identifiers and get the cfcurl.pl script (tutorial).
  2. Define a Distribution. Save this snippet in a file called create_request.xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2008-06-30/">
    ..<Origin>YourBucketNameHere.s3.amazonaws.com</Origin>
    ..<CallerReference>20080930090000</CallerReference>
    ..<CNAME>cdn.example.com</CNAME>
    ..<Enabled>true</Enabled>
    </DistributionConfig>
  3. Run the following command:
    ./cfcurl.pl --keyname <key name from .aws-secrets file> — -X POST -i -H “Content-Type:text/xml; charset=UTF-8″ –upload-file create_request.xml https://cloudfront.amazonaws.com/2008-06-30/distribution
  4. Save the response (especially the E-Tag) for later, you may need it to update the configuration.
  5. Create a CNAME entry in your DNS server using the DomainName in the response.
  6. Done!

I’m trying to think about an elegant way to manage versioning from now on (in PHP). I used to add a query-string version parameter to each resource to deal with client-side caching. With CloudFront, I need actual filenames to change, since Amazon’s servers ignore the query-string parameters when fetching the file from the S3 origin. Any ideas would be greatly appreciated!

Update: see comment below.

Cleaning Flickr Tags

Sunday, November 2nd, 2008

As part of an application I’m developing, I needed to store tags from multiple sources, and I chose to use Flickr’s method of storing raw and clean tags. I needed to figure out how Flickr converts raw tags to clean ones. This article by Terrell Russell helped a lot, but missed a few elements (and I needed it in Java).

The original regular expression by Russell did not include a comma, and I also found out certain special characters are substituted (I guess I will find more of them as I keep comparing Flickr tags).


public static String cleanRawTag(String raw, boolean isMachineTag)
{
    	if(isMachineTag)
    	{
    		// raw  = geo:lat=13.751193
    		// name = geo:lat=13751193
    		int equals = raw.indexOf('=');
    		return raw.substring(0, equals+1).toLowerCase() + cleanRawTag(raw.substring(equals+1), false);
    	}
    	else
    	{
    		String clean = raw.replaceAll("[s"!@#$%^&*():,-_+='/.;`<>[]?\]", "").toLowerCase();
    		return clean.replace('ß', 's').replace('ς', 'σ');
    	}
}

qYOUARE

Tuesday, June 10th, 2008

qYOUARE is a small thingy that lets you easily create QR Codes.

When scanned, each qYOUARE links to a specific page, where you can share some information and even have a discussion with whoever scanned the code.

qYOUAREs can be printed on stickers, t-shirts, mugs and can even be sprayed on walls. You can place them anywhere thinkable in the physical world - providing a cool and geeky bridge back to the online world.

http://qyouare.com/about/Creating the website was a learning experience for me, as I have never coded anything larger than a page or two for the Web. Since I always find it easier to develop after going over some sample code, I figured the best way to share my experience would be to make the entire source code behind the web site available for download.

In order to create a new qYOUARE, browse to http://qyouare.com/[your desired code] (I know, the GUI still sucks…)

Growing Pains

Tuesday, May 20th, 2008

First, Hello World.

My online nick has always been antichrist. It was set before they brought the internets to Israel, when all we had was teenage rage, quasi-satanic music and the A-List.antichrist fishbone cell

Over the years, I had a few mishaps surrounding this controversial choice I made, but most of the times I sticked with antichrist. I almost got banned from the Hebrew Wikipedia due to my offensive username (funny thing is, the English Wikipedia doesn’t really care) - so I had to ask the Hebrew Wikipedia god to change it to my favorite alternative, carnivore. Wikimedia supports changing usernames, and there was no problem setting up a redirect page from the old user page to the new.

Another incident occurred after sending a link to some marvelous photos on my Flickr page to coworkers in the USA on Christmas eve. All they had to say was how offended they were with receiving a satanic email on Jesus’s birthday. In later emails I used my Flickr ID instead of my Flickr URL when sending links to sissies.

About a week ago, though, Yaniv Golan told me I have to establish my Internet presence, and not as antichrist. He didn’t say that, but I felt he meant I need to grow up, in a way.

I thought about it, and decided to go with nivsin from now on, especially since it includes the word sin. So I didn’t entirely grow up.

One of my most important places on the Web is del.icio.us. I love del.icio.us. It’s one of the best inventions ever made in the online world. It’s a crowdsourced live catalog of the Web, sometimes even more effective than Google’s search engine. But it does not support changing usernames.

From the FAQ under “How do I change my username?

There’s no easy way to do this right now, but you can use the export and import features in your settings to change to a new account while preserving your current bookmarks. First, visit your settings (accessible from the top right of every page on del.icio.us) and select export (backup) from that page. Follow the directions to export your bookmarks. Then, register or log into your new account, go to settings, and select import (upload). After importing your bookmarks into your new account, you can log out of it and log back into your old account to delete that one. To do this, go to settings and choose delete account.

No easy way? But it’s possible, right? I wanted to change del.icio.us/antichrist to del.icio.us/nivsin. And I wanted it now. It was one of the most difficult and frustrating things I have ever did.

I exported my 5,914 bookmarks into an HTML file (the format IE and Firefox use to store exported bookmarks). And noticed the warning:

Note: If you choose the option to include your tags, they will be in your export even if you don’t see them on the page — you can view the source of the file to make sure your tags are there. Also note that if you have created tag bundles, they will not be preserved in your exported file. This is a limitation of the export file format.

I can re-create the bundles using copy-paste, and as long as my tags are preserved, no problem. Or so I thought. Social tags like for:username are imported as for_username. There is no automatic way to restore them to the original tag. And the worst thing of all:

Bookmarks you import will be kept private. We encourage you to share them after importing; that way, everyone can benefit.

I thought to myself, naïvely, well there’s a new del.icio.us firefox addon - it probably supports bulk operations, because I don’t want to leave all my bookmarks private. Hey, but I do want to keep my private bookmarks private… can I filter my private bookmarks? No. Del.icio.us has system: tags, for file types and more, which is great, but there are no Gmail like is:private tags.

I found a Greasemonkey userscript that enables sharing or deleting all bookmarks (on a page, up to 100 in bulk). So how hard could it be? Still naïve.

I have 60 pages of bookmarks. The plan was to go over them, find the private bookmarks, and tag them with a special tag. Then run the bulk share 60 times on the new account, and the bulk delete 60 times on the old account (I am too afraid to delete the old account completely…). Then go over the private bookmarks and unshare them. I also need to take care of re-adding all my friends to my new account’s network, recreate the tag bundles and manually rename all the for_username tags to for:username tags. A solid plan.

But wait, why is there a delay button on the bulker thingy? I found out soon enough. After doing something like 2 pages - all you get from del.icio.us is the dreaded Yahoo 999 error. Since I was doing it from home, I reset my ADSL modem every time it happened, to get a new IP address. It worked for a while, but it got really late and I had to go to sleep. I planned to continue running it from the office, with a longer delay - because we have a static IP address… but not long after, 999 again. For hours. No one from the office has access to del.icio.us, and they all blame me. me. At least it gives me some hacker hype credit whenever something like this happens.

Proxy? Worked. For about 3 more pages. Then a thought came to mind. How about I set up a web-proxy on Amazon EC2, and whenever I get banned, I’ll just terminate the instance and start a new one? Cool. 10 cents for a couple of pages… expensive, inefficient, but adventurous. There is an excellent article on how to start squid on EC2 here - it takes less than 2 minutes to start an instance running squid. You even use the default squid configuration, and I used PuTTY for tunneling the connection.

It would have been so much easier if they allowed me to change my username and just forward visitors to the new URL. Or if I continued not caring and kept my online offensive presence as-is…

EC2 Proxy Worked. For 7 more pages. Then any instance I started was already banned. I am currently sharing page 56/60, and have 44 more pages to delete. If you’re quick enough, you may try to grab my private bookmarks before I manage to re-unshare them. But I’m not worried, you’ll probably get temporarily banned by Yahoo! before you figure out which tag I used.

Lastly, I apologize to my del.icio.us contacts about all the for: links that might reappear…