How to add an EU Cookie Consent popup to your web site

Cookie Consent / IdiocyCookie Consent laws: you have surely seen them.

You go to a site, and you get a popup or bar at the top of the site that says, “We use cookies, blah blah blah…”

There is usually a “Learn more” link, and sometimes a way to accept or reject that site’s use of cookies.

The reason for this is a very stupid law implemented in the European Union that is supposed to protect people from… well, actually, it doesn’t protect anyone from anything. Okay, technically, it protects you from your sanity.

Especially if you use Google Adsense to put ads on your web site, you probably have received an e-mail from them telling you that you must have a Cookie Consent thingie on your site by the end of September 2015 in order to comply with yet another EU cookie law.

Right, so, how do you add cookie consent to your site – quickly and easily?

Read more…

Understanding Embed Codes

Embed CodesYou have probably encountered embed codes before, but they may seem like a bit of a mystery.

An embed code is, in short, a bit of HTML that allows you to embed part of another web site on your own – like a YouTube video, for example.

Embed codes come in two general flavors these days, and each has its strengths and weaknesses.

So, how do embed codes work? Why are some hugemongous, and others teeny-tiny? Are iframe tags really the spawn of the devil?

Read on!

Read more…

I shared a link on Facebook, but no image shows up

Sharing an Image on FacebookAh, yes. Facebook and images!

You know the drill: You share a link, and you expect that an image from the page you shared will show up.

But, it doesn’t.

This is especially true if you’re sharing a link from a lesser-known site, like perhaps your own blog or online store.

Fortunately, there are a few tricks you can use to make Facebook – and other social networking sites – happy.

Read more…

JavaScript Fun: Looping with a Delay

JavaScript is Awesome!If you’ve ever programmed something in JavaScript, you most likely ran into a situation where you needed a delay.

Normally, we do this with setTimeout().

For repeatedly calling some function every X milliseconds, one would normally use setInterval().

Well, that’s fine. But what if you want to so something 10 times, and delay 3 seconds between iterations?

The solution is not as obvious as it appears…

But it is simple!

Read more…

Varnish: Remove all Cookies EXCEPT the ones you want


So, you’ve got a web server. It’s slow.

So, you optimize your app, and implement some caching. It’s faster, but not fast enough.

So, you decide to use Varnish, the popular reverse-proxy web application accelerator. It doesn’t work.

The reason it doesn’t work is that on your web site, you’ve got all kinds of Javascript-based goodies, like Google Analytics, or maybe embedded videos that set tracking cookies, or maybe things like AddThis that also set client-side cookies.

Well, client-side cookies are for the JS on your site; your application doesn’t actually care about them. BUT – and this is an annoying “but” – if those client-side cookies are set for “”, then with every single request a reader makes to your server, those cookies are sent along.

And that means Varnish won’t cache anything, because it says, “Cookies?! EEK! No caching!”

So, how do you make Varnish happy with only the cookies that you want to keep?

Read on…

Read more…

How to Program Smarter Without Staying Up Until 4:00am

I just read an interesting article at entitled Why Programmers Work at Night.

The article explains why programmers generally tend to prefer working in the wee hours of the morning.

Programming requires keeping a lot stuffed in your brain at once, and thinking about all of it all at once. This task can often be a tad difficult under normal work/life circumstances.

In short:

This is why programmers are so annoyed when you distract them.

Because of this huge mental investment, we simply can’t start working until we can expect a couple of hours without being distracted. It’s just not worth constructing the whole model in your head and then having it torn down half an hour later.

In fact, talking to a lot of founders you’ll find out they feel like they simply can’t get any work done during the day. The constant barrage of interruptions, important stuff to tend to and emails to answer simply don’t allow it. So they get most of their “work work” done during the night when everyone else is sleeping.

If you have ever programmed anything, you understand the above 3 paragraphs perfectly.

Still, there is a better way…

Read more…

Ruby 1.9.3-p362: “Stack level too deep” Error Message is a bug?

Ruby 1.9.3-p362 Broken?Oopsy!

On 25 December 2012, Ruby version 1.9.3-p362 was released. Is that dedication, or what?

Yesterday, I decided to upgrade to this new version of Ruby that contains only bug fixes.

Bad idea.

Sure, the site loads… But if you try to create a new record via the front-end UI, it craps out with an Internal Server Error.

Digging a bit deeper, it seems this new Ruby version causes a “stack level too deep” error in /active_record/transactions.rb – at least when using Rails 2.3.x.

So, how do we fix this little problem?

Read more…

Sublime Text: A Programmer’s Text Editor for the Rest of Us

Ya know, I program a lot. I also create a lot of web sites. So, having a good text editor is kind of essential.

For the longest time, I’ve been searching for a good programmer text editor like TextMate.

Unfortunately, I shun Macs like the plague since I can build better, faster, more reliable puters myself for 1/3 the price, so TextMate wasn’t an option. And I most certainly will not run a hacked version of OS X just to get TextMate!

At first, I used jEdit. It’s okay, but not quite what I was looking for. Then, I switched to NetBeans for my Ruby on Rails stuff, and Notepad++ for everything else. Well, that worked okay, but NetBeans RoR support is pretty lacking these days.

Furthermore, I wanted to get the heck away from these darn Java-based text editors. That’s really just silly.

Enter Sublime Text 2!

Read more…

Make Rails 2.3.x happy with Ruby 1.9.3

Rails 2.3 + Ruby 1.9.3If you’re like me, you still have some Rails 2.3.x apps hanging around. Yeah, Rails 3 is awesome in some respects, but that “2x performance increase” never quite materialized.

In fact, for the most part, Rails 3 is still slower than Rails 2.3. SIGH!

Nevertheless, Ruby itself is progressing nicely. Ruby 1.9.3-p0 was released a few months ago. With faster garbage collection, startup, and file load times, Ruby 1.9.3 is where it’s at.

The only question is: What do you do to make Rails 2.3 play nicely with Ruby 1.9.3?

It’s actually not that hard!

Read more…

Fixing the Rails 3 Fragment Cache Path

Let’s say you were using Rails 2.3.x, and you made the (wise) decision to implement heavy fragment caching. Then let’s say that you updated to Rails 3.x. At that point, you probably noticed that Rails 3 does something seriously annoying with the paths where it caches fragments.

In Rails 2, doing this:

<% cache('posts/123/123456/main') do %>

Gave you a cache file that looks like this:


However, in Rails 3, the same cache code results in a cache file that looks like this:


WTH? That’s not documented in the Rails 3 API. So what’s going on, and how do you make Rails 3’s fragment caching work like it used to instead of using those crazy hash subdirectories? Read on!

Read more…