Tuesday, April 5, 2011

Fixing iChat GoogleTalk (gchat) connection issues.

iChat kept dropping my two Google chat accounts so I did some of my own Googling for a fix:

Create a script to reconnect iChat.


I created a file '~/dev/ichat-reconnect.sh':


#!/usr/bin/osascript


if appIsRunning("iChat") then
 tell application "iChat"
        if status is offline then
            log in
        end if
        set originalStatus to the status message
    end tell
end if


on appIsRunning(appName)
 tell application "System Events" to (name of processes) contains appName
end appIsRunning


Create a LaunchAgent


LaunchAgents are the OSX equivalent of cron jobs.

In the folder ~/Library/LaunchAgents/ I created a file 'com.ichat.reconnect.plist':


<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>label</key>
    <string>com.ichat.reconnect</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/gcoller/dev/ichat-reconnect.sh</string>
    </array>
    <key>OnDemand</key>
    <false/>
    <key>Nice</key>
    <integer>1</integer>
    <key>StartInterval</key>
    <integer>5</integer>
    <key>StandardErrorPath</key>
    <string>/tmp/AlTest1.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/AlTest1.out</string>
  </dict>
</plist>


Basically it means run my ichat-reconnect.sh script every 5 seconds.

Tell launch agent about your file


Issue the command:

launchctl load com.ichat.reconnect.plist

To get it started. It will start automatically on reboots.

Thursday, March 17, 2011

Intellij IDEA: Key command for right-click context menu

Ever wanted that right-click menu without having to touch the mouse when using IDEA?

Note: This is for OS X, probably is available for Windows.

Turns out to be easy enough:
1) Open KeyMap in Settings
2) Find "Show Context Menu" in the "Other" folder
3) Assign it a key (I used F13 since it is easy to find and available)

Wednesday, January 5, 2011

Groovy to Scala: Closures

Defining a closure that takes two variables and returns a String.

Groovy:
{ x, y -> ...}

Scala:
(x:Stirng, y:String):String => { ... }

Note, Scala requires types for values x and y.

Groovy to Scala: Regular Expressions

Coming to Scala from Groovy/Java. Scala seems to have a bit more overhead in learning basic concepts so I'm planing on keeping my notes here in a series of short posts. This is not meant by any means to be comprehensive but just a "hello world" for each topic that I wish I had.

Regular Expressions:

Defining: Just add a ".r" after a normal string:

val regEx = "apple*".r

Using: Use in a typical Scala match statement:

val name = ....
name match {
  case regEx => // do your processing here
  case entry => // like default, possibly throw an error
}

Grouping:

val zipMatch = "(\\d+)-(\\d+)"
val zip = "12345-1234"
zip match {
  case regEx(num1, num2) => // num1 == 12345, num2 == 1234
  case entry => // do nothing
}