Monday, February 27, 2012

Monday, February 6, 2012

Organize your downloads, the OS X way

If you are one of these guys who move files and organize them manually under the correct directory, this blog post isn't for you.
I usually download lots of files and I keep trying to cleanup my Downloads folder in so many ways. First, I configured every application to download in its own folder so I had Firefox, iChat, Mail, etc...
This didn't really help. When the time comes to cleanup the Downloads folder, I usually need to delete very old downloads because I no longer need a software update from mid-2009.
So next I tried one of Firefox's extensions to organize my downloads and used Glims for Safari. The idea was to organize downloaded files in a directory hierarchy where I can identify older files and remove them.
The problem with that solution is that it didn't work for all the applications I use so I decided to write a script to do that for me.
Writing that script in Bash, PHP or Python is an easy job but I wanted to do it the Mac way so I created this AppleScript and attached it to the Downloads folder using Folder Actions in OS X.
Try it out:
http://gist.github.com/445641

Thursday, February 2, 2012

My .vimrc

My .vimrc:
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Start-up
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Use Vim settings, rather then Vi settings (much better!). 
set nocompatible 
" First clear any existing autocommands:
autocmd!
" have syntax highlighting in terminals which can display colours:
if has('syntax') && (&t_Co > 2)
 syntax on
 set hlsearch 
endif

" Filetype plugins
filetype plugin indent on

setlocal spell spelllang=en


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set history=1000
set viminfo=/10,'10,r/mnt/zip,r/mnt/floppy,f0,h,\"100
set wildmode=list:longest,full
set title
set showmode
set showcmd
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize

" Status line
set laststatus=2
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [ASCII=\%03.3b]\ [HEX=\%02.2B]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set modelines=3

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Text Formatting/Layout
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set backspace=indent,eol,start 
set formatoptions-=t
set textwidth=0
set isk+=_,$,@,%,#,- " These aren't word dividers
set incsearch " do incremental searching 
set ignorecase " Do case insensitive matching
set nosmartcase " No smart case matching
set smartindent   " smart indentation
" Tab settings
set expandtab
set showtabline=2
set tabstop=2 " tab stop 2 spaces
set shiftwidth=2
set shiftround

" Comments
set comments-=s1:/*,mb:*,ex:*/
set comments+=s:/*,mb:**,ex:*/
set comments+=fb:*

"set comments=s5:/**,mb5:*,ex:*/
"set comments=sr:/*,mb:**,ex:*/
"set comments+=fb:*

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Theme/Visuals
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set showmatch " Show matching brackets.
set background=dark
set foldmethod=indent
set foldlevel=50
set mouse=i " Enable mouse usage in Insert, View and Command line modes in terminals
set ruler " show the cursor position all the time 
set number " show line numbers

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" File Handling
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autowrite " Automatically save before commands like :next and :make
set nobackup " do not keep a backup file, use versions instead 
set noswapfile
if has("autocmd")

  " Enabled file type detection and file-type specific plugins.
  " filetype plugin on indent
  filetype plugin on

  " Drupal *.module and *.engine files.
  augroup module
    autocmd BufRead                     *.install,*.schema,*.inc,*.module,*.engine set filetype=php
  augroup END

  " Python code.
  augroup python
    autocmd BufReadPre,FileReadPre      *.py set tabstop=4
    autocmd BufReadPre,FileReadPre      *.py set expandtab
  augroup END

  " PHP code.
  augroup php
    autocmd BufReadPre,FileReadPre      *.php set tabstop=2
    autocmd BufReadPre,FileReadPre      *.php set expandtab
  augroup END

  " ANT build.xml files.
  augroup xml
    autocmd BufReadPre,FileReadPre      build.xml set tabstop=2
  augroup END

endif

" Set Drupal files as php syntax-like files
au BufNewFile,BufRead *.module,*.install,*.schema,*.inc set filetype=php


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PHP Specific Settings 
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" PHP Error check
set makeprg=php\ -l\ %
set errorformat=%m\ in\ %f\ on\ line\ %l

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cool Abbreviations
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" HTML
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Print an empty <a> tag.
map! ;h <a href=""></a><ESC>5hi
" Wrap an <a> tag around the URL under the cursor.
map ;H lBi<a href="<ESC>Ea"></a><ESC>3hi



"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Cool Shortcuts
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Some keymaps:
nnoremap <C-M> <Esc>:w<CR>   "Save
nnoremap <C-O> <Esc>:Texplore<CR>   "Show Explorer in a new tab
nnoremap <C-N> <Esc>:tabnew<CR>                    "CTRL+N to open a new tab
map <C-Right> <Esc>:tabn<CR>                    "CTRL+Down to view next tab
map <C-Left> <Esc>:tabp<CR>                    "CTRL+Up to view previous tab
no <C-E> <Esc>:mks! ~/.vimsession<CR>    "CTRL+E saves the current session to ~/.vimsession

" Don't use Ex mode, use Q for formatting 
map Q gq 
map q :q<CR>

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Explorer
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Make Explorer open files in new tabs
let g:netrw_browse_split=3

Push-any Git post-update hook

Maintaining multiple branches in Git is very easy. Maintaing multiple "remotes" in Git is very easy. The tricky part comes when you join both.

Unless you have a testing, staging and production server and you maintain a branch per-server, aka remote, then you need to git your hands dirty with some code.

The other day, I wanted to have a single remote for testing multiple branches and the web had half the answer with this script, but unfortunately, it doesn't checkout the branch you're pushing.

After few lines of code, I can now push multiple branches to a non-bare remote repository and have the post-update automatically checkout the branch I pushed and update the worktree, handy huh?

Code is here. Your comments are welcome.