Tuesday 21 December 2010

mysql dumping via an ssh tunnel

First , connect to the remote mysql instance via an ssh tunnel on port 10000

ssh -f -N -L 10000:localhost:3306 remoteuser@remoteserver

Try out the connection via the mysql client

mysql -u remote_sql_user --password=remote_sql_pass -h 127.0.0.1 -P 10000 remote_db_name

Type "show databases" , and you should see a list of databases available on the remote sql instance.

To dump out a database locally, quit the mysql client, and type :

mysqldump --host=127.0.0.1 --port=10000 --user=remote_sql_user ==password="remote_sql_pass" --verbose > /your_local_directory/name_of_db.sql


For very large db dumps, it is faster to use zcat & gzip, then pipe to mysql :

gzip name_of_db.sql

zcat name_of_db.sql.gz | mysql -u local_sql_user --password=local_sql_pass --database=name_of_db

Friday 17 December 2010

Convert m4a to mp3

Via the Debian Linux Desktop survival guide


Using faad, convert the m4a to wav:
$ faad -o abc.wav abc.m4a

Yes you read that right - faad has output as the first option, and input as the second option.

Then using lame convert wav to mp3. Bitrate is specified with the "-b" option.
$ lame -h -b 192 abc.wav abc.mp3

You can combine this into a script that will convert all m4a's in a directory into mp3s
for i in *.m4a
do
faad -o - "$i" | lame -h -b 192 - "${i%m4a}mp3"
done

Thursday 16 December 2010

Git cheatsheets

Git cheat sheets via Github

Check status of your repo: git status
Committing: git commit -m "First import
Update local : git pull

See what files have been committed: git ls-files
Remove file:git rm [filename]
Add file to next commit: git add [file name]
Commit all changes to repo: git commit -a
Commit plus message :git commit -m "Message"

View log of your commits: git log
View your commits + graph : git log --stat
Log with pagination: git log -v

Create new tag , push to remote branch:
git tag "v1.3"
git push --tags

Create new branch : git branch [name of your new branch]

Pull new branch from remote repo: git fetch origin [remote-branch]:[new-local-branch]

View branches: git branch

View list of all existing branches: git branch -a

Thursday 9 December 2010

Changing page.tpl based on node type

Via here

If you use Drupal you may encounter the difficulty in setting up individual page.tpl.php for different node types. The is a simple solution to this problem but requires a few lines of code in your template.php file, found in your theme directory (/sites/all/themes/).

To begin:
Locate your template.php file in your theme directory.
At the bottom of your template.php file enter the following code:

function phptemplate_preprocess(&$vars, $hook) {
switch ($hook){
case 'page':
// Add a content-type page template in second to last.
if ('node' == arg(0)) {
$node_template = array_pop($vars['template_files']);
$vars['template_files'][] = 'page-' . $vars['node']->type;
$vars['template_files'][] = $node_template;
}
break;
}
return $vars;
}
The customizations can be seen in Devel along the lines of
page-node-1.tpl.php -> page-story.tpl.php -> page-node.tpl.php -> page.tpl.php.

If you have to use the forums feature of Drupal you may want to prevent a name clash by implementing:
$vars['template_files'][] = 'page-nodetype-' . $vars['node']->type;
instead of 
$vars['template_files'][] = 'page-' . $vars['node']->type;

Custom template for nodes of type "page"

A common query is :

if i want to override page.tpl for nodes of type "page" what is the name is the tpl file I should use - node-page.tpl.php or page-node.tpl.php?

Theme Developer module to the rescue (available here) : the answer is :

page-node.tpl.php

Friday 3 December 2010

Gpanels and Adaptivetheme - creating a two column section for blocks

Video tutorial over here

Gpanels are easy to use PHP and HTML snippets for creating multi column layouts. The idea is you copy/paste them into page.tpl.php (where ever you want) and place blocks into the regions to create columns of blocks.

Gpanels come with both Adaptivetheme and the Genesis starter theme.

This video walks you through the process of adding a Gpanel, enabling the regions and CSS, and then placing the blocks in the newly available regions.


Gpanels & Adaptivetheme: Create a 2 column section for blocks from Adaptivethemes on Vimeo.

Friday 26 November 2010

Drush makefile - installing dev versions of module

Normally in a drush make file modules to be installed are referenced by their module name e.g.
projects[]=cck


This will installed the recommended release of cck. If you want the development release, which is more recent, change the makefile entry to:

projects[cck][version]=2.x-dev


You can find the specific version of a module you are using by looking at its .info file.

Note that in your info file the version will appear with the Drupal version in front of it , like so:
version = "6.x-2.x-dev"


Just remove the "6.x-" part in front when building your makefile.

Thursday 25 November 2010

Drush blogposts

Drupal deployments with Drush Make & Aegir

Installing Drush Make

Drush Make is a very cool drush extension that allows you to automate the installation of a Drupal instance , including the downloading of modules, jquery libraries and lots more , all of which can be defined in a "make" file.


In order to get this running i placed the drush_make folder from the tar ball in my
.drush folder under my home directory - the full path being .drush/drush_make

Obviously your mileage may vary , but this worked for me.

Place your makefile in an empty site folder and just type

drush make mynewsite.make

Drush - installing jQuery UI

from your drupal root:

cd sites/all/
mkdir libraries
cd libraries
wget http://jquery-ui.googlecode.com/files/jquery.ui-1.6.zip
unzip jquery.ui-1.6.zip
mv jquery_ui
cd ../../../../
drush en jquery_ui

Drush - find module names quickly

If I have a lot of modules , scrolling through the output of drush sm isn't very productive.

If you are looking for say the "Node Reference" module you can quickly find it's drush sm output by typing:

drush sm | grep "Node Reference"

output:
CCK Node Reference (nodereference) Module Not installed 6.x-2.x-dev

It's name is "nodereference" , so to enable it just do

drush en nodereference

Drush - enabling modules with a space in their name

Problem: Within CCK there is a module called "Content Copy".

drush en "content copy" returns an error. How do I install a module with a space in it's name?


Answer: Use drush sm to list the available modules in your drupal instance.

In the "Name" column of the output generated you will see

Content Copy (content_copy)

in the CCK section.

Therefore the drush command is:

drush en content_copy

Drush - installing CCK

Problem: drush en cck will installed the approved cck release, but not the dev version. How do I install the dev version?


Answer: drush en cck-6.x-2.x-dev

This will install the latest dev version. But when it comes to enabling CCK the syntax is somewhat different - remember that "cck" is not a module , its a package of modules, with the core of it being the "content" module.

Therefore to enable CCK , the drush command is

drush en content

Features Links

Main docs
Features Module
Getting Started with Features
Readme.txt (Revision 1.1.2)
API.txt (Rev 1.1.2)
features.api.php (rev 1.1.2)
Bug Reports
Issues


Other docs
Introducing Features - Development Seed, May 2009
Scared of Features? Don't Be
Features Module abridged