Category: Linux

How To: Change hidden preferences for gedit

Very long time, so see, but that’s a good story for another time. Now it is “time” which is of the essence right now so I just wanna lay down a few simple facts about gedit in Ubuntu 15.10.

There are no preferences / settings / options in the menus (anymore). If the premise is true, or you just happen to be also the ignorant victim of a weird setup, there’s a quick way to set some default settings.

gsettings

This is a gnome settings configuration tool, as always, check the man page for more details. We’ll be using it to display line numbers in gedit and set the tab size to 4 instead of 8.

gsettings set org.gnome.gedit.preferences.editor display-line-numbers true
gsettings set org.gnome.gedit.preferences.editor tabs-size 4

Also, if you need to change any other settings for gedit, use this command to find a list of the available options.

gsettings list-recursively | grep gedit

Props go 3 years back in time to user76204 who had a nice informative post on askubuntu.com. That’s it for now, but remember kids:¬†gedit is the notepad of gnome, for a real IDE you should check Sublime Text (if you haven’t already).

Man it’s been a long time… next post will probably have to cover my new Sublime Text 3 environment (which after long enough is indeed more awesome than my previous one). Also, note to self: there are still unpublished drafts for the Git section, I should get it over with.

I don’t know what exactly the future holds, so just in case I don’t make it back until much later on, I’d like to wish every one who landed here (by mistake or otherwise) merry xmas and a happy new year ūüôā

How To: Fetch Remote Production Databases For Local Development

How To: Fetch Remote Production Databases For Local Development

Ever had that feeling you’re working with outdated data? Sure you have, that’s about the time when you ssh into the production server, make an sql dump and import in into your local development project. I personally find the whole thing extremely boring and rather gay, considering the fact it could all be done automatically… which is what this post is about.

I made a bash script a while ago to help automate fetching of a remote database into my local environment and I’ve been using it with countless projects ever since. It has become a key part if many of my projects’ development branches and I’ve grown very attached to it.

Prerequisites:

  • You’re using MySQL;
  • You have SSH access to production server;
  • You have MySQL credentials (for the root user);
  • If you’re using Windows, you’re also using Git Bash and have your MySQL binaries added to the PATH environment variable.

Script:

Copy the following code into a new file and save it as update-db.sh (you can call it anything else once you earn its trust):

#!/bin/bash

HOST=<ssh host address here>   # host address to connect via ssh (i.e. 123.123.123.123 or somehost.net)
PORT=<ssh port here>           # port for ssh connection (default is 22)
SSH_USER=<ssh username>        # ssh username 
Password=<ssh password>        # password for ssh user
ROOT_PW=<sql root password>    # password for mysql root user
TMP_DIR=/tmp                   # temp remote directory for the sql dump

# Fetching the actual hostname of the ssh server
HOSTNAME=$(ssh -p $PORT $SSH_USER@$HOST "hostname")  

# Gracefully handling potential script arguments
echo "Choose remote database to fetch (<default database name>)"
read -p "Press (ENTER) for default, or type ALL: " DATABASE
if [ -z $DATABASE ] 
then
 echo "Fetching remote database..."
 DATABASES=<default database name>
 FILENAME=$HOSTNAME-$(date +"%Y-%m-%d")
else
 FILENAME=$HOSTNAME-$(date +"%Y-%m-%d")
 echo "Fetching remote databases..."
 DATABASES=$(ssh -p $PORT $SSH_USER@$HOST "mysql --user=root --password=$ROOT_PW -BNe \"SHOW DATABASES;\" | grep -Ev \"information_schema|mysql|performance_schema\" | awk '{ printf \" %s\", \$0 }'")
fi

# Generating SQL dump for selected database(s)
IGNORE=$(ssh -p $PORT $SSH_USER@$HOST "mysql --user=root --password=$ROOT_PW -BNe \"SELECT CONCAT( TABLE_SCHEMA , '.' , TABLE_NAME ) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'rec%';\" | awk '{ printf \" --ignore-table=%s\", \$0 }'")
ssh -p $PORT $SSH_USER@$HOST "mysqldump --force --user=root --password=$ROOT_PW $IGNORE --databases $DATABASES | gzip > $TMP_DIR/$FILENAME.sql.gz"

# Fetching the SQL dump to local temp directory and cleanup the remote temp directory
scp -P$PORT -c blowfish $SSH_USER@$HOST:$TMP_DIR/$FILENAME.sql.gz $TMP_DIR
ssh -p $PORT $SSH_USER@$HOST "rm -f $TMP_DIR/$FILENAME.sql.gz" >/dev/null 2>&1
gunzip $TMP_DIR/$FILENAME.sql.gz

