Unwrongest http://unwrongest.com Just another WordPress site Wed, 01 Feb 2012 08:50:24 +0000 en hourly 1 http://wordpress.org/?v=3.2.1 Textareas with a 100% width and no overflowhttp://unwrongest.com/100-percent-width-textareas/ http://unwrongest.com/100-percent-width-textareas/#comments Sat, 19 Mar 2011 14:42:11 +0000 Jan Jarfalk http://unwrongest.com/?p=567 After a poke-around in the Facebook source code a colleague of mine found this awesome little technique to get textareas with a width of 100% to behave exactly as you want them to.

If you just slam { width:100% } on the textarea you usually end up with a textarea that overflows its container. That since the textarea’s width will be 100% + padding + borders. You need to counter the padding and borders.

The absolute easiest way to do that is to add padding to the wrapping element.

  1. <!doctype html>  
  2. <html lang="en">
  3. <head>
  4.  <style>
  5.   label { padding: 0; marign: 0; display: block; }
  6.   textarea { width: 100%; border: 1px solid #333; padding: 4px; }
  7.   .the-fix { padding-right: 10px; }
  8.  </style>
  9.  
  10. </head>
  11.  
  12. <body>
  13.  <label class="the-fix">
  14.   A good-looking textarea with a 100% width
  15.   <textarea></textarea>
  16.  </label>
  17. </body>
  18. </html>

The width of the input is 100% of its container + 1px + 1px (borders) + 4px + 4px (padding). In other words the width is 100% + 10px; Therefore we give the fix class an extra 10px padding to the right.

]]>
http://unwrongest.com/100-percent-width-textareas/feed/ 0
Speed up FTP transfers with zip and sshhttp://unwrongest.com/ftp-zip-ssh/ http://unwrongest.com/ftp-zip-ssh/#comments Mon, 10 Jan 2011 10:24:19 +0000 Jan Jarfalk http://nun/?p=410 Uploading many small files using FTP usually takes longer than one big. It’s often a good idea to upload a compressed zip archive and then unzip the whole package directly on the server.

Unzipping zip files on the server is something you often can do if you have SSH access. All you need to do is to upload a compressed archive using FTP, open up a Terminal and then do something like this:

  1. // Connect with SSH
  2. ssh yourdomain.com -l yourusername
  3.  
  4. // Locate the directory with the zip file
  5. cd /domains/yourdomain/html
  6.  
  7. // Unzip
  8. unzip html.zip

Simple as that! Another couple of minutes saved.

]]>
http://unwrongest.com/ftp-zip-ssh/feed/ 0
How to break Javascript strings into multiple lineshttp://unwrongest.com/js-multiple-line-strings/ http://unwrongest.com/js-multiple-line-strings/#comments Thu, 23 Sep 2010 16:36:58 +0000 Jan Jarfalk http://n.unwrongest.com/?p=243 There are two ways to break up a Javascript string into multiple lines: Backslashing and string concatenation.

String concatenation is often easier on your eyes, but slower and more memory intensive. If speed and performance is a goal than you should always delimit your JavaScript strings with backslashes and not plus signs.

Delimiting with backslashes

  1. var text = "Lorem ipsum dolor sit amet,\
  2. consectetur adipisicing elit,\
  3. sed do eiusmod tempor incididunt\
  4. ut labore et dolore magna aliqua.";

Delimiting with string concatenation

  1. var text = "Lorem ipsum dolor sit amet,"
  2.          + "consectetur adipisicing elit,"
  3.          + "sed do eiusmod tempor incididunt"
  4.          + "ut labore et dolore magna aliqua.";
]]>
http://unwrongest.com/js-multiple-line-strings/feed/ 0
How to decompress javascripthttp://unwrongest.com/how-to-decompress-javascript/ http://unwrongest.com/how-to-decompress-javascript/#comments Thu, 05 Mar 2009 21:47:10 +0000 Jan Jarfalk http://nun/?p=554 The online beautifier is a javascript decompression tool. It takes a compressed javascript and inserts indents, new lines and makes it readable. You find the online beautifier at http://elfz.laacz.lv/beautify/.

When I am finished with a javascript component, like Elastic, Tabify or Accordion, I always create a compressed version of the source code using a javascript compressor like YUI Compressor or Dean Edwards Packer. The compressor shortens long internal variable names and removes unnecessary white spaces making the code lighter.

Developers often only provide these compressed versions of the code, which makes the code hard to read, understand and modify. The online beautifier is a javascript decompressor. It doesn’t get back the original variable names but it does create indentations and new lines. Below is an example of what the online beautifier does with the compressed code of my Jquery plugin Accordion.

This is the compressed and minified version of the jquery plugin Accordion. The whole source code is on one line and all white spaces are removed.

  1. (function($){$.fn.extend({accordion:function(){return this.each(function(){if($(this).data('accordiated'))return false;$.each($(this).find('ul, li>div'),function(){$(this).data('accordiated',true);$(this).hide()});$.each($(this).find('a'),function(){$(this).click(function(e){$(e.target).parent('li').toggleClass('active').siblings().removeClass('active').children('ul, div').slideUp('fast');$(e.target).siblings('ul, div').slideToggle('fast');return void(0)})})})}})})(jQuery);

This is exactly the same code after the online beautifier is done with it. The tabs and new lines it has inserted has made the code a lot more readable.

  1. (function($) {
  2.   $.fn.extend({
  3.     accordion: function() {
  4.       return this.each(function() {
  5.         if ($(this).data('accordiated')) return false;
  6.         $.each($(this).find('ul, li>div'),
  7.         function() {
  8.           $(this).data('accordiated', true);
  9.           $(this).hide()
  10.         });
  11.         $.each($(this).find('a'),
  12.         function() {
  13.           $(this).click(function(e) {
  14.             $(e.target).parent('li').toggleClass('active').siblings().removeClass('active').children('ul, div').slideUp('fast');
  15.             $(e.target).siblings('ul, div').slideToggle('fast');
  16.             return void(0)
  17.           })
  18.         })
  19.       })
  20.     }
  21.   })
  22. })(jQuery);

The tool is not perfect, and it can’t decompress everything, e.g. it can’t decompress a file which have been Base62 encoded – But I like it and think you should give it a go at http://elfz.laacz.lv/beautify/.

]]>
http://unwrongest.com/how-to-decompress-javascript/feed/ 0