One liner for importing multiple SQL files using WP CLI DB command

In some cases, SQL backups break exports into multiple files, usualy by table name.

I wanted to import all the files in one go and figured googled my way to this “one liner”:

for sql in `ls wp_sql`                                                     
do
Next up is $sql
time wp db import wp_sql/$sql --skip-optimization
done

How to use this command – Setup:

This assumes that you have exported the files correctly.

  1. Make sure that the directory holding your SQL files are in the root WordPress directory (next to wp-config.php file)
  2. Make sure you’ve changed directory to the WordPress root.
  3. Rename the directory towp_sql or change the name in the script to the name of your directory.
  4. Add each command line by line.

I hope this helps some one.


Other posts you may also enjoy:

One year at the helm of Vim

One year ago I started using an old text editor called Vim. I’m happy to say that I’m still sticking with it. I’m now very comfortable with VIM and more empowered translate Ideas into working solutions.

In this year I’ve become accustomed to working the terminal, embracing the VIM way while realizing that that coding is just one part of the challenge.

Not your IDE

Transitioning from PhpStorm, I desired the same IDE-like features in VIM. After multiple config changes and plugin tests, I had an epiphany: VIM is an editor and that’s it. It is one of the tools in your shed. You combine it with other command line tools to empower an efficient workflow. I believe this is key to making the most of VIM.

With this also comes the realization that tabs, though it looks nice, is not the most efficient way to switch between files. A short list of buffers is the way to go. I always close the editor when I’m done with a task and re-open it for the next one. This ensures that all current buffers are closed and I can start with a low memory footprint every time.

Who Uses Caps Lock anyways?

A common thing in the VIM community is to modifying CAPS LOCK key. As a programmer you don’t really use CAPS LOCK, you will mainly use SHIFT for upper case. Some VIM users take CAPS LOCK as an extra escape and others as another CTRL. I have chosen CTRL as many commands require this button, which is awkwardly placed on my Mac Keyboard.

Hard Times are good for you

One of the first things I embraced was Hard mode. With this activated, VIM disables the arrow keys for navigation and stops you from jumping up more than one line at a time (using h,j,k,l). This pushed me to use other movements. I would argue this to be a must for any VIM beginner. You simply don’t understand how powerful these other movements are until you get used to them. It is excruciating in the begging but the benefits far outweigh the cost. After some time I turned this mode off and used “Hard Time” instead, which works the same but is a little more forgiving.

Undo and try again

Practicing all the time is critical to mastering VIM. By practicing, I mean on the Job training, while you’re working and editing. If you find that you did something and it took too long, or you remember a faster way to do it. Stop, undo and redo it in a more efficient way. This more effecient way becomes the default going forward and you save yourself many many seconds in future. Adding all these ups definitely increases your editing speed.

Another note on this is not to worry about the time it takes to add a shortcut to your config files. Every second you shave off your workflow gets multiplied by how many times you have to repeat the same editing tasks and this is a major win!

Trying not to use so many plugins

The VIM plugin echosstem makes it much easier for newbies feel comfortable and for masters to craft the exact experience they desire.

I discovered that plugins can get in the way just as much as they can help. You need to make sure you really need a plugin before installing it. What I do is try to I try to get away without a plugin to see if I cant modify my VIMRC to do the same thing a plugin does. As a last resort, I’ll use a plugin.

Onwards and Upwards?

I would encourage everyone to learn VIM, but honestly but I understand that not every workflow will benefit from being close to the Command Line.

You are not in a mutually exclusive relationship with your editor. Use the one that’s better for the task at hand. I occasionally jump into Atom ( forgive me VS Code champs ). As Daniel Miessler puts it, the content matters more than the editor.

Let’s not allow our tools to get in the way. These are our weapons of mass impact and ultimately only a means to an end.

Imposters handbook: a quick review

A year ago I read the imposters handbook. It seemed like this book was specifically for people like me. The found himself in the same position I was in: Feeling like an imposter.

I read this book a year ago, but it took me this long to write something about it as I was lacking the daily discipline of working on my blog probably related to the same imposter feeling.

I felt like an imposter and, at times, probably still, but I’m way more confident now after I realized that everyone else feels the same way. The book showed me that feeling like an imposter is normal but that it doesn’t mean that you should continuously take the back seat and let another lead the way as you think you don’t belong.

This book is a great starter for people, like me, who did not do a Computer Science degree. It is a basic introduction to many relevant topics, but you may want to dive even deeper into those that you encounter more often.

You will find topics you may never ever need, but it’s simply nice to be familiar with what these are and that you can smile and nod without blatantly faking it.

A year later I notice that version 2, with Scott Hanselman, is out and it looks promising:imposters_handbook_season2Link to Imposters Handbook Season 2

I would encourage anyone working in technology or with an interest in programming to read this. It has certainly given me a great deal of comfort knowing that I can now understand some CS concepts that evaded me in the past. 

a brilliant talk on how to prepare for success

I watched this talk and it answered most of the questions I had about how to succeed and make an impact.

The talk is titled “You and your research/career”, implying your career is something to be studied.

You should watch it yourself, but for me, the main take away is: “Work on important things with important people”.

I hope you learn something that inspires you to take charge of your career. Where do you want to be, who do you want to work with and what kind of legacy do you want to leave behind.

I got this talk from: Must-See Tech Talks for Every Programmer