# Purge the local database (if existing) and import the remote database from sql dump
echo $DATABASES | awk '{ printf "DROP DATABASE %s;", $0 }' | mysql --user=root --password=$ROOT_PW
mysql --user=root --password=$ROOT_PW < $TMP_DIR/$FILENAME.sql
rm -f $TMP_DIR/$FILENAME.sql
echo "Updating local database(s) complete."

Make sure you replace the bootstrap variables with your own data and then make the script executable by running chmod:

chmod +x update-db.sh

Now what?

Now you just run it. If you configured it correctly, it will NOT expose your machine by opening all available ports, steal all your sensitive information, format your other partitions or burn your house down:

./update-db.sh

Here’s exactly what happens when you run it:

  • It says Press (ENTER) for default or type ALL,¬†to which you respond by doing so dooh~
  • It connects to the SSH server and generates an sql dump in the temp directory, containing the selected remote database or all of them, except information_schema, mysql and performance_schema
  • It copies the sql dump file (its name would be something like <hostname>-<year>-<month>-<date>.sql.gz) to your local temp directory
  • It unzips the file on your local machine
  • It deletes the remote sql dump file
  • It drop the local database(s) if existing and imports the remote one(s) from the sql dump
  • It says¬†Updating¬†local database(s) complete.

The catch…

Almost too good to be entirely true, yes, the script has a few minor drawbacks… I cannot be entirely sure, but I think you shouldn’t use this script with the ALL option (or typing anything else before pressing ENTER for that matter) – by the looks of it, it might drop all existing local databases and import the ones in the sql dump (which is perfect only if your workstation doesn’t contain other databases than what the server does).

I’ve been successfully using it with the default option for too long to care anymore. Another downside would be that using it makes you about 30% less cool, as compared to your typical routine of manually ssh-ing into the server, dumping databases and scp-ing them back you sexy hacker, you…

How To: Upgrade To The Latest Version Of phpMyAdmin [Updated]

How To: Upgrade To The Latest Version Of phpMyAdmin [Updated]

Update: The ppa hasn’t been updated in over a year so, just go to phpmyadmin.net, download the .deb and overwrite the installed packages and maybe do a reconfig.

If you installed phpMyAdmin from the main repositories, chances are you’re never going to be up to date with the latest stable release. Ubuntu users got it easy though, while in Windows you would download the zip file containing the latest stable release, dump it in your wamp/apps folder and change the .conf file every time a new version comes out, in Ubuntu you only need to add a ppa repository and let apt handle the rest.

To add the repository

sudo add-apt-repository ppa:tuxpoldo/phpmyadmin

To install the latest version

sudo apt-get update
sudo apt-get install phpmyadmin

The installation process is pretty straight-forward to the point where it asks you reconfigure the db (attempting to do that didn’t work in my case so you probably might as well abort that from the start).

Also it might be possible that you get left with a bunch of orphaned packages which you can get rid of by running a simple sudo apt-get autoremove or something.

To remove the repository

If you want to keep only the packages you installed from the ppa:

sudo add-apt-repository --remove ppa:tuxpoldo/phpmyadmin

If you want to remove everything (i.e. the repository and the installed packages):

sudo apt-get install ppa-purge; sudo ppa-purge ppa:tuxpoldo/phpmyadmin

That’s about it. Now in case you haven’t done this already, you need to check out my dark minimal theme for phpMyAdmin, always updated and optimized for the latest stable release. Clone the repository in your themes¬†directory and go feel good about yourself.

Gource: Visualize your Git logs in style

Gource: Visualize your Git logs in style

While generally there isn’t any¬†real benefit in¬†using this tool, it has been known to be able to increase your swag factor by up to 83% and it is, in the context of version control, the ultimate eye candy, an absolute must-have for catholic priests and Pedobear fanboys.

Gource was developed by Andrew Caudwell as a software version control visualization tool with built-in log generation support for Git, Mercurial, Bazaar and SVN. To find out more about it, you can check out the official page on code.google.com.

Software projects are displayed by Gource as an animated tree with the root directory of the project at its centre. Directories appear as branches with files as leaves. Developers can be seen working on the tree at the times they contributed to the project.

Gource Screenshot

Windows users can download it from the Downloads section of the project page, install it and run it normally from a command prompt, while in Linux, you can just install it from the main repository:

sudo apt-get install gource

To use it, just navigate to the working directory of a git repository and run it:

cd /path/to/your/repo
gource

or, run it directly by just providing the directory as an argument:

gource /path/to/your/repo

Here’s an absolutely remarkable video showing 21 years (1991 – 2012) of the Linux Kernel development process in somewhere around almost three hours:


