Image for post
Image for post

Handy little shortcut I use when I run git pull so I don’t have to specify the current branch:

git pull origin $(git rev-parse --abbrev-ref HEAD)

I make this an alias of git pull so that I always get the branch first.


Image for post
Image for post

Sometimes when you are committing changes in git you’ll find that a number of files have been deleted.

You could manually set these files to delete by individually issuing the command:

git rm filename

However, there is a shortcut. If you issue the command:

git ls-files --deleted

It will return a list of all files that are flagged as deleted.

You can then simply pass that list to git rm, using a combined syntax like this:

git rm $(git ls-files --deleted)

Just don’t forget the--deleted parameter!


Image for post
Image for post

The following command can be used to find and checkout (undo) all files with modifications:

git checkout $(git ls-files -m)

This is effectively an “undo” of all modifications in the given branch (but it doesn’t impact added or deleted files).


Image for post
Image for post

Here’s a list of things you can check if you aren’t getting anything written to the PHP error log on your server:

  • In php.ini, do you have error_reporting set to E_ALL ?
  • In php.ini, do you have log_errors enabled?
  • In php.ini, do you have track_errors enabled?
  • Have you specified a valid file / location for error_log
  • Does the user that starts PHP (e.g apache) have relevant permissions and ownership to write to the PHP error_log file ?
  • Does your application have an override set in .htaccess or php.ini for any of the above?
  • Have you restarted PHP/Apache after making changes for these things to take effect?
  • What does php -i | grep error tell you regarding these settings?

Image for post
Image for post

The group_concat() function in MySQL is really nifty. It concatenates all rows that match your group by statement into a single, comma separated string.

Essentially, it transposes rows to columns.

Take this example. Say you have a table that stores a set of locations by country, state and city.

You could then write SQL as follows:

select 
country,
state,
group_concat(city) as cities
from locations
group by country, state

What this is saying is bring back 3 columns, country, state, and for each combination of country and state, a list of all of the cities in that country and state as the third column (called cities).

This is actually a phenomenally handy thing to be able to do and something you’ll use a lot once you know it exists!


Image for post
Image for post

To see what storage engine is used by the server by default you can use the following command in the MySQL/MariaDB shell:

show variables like '%storage_engine';

You can view a list of supported engines using:

show engines\G;

To find out what storage engine your tables are using by schema use this command. You might want to filter by TABLE_SCHEMA to see a specific database.

select TABLE_SCHEMA, TABLE_NAME, ENGINE 
from information_schema.tables;

You can view statistics about a particular engine using the following (adjust for the relevant engine):

show engine innodb status\G

Image for post
Image for post

By default on Apache web servers, PHP code will not execute in a file that does not have a .php (or similar) extension. So even though you can embed PHP into a HTML file, it won’t execute when the file extension is .html, .htm etc.

To change this, you can add a .htaccess file to allow PHP execution.

Here are some examples depending on your system:

AddType application/x-httpd-php .html .htm

For certain hosting providers you may need to do this (adjust for PHP version too).

Addhandler application/x-httpd-php5 .html .php

Put this in a file called .htaccess in the same folder as your HTML files.


Image for post
Image for post

For example, on a Mac, you’ll often find .DS_Store files. To find and remove these you can run the following command to search for and remove every instance:

$ find . -type f -name ".DS_Store" -exec rm {} ;

This will find all files (-type f) called .DS_Store and execute the rm (remove) command on that set {}.

Run from the top directory and it will recurse its way into all sub directories and remove the files. This can be a dangerous command so use with caution.

You can also adapt the command to execute something else (e.g. a mv to another location for example.


Image for post
Image for post

If you work with databases, sooner or later you’ll need to write SQL to “fix” data in a database table (or tables). One key piece of advice is to make sure that the SQL script you come up with is reversible, just in case you need to change things back or make additional changes on the data set that was changed.

Here’s an example of what I mean:

If this was your data conversion script (to flag users as deleted):

update users
set deleted = 1 where id = (
select id from users
where to_be_deleted = 1
and deleted =…

Image for post
Image for post

The following addition to your .bash_profile is super handy if you regularly use the command line/console on your Mac. Instead of simply deleting files forever it will instead put them into the .Trash folder in a unique sub-folder so you can recover them until you empty your bin. Very handy if you delete something by accident!

function rm () {
local path
for path in "$@"; do
# ignore any arguments
if [[ "$path" = -* ]]; then :
else
local dst=${path##*/}
# append the time if necessary
while [ -e ~/.Trash/"$dst" ]; do
dst="$dst "$(date +%H-%M-%S)
done
mv "$path" ~/.Trash/"$dst"
fi
done
}

Praj Basnet

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store