Converting hexadecimal RGB code to decimal with a bookmarklet

March 22nd, 2012

Many applications use the default Windows colour picker which unfortunately, doesn’t support hexa codes. Use this bookmarklet to convert and copy the decimal values from your browser to the picker. No need to bullshit around, here’s the thing :-)

Drag this onto your bookmark toolbar:
RGB hex2dec
Read the rest of this entry »

Using NCache to store image thumbnails

November 30th, 2011

There are many ways to handle image thumbnails.  Sites with heavy traffic generate resized copies right after the original image is uploaded. Light traffic sites on the other hand, prefer to wait until the thumbnail is actually requested. Nette offers a few creative ways to handle this:

  1. You can use .htaccess to catch requests for non-existent thumbnails and redirect them to your script.
  2. Following the same theme, you can also use your ErrorPresenter to generate the thumbnail and override the response code (so that it’s not 404).
  3. An unusual solution is to use a helper and generate the thumbnail when rendering your template.
  4. Or simply use a presenter action.

In any of these cases, you need to decide where you’re going to store the thumbnail and how you’re going to delete/update it when the main image changes. This is where you can use the excellent built-in caching aparatus.

Read the rest of this entry »

n:src – the missing twin brother of n:href

November 23rd, 2011

As you have probably guessed by now, I love Nette. The more it hurts when I see the documentation lag behind the quality of the framework. Although I don’t understand why Latte built-in macros don’t include n:src when the oh-so-useful n:href is there my main concern however, is that nowhere in the documentation you’ll find detailed information on how to add it yourself. You’re condemned to endlessly search through forum again and crawl through various outdated subdomains of nette.org.

Here’s my solution to the n:src alias based on a post in the cookbook and the built-in n:href macro. You can also take a peek an another post of mine on how to tweak your forms using macros. As always, hopefully it’ll save you some time.

Read the rest of this entry »

Repeated forms on the same page

November 22nd, 2011

Often you want the user to have a form not just for one entity but for all of them on the same page. A form for each product in the same category, for example. I’m not talking about multiple different forms but multiple instances of the same form.

This topic has been discussed in the Nette forum so many times that it’s really a shame that it’s still missing in the documentation. Frustrated after an hour spent reading outdated forum posts, I offer here a complete solution based on one of the posts.

Read the rest of this entry »

Refreshing current user’s identity

November 9th, 2011

Nette stores current user’s identity in session. There are a few situations when you want to reload the identity or change it completely. For example, the user updates his profile and you want the change reflected in the page header. Or a super administrator is allowed to re-authenticate as a different user without having to know the other user’s password.

NUser has a convenient method called setIdentity() but unfortunately, it’s declared as private so you can’t use it. The solution is either to loop through the current identity and update its fields one by one, or do it nice and clean with a custom authenticator. Let me show you.

Read the rest of this entry »