Check out the help/man pages for a list of all the options and how to use them. For instance, I sometimes use this as a screensaver:

gource -1920x1080 --fullscreen --multi-sampling -a 0.1 --time-scale 3.0 --loop -i 3600

Oh, and here are some fun interactive keyboard commands:

(V)         Toggle camera mode
(C)         Displays Gource logo
(K)         Toggle file extension key.
(M)         Toggle mouse visibility
(N)         Jump forward in time to next log entry.
(S)         Randomize colours.
(+-)        Adjust simulation speed.
(<>)        Adjust time scale.
(TAB)       Cycle through visible users
(F12)       Screenshot
(Alt+Enter) Fullscreen toggle
(ESC)       Quit

The documentation is a lot, but well structured and worth reading + there’s even a guide for recording / encoding videos if you’re not into third party video capture software.

Hardware Acceleration in Chrome

Hardware Acceleration in Chrome

All work and no play makes Jack a dull boy

Well, as if anybody expected that to only apply to Jack, you can bet your ass it also applies to Mike. That’s right – every now and then Mike needs to take the edge off on some Youtube sh*t (sometimes even for endless hours lost in oblivion) or some damned annoyingly addictive browser game.

But then again, how in f*ck’s name would Mike feel any better about doing so if everything hangs and seems laggy / choppy? He wouldn’t, that’s how. And right about now, he blames it all on Chrome’s hardware acceleration default settings under Linux. Just to make sure, he goes to¬†chrome://gpu/¬†and witnesses this horrific scene:

chrome-gpu-off

But Mike’s a crazy mothaf*cka – he then just goes straight to¬†chrome://flags/¬†and enables the override on software rendering, thus enabling GPU acceleration on his¬†apparently unsupported system configuration.

chrome-flags

He now restarts his Chrome, everything works fine and the Gods of Internets smile approvingly. But just before diving into a multiverse of fun, he takes a few short moments wallowing in self-pity, consumed by doubts about nVidia and random homicidal thoughts about Aquaman while checking the chrome://gpu/ page one last time.

chrome-gpu-on

Just to remove any trace of doubt – that green text right there – it makes St. Patrick proud and Chrome run smooth. Mission complete.

How to make a Git server: The quick and dirty way

How to make a Git server: The quick and dirty way

Just as I was organizing my thoughts for the second part of my Getting started with Git series, I realized that it will all pretty much revolve around working with remotes – so here’s a quick guide to install and configure a git server. While this method is not the recommended way of doing things, it will get them done quite fast but don’t expect any sophisticated security or easy repository management.

This guide will get you up and running your Git server in no time, so that you can get right into creating new repositories that you and anyone else who has access to the server can clone locally, pull from and push to.

Step 1

SSH into your server and install git:

sudo apt-get install git

Step 2

Create a directory to hold your repositories and make sure it has the right user permissions:

sudo mkdir /srv/git

Step 3

Create and initialize your first repository by making a new directory and initializing a new bare git repository there:

mkdir /srv/git/my-repository.git
cd /srv/git/my-repository.git
git init --bare

Step 4

Clone your repository locally and make your first commit and push:

cd /var/www/public_html
git clone ssh://you@server-address/srv/git/my-repository.git
cd my-repository

At this point, it’s time to add some files to this empty directory, or start making them one by one if you feel that hardcore. If you run a git status command, you’ll see that your file(s) are all there but not currently being tracked, so we should add them to the staging area:

git status
git add .

Time to make our first commit and add a meaningful message to it, like “Initial commit”. But no, really, these sort of messages are only permitted on first commits, for all the rest of them you should try to be as descriptive as possible and always to the point… oh hell, I’ll just write a separate post for that later on.

git commit -m "Initial commit"

We can now safely push this commit to the remote repository and also set our master branch to track the remote master branch for changes by using the -u¬†option just this one time only. If you haven’t done this already, it’s about damn time you set up passwordless SSH login, it can and most probably will save lives.

git push -u

Updating your local copy with the potential changes from the remote before pushing your own is usually considered good practice, especially if you’re not the only one working on the repository. A little git pull¬†every now and then never hurt anyone – well, except for the times you get conflicts.

That’s when sh*t gets ugly and even though the rational thing is to just calm down work them out one by one, it really pays off to storm out of your cubicle, bloodshot eyes, swinging¬†a DIY nunchuck made of keyboards / mice / extension cords / what have you, spitting death threats at your co-workers…

This will get you a reputation and / or a night in jail so be ready for both. For more tips on moronic behavior, follow my guide on How To: Make A Rep In Jail In The First 12 Hours. Just kidding… am I?… kidding… or am I?…