ThingyMaJig

Thingy Ma Jig is the blog of Nicholas Thompson and contains any useful tips, sites and general blog-stuff which are considered interesting or handy!

Connect

LinkedIn GitHub

Topics

announcement 25 apache 3 Apple 1 bash 8 code 7 cool 30 Days Out 8 Dark Basic Pro 4 design 12 doctor who 1 Drupal 74 E4600 1 EOS 400D 3 firefox 2 Flickr 3 free 21 games 5 geek 38 git 2 GreaseMonkey 1 hardware 7 Homebrew 1 How to 37 humour 5 iphone 1 javascript 1 jquery 1 K800i 6 k850i 4 lighttpd 3 linux 33 mac 9 miscellaneous 4 mobile phone 9 music 4 mysql 8 n73 1 n95 1 New Relic 1 Ogre3D 1 OS X 2 performance 3 photos 10 programming 40 Quicksilver 1 review 19 security 3 SEO 6 software 12 svn 2 technology 4 tip 7 tips 10 tv 3 video 3 vim 7 webdev 2 websites 33 wii 1 windows 1 YADS 10

linux

Linux is a great OS, don't you think? I know I do - and here is a list of stuff about linux such as tips on use and useful software.

How to run Drush as Apache

10 August 2012
Drupal linux

It's usually considered best practice to run Drush under the same user account that the webserver runs on. Some modules, such as XML Sitemap, Advanced Aggregator and cTools, often try to alter or generate files. If you run Drush under your own account then these files may get generated as you (and therefore become unwritable by the webserver) or, if the files were generated by the webserver, are usually unwritable by your user which can mean you get errors and being unable to delete/unlink files.

How to get Load AVG for remote server on loop

11 May 2011
bash linux How to

This handy script will allow you to get the current Load Average (loadavg) for a remote server over SSH. It will stream the result set back to you, which you can then pipe into a file if you need to.

This would be handy for monitoring the load of a server while stress testing, for example.

Fixing Dos Line Endings

25 November 2010
tips linux How to geek code Drupal

Sometimes, when you're running coder on a module, you'll get a lot of errors complaining about Windows line endings. This is because you should set your editor to use Unix Line endings to be consistent with all developers. See the Drupal Coding Standards for more details.

Below is a handy bash script which will help you batch convert many files from DOS to Unix line endings.

Generate Entropy for GnuPG

22 January 2010
security linux geek

Has anyone every tried to generate a GPG (or GnuPG) key? I have… and I received this error…

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 284 more bytes)

Patching can cause permission denied errors

11 August 2009
linux How to geek Drupal

I just updated this server to PHP 5.3. As all my sites are Drupal 6 it seems I have a few issues ahead which mean I need to patch Drupal to stop PHP complaining about deprecated stuff…

So I headed over to the post on drupal.org which is discussing 5.3 compatibility in Drupal 6 (which I personally think SHOULD go in) to grab a patch. I applied the patch with no problems. I refreshed a page and got a white screen so I checked the logs only to see…

Indenting in Vim

27 May 2009
vim linux How to

Ever had that situation where you've enabled :set paste and pasted in hundred of lines of code into vim only to see it all fully left aligned? I just did… And bugger going over each line and manually indenting it! Want know how to indent a visual block of text?

How to use "sed" to find and replace

26 May 2009
tip linux How to bash

After Worldpay recently changed to use the RBS system, I was tasked with finding every instance of select.worldpay.com/wcc/purchase in our forms and replacing it with select.wp3.rbsworldpay.com/wcc/purchase. There appeared to be thousands of files and I wasn't going to do it manually…

Backing up a Drupal Database: Redux

27 April 2009
tip linux How to geek Drupal code bash

Back in November last year, I wrote a script which handled backing up a drupal database. There were quite a few comments and I've taken some on board and developed the script on a little further to be more "generic".

One of the main complaints/suggestions about my previous snippet was the hard coded nature of it. The follow script offers far more configuration through the command line itself.

I'm a lazy linux piper

11 March 2009
tip svn linux How to geek Drupal

This morning I updated a site to the latest release of Drupal 5.16. Nothing special there at all. I’ve done that many times as has (hopefully) mabye other drupal devs… However, I’m a bit of a newbie when it comes to SVN. Didn’t I mention this drupal site was in an SVN repository? ;-)

Neat commenting in Vim

12 January 2009
vim programming linux Drupal

I am a bit of a "neat geek" when it comes to coding. Things should be indented neatly and should have well laid out comments! Why? Well… It's easy to do and in 6 months time when you look at your code you will appreciate it! It will also me even more appreciated by another developer in less than 6 months time ;-)

Finding the largest files in a folder

06 January 2009
linux How to geek bash

I just needed to find the largest files in a folder (in an attempt to find out why it was so bloody huge!) and have ended up with the following handy combination of commands…

find /path/to/folder -size +1M -print0 | xargs -0 du -h | sort -nr

OpenSuse 11.0 Issues

12 December 2008
linux How to geek

After about 4 days of using OpenSUSE 11.0, I'm not overly impressed with it in comparison to RedHat Enterprise 3/4/5, CentOS 5, Fedora 9 and Ubuntu 8.x (other distro's I've used). OpenSUSE has some annoying habits and default/unusual configurations…

Backing up a Drupal Database

26 November 2008
tip linux How to geek Drupal code bash

I was just dumping a database using mysqldump and I noticed that tables such as cache (and its cousins cache_page, cache_menu, etc), sessions and watchdog can be pretty big and are also not often essential for backing up. I mean, when you restore your web site do you really care about restoring people's logged in sessions from when the backup took place? I can understand maybe keeping watchdog; but then again should you lose your site you would probably lose it several hours after the backup so would miss out on any relevant watchdog notices.