Programming well with others

I watched a funny but interesting talk about working well with others.

An important take away from this video is:

  • It’s not about how smart you look, but what impact you can make with others

You can find many other great pieces of advice in the video. It is done in a very interesting manner. They’r taking “live” calls!

I got this from Must-See Tech Talks for Every Programmer.

When are you proficient in a programming language?

Learning a programming language gives you the opportunity to explore other problem domains alongside new approaches to addressing familiar problems.

I write this as I was looking for the answer to exactly this question. There were many opinions that had me confused, some from ancient rockstar ninjas who command CPUS at will and others from earnest people who are also seeking.

Why would one ask such a question in the first place? It seems like the actual issue is 2 fold. For me it is firstly; when can this go on my resume. Secondly and probably more specific to me: when to move on to the next language or skill. When can I check off my to-do list and say that I know a programming language?

After looking at many other ideas, In my opinion: You are proficient in a language when you are able to read, understand and debug code along with deploying to production.

If you can read, write and execute you are well on your way and I would consider this profecient. Beyond this, optionally, persue mastery. Though in order to keep a language on your resume, make sure to continually read, understand and debug.

Link to other opinions: https://softwareengineering.stackexchange.com/questions/154862/at-what-point-can-i-say-ive-learned-a-language

Take a Nap, Change your life Book Review

I used to ascribe to the phrase: “sleep when you die”, but to what benefit? Hustling? Working hard? That may seem like the best thing to do now, but it may take 3 times as long for you to reach your goals, if you are burnt out, as you make a lot of mistakes in this state.

The title of this book grabbed my attention. Who doesn’t what to change their lives for the better? I guess most of us do, so the things I take form this book was exactly what I expeceted: Working smart and sharpening your most valued tool, the mind, is simply one of the best things you can do for your better future.

The book teaches that napping has many benefits and encourages you to incorporate a nap into your daily routine. On regular days, a short nap will do, but on days when you feel more exhausted taking a longer one is perfectly fine.

The short 20-minute nap gives you a boost in energy and alertness, which is good for motor learning skills. The longer 90-minute nap gives you a full sleep cycle, improved emotional state, and procedural memory, this also helps with new connections in the brain. Source for more data.

What I didn’t like about the book. I was expecting a 5 pager to be honest. Give me all the good stuff and let me go to bed right now. The book focuses on education around sleep in general. It makes a short hit at the naps and how to do it. The main focus is on understanding how sleep works.

You should read this book, if you want to undrestand why napping is important and how your sleep cycles work.

This book may not change your life, but applying the principles may have an exponential impact on your health, happiness and possibly even bank account.

Creative Computer Science

I read an interesting article on how personal development as a Software Engineer should be largely focused on thinking rather than specific technologies.

To add to this, when you happen upon the new shiny tool, language or technology you should look at it and try to decipher the underlying ideas and concepts that allow it to exist.

We need to focus more on ideas and less on implementation and specific technologies.

Link: https://www.ybrikman.com/writing/2014/05/19/dont-learn-to-code-learn-to-think/

Why I’m learning a new Programming Language called Go

For the past few years, I got stuck in a rut, a good one. My sole focus was not the technology I used. but rather the thought processes behind why and how I write code. I write in PHP and I mainly focus on the WordPress CMS. This pays the bills and helps me take care of my family but, while focusing on thought processes, I didn’t realise that learning a new language can have the same effect, helping me think differently about similar problems.

So why Go (#golang)? This one I stumbled upon by accident. A colleague of mine, Akeda, automated one of our workflows. Before this, we had a weird process involving multiple tools and steps. His script made life just a little easier. I thought one could improve it just a little bit more, but in oreder to do this I had to go digging into Go source code.

After hacking on this project and getting it “mostly working” I decided to dig a bit deeper into Go. I found out immediately that it was created by a few very smart people at Google. It is open source and has a very strong community. More specifically, Docker, the tool I use all the time, was written in Go(mind blown gif goes here).

With Go you to create systems software. I know my way around PHP and this is great, but there are a few things an interpreted language simply can’t do. This presented me with another opportunity to learn.

Go is written in Go! Yep, that means you can eventually read and contribute to any bugs in the language itself, if that’s something you’re interested in. I think it’s great that one only needs to learn on language to get involved with an entire commuinity.

Learning GO is free, no need to buy expensive books. Do the tour, then work through How to write go code and then read Effective Go. After this, you can start using the language. If you are new to programming you may need more help.

With Go, most of the tooling forms part of the language. The following things are already included: code documentation generation, testing, dependencies etc. In most languages I know these are third party tools. They may not work exactly how you want them to, but they work and they remove the burden of having to choose between third-party options. Though third-party options are available, the idea is that everything you need to be productive should be part of the language.

New languages force us to think differently about the same problems, as per this stack overflow answer:

It’s not about the next “new thing”. It’s about thinking in different ways outside of your normal thought patterns

I hope this inspires you to pick up a new language. There are so many to choose from.

Featured image is a gophers, the Go mascot. It was created with https://gopherize.me/. Creating a unique gopher.

Microservices Are Something You Grow Into, Not Begin With

The craze around microservices is great, but starting small and simple is the best use of our limit time, specially when starting a new project, More on this from the link below:

https://nickjanetakis.com/blog/microservices-are-something-you-grow-into-not-begin-with