My Tech Blog

Subscribe to My Tech Blog feed
Updated: 1 hour 46 min ago

Export a MySQL table to a CSV as fast as possible (even for millions of records)

Thu, 2015-11-26 15:28

using the mysql query tool from the command line, run a query like this:
    -> INTO OUTFILE '/tmp/weather.csv'
    -> ENCLOSED BY '"'
    -> ESCAPED BY '\\'
    -> FROM weather_archive;

this exported 1229798 rows (30 cols) in 4.98 sec ;-)

Install Google Earth on Ubuntu 14.04 64-bit

Sat, 2015-02-07 08:46

Since the 64 bit version or GE does install correctly on 64 bit ubuntu, the following will get the job done by installing the 32bit requirements in your 64 bit OS then installs the 32 bit version of GE.

sudo apt-get install libfontconfig1:i386 libx11-6:i386 libxrender1:i386 libxext6:i386 libgl1-mesa-glx:i386 libglu1-mesa:i386 libglib2.0-0:i386 libsm6:i386
cd /tmp && wget sudo" title="
dpkg -i google-earth-stable_current_i386.deb
sudo apt-get install -f

Install NOIP Client on your Raspberry Pi Model B

Sat, 2015-01-24 17:47

sudo apt-get update -y; sudo apt-get upgrade -y;

read more

Install Drupal on your Raspberry Pi Model B

Sat, 2015-01-24 16:29

Installing Drupal 7 on Rpi B - Raspbian with Network & SSH working:

sudo apt-get update -y; sudo apt-get upgrade -y;

read more

Create a headless UPnP/DLNA Renderer in Ubuntu 14.04

Tue, 2015-01-06 10:16

You can make your ubuntu 14.04 into a Media renderer quite easily.

sudo apt-get install autoconf automake libtool
sudo apt-add-repository ppa:mc3man/trusty-media
sudo apt-get update
sudo apt-get install libupnp-dev libgstreamer0.10-dev \
gstreamer0.10-plugins-base gstreamer0.10-plugins-good \
gstreamer0.10-plugins-bad gstreamer0.10-plugins-ugly \
gstreamer0.10-ffmpeg \
gstreamer0.10-pulseaudio gstreamer0.10-alsa
sudo apt-get install git
git clone
cd gmrender-resurrect

read more

Easy exporting of Drupal 7 custom fields for use in module code.

Fri, 2013-05-17 16:49

ok, down and dirty, you need the devel module installed and working, but this code will produce two arrays you can paste into your :

_my_module_installed_fields() and _my_module_installed_instances()

* Returns a structured array defining the fields created by this content type.
* @return
*  An associative array specifying the fields we wish to add to our
*  new node type.
function _my_custom_module_installed_fields() {
  $t = get_t();

read more

Midnight Commander on OS-X

Sat, 2013-03-30 10:40

As a die hard terminal man, I have found my Macbook Pro to be a pain because of my linux habits. I found myself asking; How do i select files and access the menu in Midnight Commander on OS-X

Google is my friend :)

On a Mac the insert key may be triggered by the <ctrl>+<t> shortcut. So you may use this key combination to select files in the Midnight Commander.

When using this Norton Commander clone, you may also want to access the menu. But the function keys are preassigned to OS-X functions. So how do you get them to work with Midnight Commander?

read more

Get lists of NIDs from DB filtering by fields without having to do joins - Hello "Entity Field Query"

Thu, 2013-03-28 16:50

New with D7 is the Entity Field Query. Use it like this!

$query = new EntityFieldQuery();

$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'article')
->propertyCondition('status', 1)
->fieldCondition('field_news_types', 'value', 'spotlight', '=')
->fieldCondition('field_photo', 'fid', 'NULL', '!=')
->fieldCondition('field_faculty_tag', 'tid', $value)
->fieldCondition('field_news_publishdate', 'value', $year. '%', 'like')
->range(0, 10)
->addMetaData('account', user_load(1)); // Run the query as user 1.

read more

Setting the maximum upload size or php memory for Drupal 7

Thu, 2013-03-28 10:46

There are 3 main ways to do this:
1) custom PHP.INI file
2) .htaccess
3) settings.php

I may come back and document the other 2 in this post at a later date but for now I will cover the custom PHP.INI approach.

I tend to use this approach in a hosting environment and becuase if you need additional memory to install drupal as is the case if you install a profile like Commerce Kickstart, then the changes set in the settings.php are not used until after the install.

First I create a blank file in the drupal directory called php.ini

read more

Charts and Graphs in Drupal 7

Wed, 2013-03-27 11:07

