Human join / implode helper

December 11th, 2013

Did you notice that when humans list items, they use a different glue for the last item?
“Who was there?” “Tom, Bob and Jane.”

Here’s a Nette helper that does the same.

  1.  
  2. public function humanJoin($pieces, $glue = ‘, ‘, $lastGlue = ‘ and ‘)
  3. {
  4.   if (empty($pieces)) {
  5.     return null;
  6.   }
  7.  
  8.   if (count($pieces) == 1) {
  9.     return $pieces[0];
  10.   }
  11.  
  12.   $lastItem = array_pop($pieces);
  13.   return join($glue, $pieces) . $lastGlue . $lastItem;
  14. }
  15.  

Use as {$friends|humanJoin} or {$aliens|humanJoin:’, ‘:’ nor ‘}.

Configuring Nette in Neon

February 18th, 2013

I bet you didn’t know it but Nette’s internal behaviour can be configured quite extensively in config.neon. Default form error messages, switching on/off debugger panels, changing mailer to use SMTP instead of mail() and so on. All of this can be set up in PHP but keeping configuration out of your code helps making it easier to read. Do have a look, it has a great potential. As usually, the documentation is pretty bare and it’s up to us to discover the whole truth. This post contains some additional information that I scavenged in forums or discovered myself. Read the rest of this entry »

You thought using Skype was secure?

August 13th, 2012

Many of us send sensitive information over Skype chat in order to prevent a third party from reading it. Think login credentials for example. What you may not know is that Skype is set by default to store chat history on your hard disk. Nothing wrong with it if it weren’t in plain text!

Read the rest of this entry »

Dynamic snippets for repeated forms

April 11th, 2012

At the time of this writing, Nette lacks a good support for dynamic snippets. You can define them wrapped in a static snippet but you can’t invalidate them individually (unless they each belong to a different control, I think). You can only invalidate the static parent snippet which means you receive all its dynamic children snippets in the payload.

If you defined only a few snippets with small amount of data in each then no big deal. If however, you have a pageful of forms, each form containing a snippet that you want updated upon the parent form submission then you have to resort to tricks. For instance, you don’t want a message “Saved” displayed in each row/form in a product administration table.
Read the rest of this entry »

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 »