Automatically setting height of textarea to height of its contents on page load

jQuery makes everything so ridiculously simple. To make sure a textarea is automatically resized so it fits its content one could calculate the amount of rows of text and the approximate height of the font and set the height of the textarea to the product of that. Or you could set the height to the scroll size with jQuery and JavaScript. <script> $(function() { $('textarea').height($('textarea').prop('scrollHeight')); }); </script> Admittedly, it’s not a complete solution if you need it on a page with more than one textarea though.
Read more →

Is [language] worth learning?

This is a really short response to a question I’ve stumbled across twice today, “Is [language] worth learning?” All languages have some worth, but they are all good in different areas. It all depends on what you want to do and how much you want to learn about programming. C is very good if you want to learn how computers work without delving into the inaccessible mess that is assembly programming.
Read more →

How to put checkboxes in Bootstrap dropdowns

Bootstrap is an extremely useful set of tools which, I personally believe, everyone should know about and use for their own internal projects. It’s ridiculous what a time saver it is, especially combined with Font Awesome to get over 360 free, scalable icons to use with Bootstrap. Bootstrap also have these amazing JavaScript tools which, for instance, allows you to place a dropdown menu on virtually any element. The only problem with these are that you can’t really put forms in them, since the dropdown closes when you click on it.
Read more →

An alternative for SQL pagination

I was reading up on improving the performance on MySQL when I found an article and stumbled on a really cool alternative to using offset when generating pagination results from the database. On the query side, instead of using LIMIT with offset, you can select one more row than you need, and when the user clicks the “next page” link, you can designate that final row as the starting point for the next set of results.
Read more →

Building a template engine in PHP

Possibly the most common sign of bad code is tight coupling, especially between logic and presentation. It might seem like a good idea to print out the HTML while the data is being generated, but it more often than not leads to a big incoherent mess of tangled code. It also causes other issues, like what happens if an unexpected error occurs in the middle of the page? By then half the page has already been outputted and it might be too late to handle the error nicely.
Read more →

Bear riddle

Read more →

How to combine multiple commits into one

If you’re using Git you know how powerful it is as a CVS tool. But when Git is used as a deployment tool to be able to quickly revert changes if needed it may cause some headaches when deploying major features. There’s a trade off between having one giant commit and working with Git the preferred way of using small, incremental commits when deploying in this way. If there’s a critical problem with the new feature it will need to be reverted quickly which could become quite annoying if there are a lot of commits.
Read more →

Creating a new user on MySQL

Creating a new user should be a lot simpler than it is. I always forget one or two things and need to look up the exact syntax whenever I need this to make sure that everything is included properly. This is the full command used to create a new superuser in one line with full access to all tables and ability to create new users as well. The following command essentially creates a new root user that is allowed to connect from any host so use this with caution.
Read more →