I have been struggling to find a solution to creating graphs from views in Drupal 7 for some time and recently while working on the SPARCS project and at long last I have done the hard work to get it going.

If you want to just create a simple graph easily, use the CHART module. This will use the google charts api and draw simple but many different graphs:
drush dl chart
drush en chart_views

read more

Restore a LVM image to LVM direct from gzip to LVM with a progress bar

Wed, 2013-03-20 10:35

By piping commands together you can save yourself the trouble of filling your harddisk with the uncompressed logical volume manager (LVM) image and pipe the image direct to a logical volume.
the LV is here: /dev/lg_storage/lv_harddisk (16 gigs)
the compressed image is: disk_backup.gz (2 gigs - 16 gigs uncompressed)
you have pv installed (apt-get install pv)

as root do:
pv disk_backup.gz | gzip -d | dd of=/dev/lg_storage/lv_harddisk
this will give you:
0.88GB 0:02:09 [84.41MB/s] [=========>              ] 41% ETA 0:04:30

read more

Check if port XXX is listening on your server

Tue, 2013-01-29 15:03

I use two approaches with the same tool, netstat.

sudo netstat --listen

this gives output like:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 *:webmin *:* LISTEN
tcp 0 0 *:ssh *:* LISTEN
tcp 0 0 localhost:postgresql *:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN

read more

Fix slow SSH response on your Ubuntu Server

Tue, 2013-01-29 10:43

By default, ubuntu will force each connection to have a reverse-dns lookup before establishing the session, this is great when doing a forensic audit of which IP address/FQDN logged into your server, but for day to day internal lan use, this added security measure is a PITA when you dont have a reverse dns as all it does is delay the establishment of the SSH session.

read more

Things i like to do to Ubuntu to make it rock.

Wed, 2013-01-23 11:11

This post will be an ongoing work:

I like to have a few standard tools I like to use:
sudo apt-get install nano mc htop

I also like the desktop to default to list view not icons:
In nautilus, go to Edit -> Preferences and select "list view", instead of "icon view" (in the "default view" section).

Find and eliminate rogue or ghost KVM Virtual machines under Cloudmin

Fri, 2013-01-18 14:59

I simply love managing my KVM virtual machines on ubuntu using cloudmin. But if you are like me you will have renamed a few virtual machine hostnames before you realize that doing so can orphan the VM processes under cloudmin and that these rogues will persist even after a reboot, or even a reinstall.

read more

Force Ubuntu to get a DHCP Lease

Fri, 2013-01-18 09:05

Sometimes when you are altering the network interfaces in your computer, or in a virtual machine, you find you need to force the client to request a new lease from the DHCP server, you can do this with the command (Replace eth0 with your interface):
sudo dhclient eth0

Adding and removing PPA repositories to ubuntu

Thu, 2013-01-17 10:57

To add a repo:
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable

to remove a repo:
sudo apt-add-repository --remove ppa:ubuntugis/ubuntugis-unstable

Connect to your postgres DB over an SSH tunnel proxy

Thu, 2013-01-17 09:28

So in this case, you are on a machine that has pgadmin3 but you want to connect to a database over an SSH connection, if you already have the SSH working, the rest is simple. Localhost is the machine you are on and is the ip of the remote db

What we have to do is ssh into a machine at the office, then use a tunnel over
ssh to forward a port to the database.

ssh -L5555:localhost:5432 username@
Then connect using:
psql -h localhost -p 5555 -d dbname -U username

read more

Upgrading an Old or End of life (EOL) release of ubuntu back into usefulness.

Wed, 2013-01-16 13:26

If you find yourself with an old version of ubuntu that is unable to update or upgrade, the solution is very simple.

For example, if you are running Ubuntu 10.10 (Maverick Meerkat) and you want to upgrade it

Ubuntu maintains a repo for this so open your sources file in the terminal with:
sudo nano /etc/apt/sources.list

then comment out all your repos, and use this(substitute maverick with the old code of your outdated ubuntu):

## EOL upgrade sources.list
# Required
deb maverick main restricted universe multiverse

read more

Watch the progress of dd - no kidding.

Wed, 2012-11-14 12:11

Ok, i did not even know this was possible but it works great and makes a painful tool painless to use.

As you know DD is an intense all consuming process that tends to slow everything down and tell you nothing while it works. This means you are left to guess when it will be done what its doing,and usually this is a long time.

This little solution works great, but requires some terminal mojo and some confidence to perform.

what you need is the PID (process ID) of your dd operation. so lets assume you know how to use ps, top or htop or equivalent to determine the PID

read more