Generic vim counters

I needed a way in vim config to use counters and what better way, but to write a function to simultaneously handle all variables and optinally increase or decrease them:

" define and manage counters
" NB! all counters are namespaced globally (g:)
function! Counter(name,...)
" check if this variable already exists or should we initialise it
  if !exists("g:" . a:name)
    exec 'let g:'  . a:name .' = 0'
  endif
" if second parameter is given, increase/decrease value
  if a:0 > 0
    exec 'let g:'. a:name .' = g:' . a:name . ' + ' . a:1
  endif
  exec 'return g:' . a:name
endfunction

Usage of the function is as follows:

" Get the current value
echo Counter('mycount')
 
" Increase value by 1(and return the new value)
echo Counter('mycount', 1)
 
" Decrease value by 2
echo Counter('mycount', -2)

BetterTouchTool and Safari


Few days ago I switched to BetterTouchTool from MagicPrefs because (1) MP somehow blocked clicks when MagicMouse was disconnected and I always had to quit the MP. And (2) BTT lets me configure the trackpad too.

BetterTouchTool lets you define tons of gestures for your Macbooks Trackpad, your MagicMouse and your MagicTrackpad. In addition to that it brings lots of new stuff to MacOS like Windows 7 like window snapping, window switchers etc……

Extensive explanation is at the BTT developer’s blog.

I wanted to add a gesture (four-finger click) to bring up a new Safari window. BTT had Predefined actions to Open Application/File/Script… or Open URL. First of these unfortunately did not open new window, but instead activated one of the pre-existent windows (which I could do just by clicking the Safari Dock icon). The latter did bring up a new window, but I missed the chance to use Top Sites.

AppleScript to the rescue

So I typed four lines in AppleScript and now have an action to pop up new Safari window:

tell application "Safari"
	activate
	make new document
end tell

I saved this as an Application to the /Applications folder just for faster startup and pointed BTT Open Application action to that file. Viola!

Download the Safari New Window action.

MTS to MP4 converter

Following my previous post about iMovie and MTS I always had random trouble with my converter failing/hanging with some  MTS files. And when repeated for the same file – no problems. This way I couldn’t just set the converter to work with tens of files and go for a coffee – I always had to look for hangs and stop the process only to restart it again.

And after I had problems with QuickTime refusing to open the new .mov files and iMovie having no sound, I thought it to be prime time to revisit the script.
Read more »

Mac OS X 10.6.5 upgrade freed 2 GB

When Snow Leopard first game out, it was promised to cut back on the OS footprint (in Gigs).

Now, upgrading to 10.6.5, I somehow had insight to take screenshot of disk usage right before upgrading and comparing to the after shot:

Before:

Mac OS X 10.6.4

After:

Mac OS X 10.6.5

As you can see – it freed over 2 GB of disk space. Now this is what I call a good upgrade. Not only adding features and fixing bugs, but at the same time cutting back in bloat.

Note: my Time Machine reported 7.03 GB worth of changed data that needs to be backed up. So get some, loose some. But as my backup drive has lots of space while MacBook has little, I consider myself a winner.

Address Book groups

Some time ago I found a rather useful way to use my Address Book contacts – group them and when you type the name of the group in Mail.app address field, it is expanded to all the contacts. But the problem was that when a contact had multiple addersses, I could not determine which was to be used for the group automatically and if I wanted to write to a specific address I had to manually adjust, which I forgot rather often.

Edit Distribution List

Fortunately Address Book has a way to specify the default address for any group (or distribution list as it is called). Just right-click on one of the groups, as shown below and pick “Edit Distribution List…

Pick Edit Distribution List from options

Pick Edit Distribution List from options

Now a window pops up that shows you the entire list and all of the multiple addresses for each card. Just skim through the list and highlight in bold the default addresses which should be used automatically for this list:

Address Book Distribution List

Clik OK to save changes and your done.

iTunes, iPhoto and Migration Assistant

I migrated my MacBook to a new MacBook Pro 2010 release using Migration Assistant and just as many others, found that my iPhoto did not show any photos (only thumbnails) as well as iTunes did not show any music. The Finder did show the files though.

Don’t panic!

And don’t blame Migration Assistant for it. What has happened is that you are probably running older versions of iTunes and iPhoto (and probably OS X too for that matter) than you were at the other Mac. So, just run Software Upgrade (with restarts and everything) until it tells you that you are up to date. Then all should be well with iTunes and iPhoto too.

Credit: this tip was kindly pointed out by AndyField. Thanks!

Overfilled ZFS won’t delete files

Today I ran into a trouble when I had filled my ZFS filesystem and tried to free up some space:

$ rm boxroom-0.6.3.zip
rm: boxroom-0.6.3.zip: Disc quota exceeded

The same error was given for all kinds of rm options, recursive, force, etc.

Digging around, pointed me to this post and that B solution was excellent:

$ ls -larth boxroom-0.6.3.zip
-rw-r--r--  1 laas  wheel   344K Apr 19  2009 boxroom-0.6.3.zip
 
$ cat /dev/null > boxroom-0.6.3.zip
$ rm boxroom-0.6.3.zip

Though this only freed up 344 kilobytes, it was enough that I could remove the file itself and then move on to more bigger files to free up the needed space.

Note: It was pointed out to me that the ZFS filesystem was compressed, which would shed light on the whys of the problem, as modifying compressed structures might increase the size, whereas truncating is the only option to decrease it.

xdebug with XAMPP on Mac OS X

Xdebug logoI just upgraded my XAMPP to latest release and found myself trapped with no memory of how to install xdebug on a Mac with XAMPP.

Read more »

Git reset –merge

Or how to reset a merge commit?

If just after a merge commit you recognized that it was actually “git rebase” that you wanted to do, then your friend is:

git reset –merge 14c1d90c3e

where the target commit is the one preceding the merge.

But when reset is not an option?

But if you found the faulty merge after several other commits (or after pushing to remotes), resetting is not so good idea or won’t work at all. In that case refer to How to Revert Faulty Merge in the HowTo.

Vim unindenting comments

I was annoyed that Vim moved all comments to the beginning of the line the moment I entered # sign. Searching around first turned me to smartindent, but I found that was already off.

Then this vimtip shed the light on the monster:
http://vim.wikia.com/wiki/Restoring_indent_after_typing_hash

just add to your .vimrc:

set cinkeys-=0#

And you are good to go.