Anywho… I did a mysqdump for a large database for a website I maintain and the dump came out at 400Mb. I then spent a few minutes cobling together a small script which would do a mysqldump but had some pre-programmed Regular Expressions to match specific groups of tables which it would only dump the structure for (ie, no data). After running this script, the SQL dump was only 220Mb. Much better! It also runs considerable quicker too and will cause less table locking.

So - the script?

SVN + NFS = svn nfs cant get exclusive lock

25 November 2008
svn programming linux How to geek

Last night I was trying to configure SVN on a server. The setup was that the SVN Repo was on "srv2" and the frontend and code I wanted to import was on "srv1".

I created an NFS share on srv2 and mounted it on srv1 in /mnt/svnroot. The mount worked perfectly and I could touch and remove files from srv1.

So I tried to create a "sites" folder where I wanted to import a site I wanted to version control. This is where I started to have problems… The sollution was to add "nolock,bg" to the mount options on the client. Read on for more details!

List enabled services in Linux

21 November 2008
linux How to geek

Today I needed to list all of the services which were enabled on boot-up for one of the servers I maintain. Obviously, my first port of call was to use the nifty tool ChkConfig like so…

Vim and Drupal Modules

18 August 2008
vim programming linux geek Drupal

I just finished upgrading a server to Ubuntu 8.04 which came with Vim 7.1 rather than 6.3 on the older server. It seems 7.1 does things slightly differently to 6.3.

In 6.3 I could create ~/.vim/filetype.vim and in there define a line as follows:

au BufRead,BufNewFile *.module,*.install,*.theme setf php

However in 7.1, it looks like a line similar to this has to go into ~/.vimrc instead…

Removing trailing spaces with vim

16 July 2008
vim linux Drupal

After recently reading about how great VIM is for the three hundredth and fifty second time (I kept count), I decided to take a look.

It really is quite cool! I've also decided to try to log any cool tips I learn about it. Here is the first which I found after running the coder module on one of my modules (Page Title 2) and it threw hundreds of errors about too many trailing spaces on empty lines.

How to batch rename files

19 April 2008
mac linux geek bash

This afternoon I needed to rename a bunch of files from one form to another in a command shell… Well technically I didn't need to do it in a shell - but, as sure as there is a hole in my ass, I wasn't gonna go through renaming them all manually!

They needed to go from, for example, add.png to add_32.png. After a little research into commands like printf, awk, bison and so on - I suddenly realized that 'cut' held the key!

Powered by Lighttpd

16 April 2008
linux lighttpd Drupal

This blog is now no longer powered by Apache (the feature filled but slightly bloated beast), instead I have decided to give Lighttpd (pronounced Lighty) a whirl.

What convinced me? Ages ago I read an article by Dries Buytaert comparing webserver configurations. It was shocked to see that Lighttpd appeared to be able to serve almost twice as many pages per second as Apache. There is also the advantage that a static file will only cost you substantially less memory to serve in Lighty than it will in Apache due to Apache bundling ALL the mods into every process.

So what is Lighttpd? The inventors describe it perfectly…

The price of sucess - too many users!

25 October 2007
programming linux geek Drupal cool apache

Recently at work we had been having issues with spiking server load. One of the potential suspects was the Apache configuration as it was allowing 256 MaxClients. Combine that with Drupal eating RAM for breakfast (say a minimum of 12Mb per page) and you have a recipe for disaster - too many visitors cause a RAM shortage, lots of swapping and eventually a server meltdown. After speaking the Rackspace Technical Support Team, one of the guys there (Daniel) wrote a VERY useful script for us to run on the server to monitor Apache usage.

Getting the most out of Fedora Core 4

28 September 2007
websites software linux How to geek Drupal

I recently looked into which versions of software I was running and was a little concerned to see how backward Fedora Core 4 was in some areas. I did a little Googling around and found a website (http://remi.collet.free.fr/) which is predominately written in French (but has a few English translations) which provides a new repository for Fedora Core 4's Yum Installer Package which provides far more recent RPM's for the likes of PHP and MySQL... So I installed it!

Force a PDF to download

06 August 2007
software programming linux cool apache

I recently needed to force a PDF to download using Apache. The default behaviour for most browsers is to try to open the PDF inside the browser itself. This is fine for a small PDF or for powerful machines - but a large PDF on even a modest machine can often lock the browser up. This needed fixing!

After 20 minutes of perusing the Apache documents, I happened across the FilesMatch option which takes Regular Expressions. Regular Expressions are cool things which pattern match; you give it a rather complicated (yet logical) pattern and it matches it for you. Initially I used something like this...

Which modules use hook_cron?

14 May 2007
programming linux geek Drupal cool

I recently needed to find out a list of modules which used hook_cron. I have SSH access to my server. Instead of writing a module (or using devel to execute some PHP) which returned the result of module_implements, I turned to grep. Simply cd into your modules folder (can be the Drupal install, but you end up recursing through unlikely folders) and run this:

grep -R "^function.*_cron" *module

How to SCP a path with spaces

14 May 2007
mac linux How to geek

I recently needed to remotely copy over SSH a folder from the remote machine to my local machine. Usually this is not a problem, however the path to this folder had a space in it. The folder itself is rather large and contains files which wouldn't really benefit from compression. It turns out the solution was quite simple.

YAFC as an FTP Client

02 February 2007
review linux How to

Firstly - YAFC? "What on earth is YAFC?" I hear you say. YAFC is a command line FTP tool which, unfortunately, only comes in source code which means you need to know how to compile it. Fortunately, compiling it is easy - it required very few dependencies and most of those I could install using yum on my linux box (Redhat Fedora).