header

Thingy Ma Jig Blog

Syndicate content Some Rights Reserved
Updated: 6 hours 3 min ago

Exporting a Git Repository

15 December 2011 - 5:14pm
drupal, git and webdev

Have you ever needed or wanted to pull a remote Git Repository on Drupal.org down as a zip or tarball? You know, the way Github does? Most project releases have fairly recently built tarballs which is awesome - but Sandboxes do not (so it seems - please correct me if I'm wrong!).

The following snippet lets you "archive" a remote repository, pull it down as a tarball, and extract it in-place:

git archive --format=tar --prefix=PROJECT/ --remote=USERNAME@git.drupal.org:sandbox/USERNAME/123456789.git BRACH | tar -xf -

Some important notes:

  • The prefix is very important - without it, tar extracts to the current folder.
  • The number (next to .git) references the sandbox Node ID.

I have tried using the "zip" format, however the unzip bash command doesn't accept stdin as a source. It looks like funzip might hold some promise thought…


Quick Tip: Drupal Hook Commenting Using Vim

14 November 2011 - 6:50pm
vim, drupal and programming

According to the Drupal Coding Standards for Documenting Hook Implementations, its considered a good practice to quickly chuck a comment before any function which implements a Drupal hook (eg, hook_menu). This helps someone reading your code quickly see that the function is actually linked with a hook in Drupal and isn't just a function in your module to be called directly.

But… Well… The thing is… Does anyone else get bored of writing the following over and over again? I know do…

/** * Implements hook_menu(). */

Wouldn't it be nice if you could just type in "menu" and Vim could just fill it our for you? Here follows a little Vim script for inserting a "hook implements" comment at the current cursor position. function! DrupalImplementsComment(hook) set paste   exe "normal! i/**\<CR>" \ . " * Implements hook_" . a:hook . "()\<CR>" \ . " */\<Esc>"   set nopaste endfunction   map <C-C><C-C><C-C> :call DrupalImplementsComment(input("Enter Hook name:"))<CR>

Wherever your cursor is, press Ctrl+C 3 times, you then get prompted to enter the hook name. When you press enter, a comment gets inserted. Hopefully this will save someone some time - its already saving me time!

To install the script, I just have it in a file called DrupalCommenting.vim inside my ~/.vim/ folder. Then, inside my ~/.vimrc file, I have a line which imports the source file, eg: so ~/.vim/DrupalCommenting.vim.

Any improvements very welcome!


JQuery Table Sorter Bookmarklet

25 October 2011 - 10:49am
javascript, programming, webdev and jquery

Christian Bach has made an awesome JQuery plugin to turn any HTML Table into a real-time sortable table using Jquery. I recently needed to turn this into a Bookmarklet so that I could embed it onto a page to sort a large table (I did not have access to the server-side code for this table).

If you drag the following link into the bookmarks toolbar of your browser, you can turn any table on any website into a sortable table!


Table Sorter Bookmarklet