Recently I had to loop through a series of elements in a WordPress template (thanks Timber), which happened to be using Bootstrap.
If you ever used Bootstrap, you are familiar with the following markup:
The problem here is very common. You have to:
- Loop every 3/4/n items.
- Insert a separator or whatever every 3/4/n items.
You can achieve this with modulo (divisibleby) and checking if the loop index is last and other weird magic. However, Twig introduced the batch filter in version 1.12.3, where you can make this much less cumbersome.
So, adapting the current example and their docs, this is how we achieve a clean loop:
Much better, right?
I realized PHP has a built-in function that handles this. It’s called array_chunk which, of course, splits an array into chunks (or batches as I recalled, and the reason why I hadn’t been able to find it on the docs.)
Edit 19 Jul: Added plain PHP version.
I recently had to install MAMP Pro, in order to do some separate work from my Laravel Homestead VM.
After a weird Mac crash, MAMP would no longer start the MySQL server. This was the data from the logs:
To fix this, go to MAMP, File > Edit Template > MySQL > [version] and add the line highlighted below.
# The MySQL server
innodb_force_recovery = 1
The restart the server. After this you can comment out that line. Hopefully you will now be able to run the server again.
Today I saw a tweet from Das Surma, where it shows how you can open a chromeless Google Chrome browser. Like this:
- Open Terminal app
open -n -a 'Google Chrome' --args "--app=[URL]" where
[URL] is something like http://google.com
If you’re curious about what those flags do, -n “Open a new instance of the application even if one is already running.”, -a “Opens with the specified application” whatever that means.
Today I was bored checking someone’s Linkedin profile page when a friend mentioned that that person was going to know that I visited it.
I thought, that’s weird, Linkedin doesn’t tell me who visited my profile. After a while going through settings, I notice theres an option that lets you hide that information. It’s worth mentioning that it works both ways, i.e., you can roam Linkedin “anonymously”, but you can’t see who visited your profile.
Here’s the link: http://goo.gl/50LI4t
Recently someone told me this great and simple trick on how to run an HTTP web server with just one command line. This is useful for a million things, but I use it for prototyping and avoid same-origin policy in Chrome. Sure, I know there’s a way to disable it, but you may not want to do that.
XMLHttpRequest cannot load file:///C:/Projects/Test/app/views/shell.html. Cross origin requests are only supported for HTTP.
This is all it takes:
$ cd /projects/TestProject
$ python -m SimpleHTTPServer 1234
Then you can access your files at localhost:1234.
I think this provides a much real environment while you build your HTML/JS. That way, you can have a more accurate preview on how your UI is going to feel when served through the Internet by a real server.
Note: This can also be achieved using PHP and probably a gazillion other programming languages.
I found out this amazing tip the other day that turns a browser tab into a full size editable area. As the author said, many of us live on the browser. So having somewhere to jot down ideas/lists while browsing or programming without leaving “home” is great.
I started using this version, but the link below provides various flavours of the same “hack”. So, check it out if this doesn’t cut it for you ;)
data:text/html, <title>Quick Notes</title><body contenteditable style="font-size:2rem;line-height:1.4;max-width:60rem;margin:0 auto;padding:4rem;">
Jus paste this on your browser address bar.