<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ted Naleid &#187; command line</title>
	<atom:link href="http://naleid.com/blog/category/command-line/feed/" rel="self" type="application/rss+xml" />
	<link>http://naleid.com/blog</link>
	<description>Groovy, Grails and OS X tips and tricks</description>
	<lastBuildDate>Wed, 16 May 2012 00:54:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Quick Shell Function to Bootstrap a Gradle Groovy Project</title>
		<link>http://naleid.com/blog/2012/02/29/quick-shell-function-to-bootstrap-a-gradle-groovy-project/</link>
		<comments>http://naleid.com/blog/2012/02/29/quick-shell-function-to-bootstrap-a-gradle-groovy-project/#comments</comments>
		<pubDate>Thu, 01 Mar 2012 03:57:39 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=571</guid>
		<description><![CDATA[Gradle is a great build tool. It&#8217;s easy to download and install. If you&#8217;re on a mac and have homebrew, it&#8217;s as easy as: brew install gradle It&#8217;s very easy to use with a little experience, but I find having a good starting place to base your work from can help. Here&#8217;s a quick function [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://gradle.org/" onclick="pageTracker._trackPageview('/outgoing/gradle.org/?referer=');">Gradle</a> is a great build tool.  It&#8217;s easy to <a href="http://gradle.org/downloads" onclick="pageTracker._trackPageview('/outgoing/gradle.org/downloads?referer=');">download</a> and install.  If you&#8217;re on a mac and have <a href="http://mxcl.github.com/homebrew/" onclick="pageTracker._trackPageview('/outgoing/mxcl.github.com/homebrew/?referer=');">homebrew</a>, it&#8217;s as easy as:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">brew <span style="color: #c20cb9; font-weight: bold;">install</span> gradle</pre></div></div>

<p>It&#8217;s very easy to use with a little experience, but I find having a good starting place to base your work from can help.</p>
<p>Here&#8217;s a quick function that I&#8217;ve got in my <code>.zshrc</code> to bootstrap a new groovy gradle project in the current directory (it should also work in in a .profile/.bash_profile/.bashrc).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> newgradle<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Creating files for new gradle project&quot;</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;&lt;</span>EOF<span style="color: #000000; font-weight: bold;">&gt;</span>.gitignore
<span style="color: #000000; font-weight: bold;">*</span>.un~
<span style="color: #000000; font-weight: bold;">*</span>.iml
<span style="color: #000000; font-weight: bold;">*</span>.ipr
<span style="color: #000000; font-weight: bold;">*</span>.iws
build
.gradle
EOF
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">&lt;&lt;</span>EOF<span style="color: #000000; font-weight: bold;">&gt;</span>build.gradle
apply plugin: <span style="color: #ff0000;">'groovy'</span>
apply plugin: <span style="color: #ff0000;">'idea'</span>
&nbsp;
repositories <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    mavenCentral<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
dependencies <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    groovy <span style="color: #ff0000;">'org.codehaus.groovy:groovy-all:1.8.6'</span>
    groovy <span style="color: #ff0000;">'org.apache.ivy:ivy:2.2.0'</span>
    testCompile <span style="color: #ff0000;">'junit:junit:4.10'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
task createSourceDirs<span style="color: #7a0874; font-weight: bold;">&#40;</span>description : <span style="color: #ff0000;">'Create empty source directories for all defined sourceSets'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&lt;&lt;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    sourceSets<span style="color: #000000; font-weight: bold;">*</span>.allSource.srcDirs.flatten<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.each <span style="color: #7a0874; font-weight: bold;">&#123;</span> File sourceDirectory -<span style="color: #000000; font-weight: bold;">&gt;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>sourceDirectory.exists<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
            println <span style="color: #ff0000;">&quot;Making <span style="color: #000099; font-weight: bold;">\$</span>sourceDirectory&quot;</span>
            sourceDirectory.mkdirs<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
idea <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    project <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        jdkName = <span style="color: #ff0000;">'1.6'</span>
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
EOF
&nbsp;
    gradle createSourceDirs
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">git</span> init
    <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-a1</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">find</span> src    <span style="color: #666666; font-style: italic;"># list all created assets</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>It creates a <code>build.gradle</code> file ready to work with java and groovy projects, including IDEA integration (just execute <code>gradle idea</code>).</p>
<p>This gives you all of the tasks necessary to compile, jar, test, and distribute your code.  For more information, check out the gradle docs on the <a href="http://gradle.org/docs/current/userguide/java_plugin.html" onclick="pageTracker._trackPageview('/outgoing/gradle.org/docs/current/userguide/java_plugin.html?referer=');">java</a>, <a href="http://gradle.org/docs/current/userguide/groovy_plugin.html" onclick="pageTracker._trackPageview('/outgoing/gradle.org/docs/current/userguide/groovy_plugin.html?referer=');">groovy</a>, and <a href="http://gradle.org/docs/current/userguide/idea_plugin.html" onclick="pageTracker._trackPageview('/outgoing/gradle.org/docs/current/userguide/idea_plugin.html?referer=');">idea</a> tasks.</p>
<p>It also creates all the necessary source directories for you and initializes a new git repository (with starting <code>.gitignore</code> file) for you to save your work.</p>
<p>You can easily tweak the <code>build.gradle</code> or <code>.gitignore</code> files to fit your needs.  If you don&#8217;t use git, you can either delete those lines, or subsitute the equivalent lines for the source control tool you use. These are just a good starting place for me.</p>
<p>Here&#8217;s the sample output from the script above:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> testapp
<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">cd</span> testapp
<span style="color: #000000; font-weight: bold;">%</span> newgradle                                                                   
Creating files <span style="color: #000000; font-weight: bold;">for</span> new gradle project
:createSourceDirs
Making <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>testapp<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>resources
Making <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>testapp<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>java
Making <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>testapp<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>groovy
Making <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>testapp<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>resources
Making <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>testapp<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>java
Making <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>testapp<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>groovy
&nbsp;
BUILD SUCCESSFUL
&nbsp;
Total <span style="color: #000000; font-weight: bold;">time</span>: <span style="color: #000000;">2.344</span> secs
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>testapp<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span>
.
..
.git
.gitignore
.gradle
build.gradle
src
src
src<span style="color: #000000; font-weight: bold;">/</span>main
src<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>groovy
src<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>java
src<span style="color: #000000; font-weight: bold;">/</span>main<span style="color: #000000; font-weight: bold;">/</span>resources
src<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>
src<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>groovy
src<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>java
src<span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>resources</pre></div></div>

<p>Then you&#8217;ve got all this gradle functionality ready to use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> gradle tasks                                                           
:tasks
&nbsp;
<span style="color: #660033;">------------------------------------------------------------</span>
All tasks runnable from root project
<span style="color: #660033;">------------------------------------------------------------</span>
&nbsp;
Build tasks
<span style="color: #660033;">-----------</span>
assemble - Assembles all Jar, War, Zip, and Tar archives.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles the main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles the <span style="color: #7a0874; font-weight: bold;">test</span> classes.
&nbsp;
Documentation tasks
<span style="color: #660033;">-------------------</span>
groovydoc - Generates Groovydoc API documentation <span style="color: #000000; font-weight: bold;">for</span> the main <span style="color: #7a0874; font-weight: bold;">source</span> code.
javadoc - Generates Javadoc API documentation <span style="color: #000000; font-weight: bold;">for</span> the main <span style="color: #7a0874; font-weight: bold;">source</span> code.
&nbsp;
Help tasks
<span style="color: #660033;">----------</span>
dependencies - Displays the dependencies of root project <span style="color: #ff0000;">'test'</span>.
<span style="color: #7a0874; font-weight: bold;">help</span> - Displays a <span style="color: #7a0874; font-weight: bold;">help</span> message
projects - Displays the sub-projects of root project <span style="color: #ff0000;">'test'</span>.
properties - Displays the properties of root project <span style="color: #ff0000;">'test'</span>.
tasks - Displays the tasks runnable from root project <span style="color: #ff0000;">'test'</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>some of the displayed tasks may belong to subprojects<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
&nbsp;
IDE tasks
<span style="color: #660033;">---------</span>
cleanIdea - Cleans IDEA project files <span style="color: #7a0874; font-weight: bold;">&#40;</span>IML, IPR<span style="color: #7a0874; font-weight: bold;">&#41;</span>
idea - Generates IDEA project files <span style="color: #7a0874; font-weight: bold;">&#40;</span>IML, IPR, IWS<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
Verification tasks
<span style="color: #660033;">------------------</span>
check - Runs all checks.
<span style="color: #7a0874; font-weight: bold;">test</span> - Runs the unit tests.
&nbsp;
Other tasks
<span style="color: #660033;">-----------</span>
cleanIdeaWorkspace
createSourceDirs - Create empty <span style="color: #7a0874; font-weight: bold;">source</span> directories <span style="color: #000000; font-weight: bold;">for</span> all defined sourceSets
&nbsp;
Rules
<span style="color: #660033;">-----</span>
Pattern: build<span style="color: #000000; font-weight: bold;">&lt;</span>ConfigurationName<span style="color: #000000; font-weight: bold;">&gt;</span>: Assembles the artifacts of a configuration.
Pattern: upload<span style="color: #000000; font-weight: bold;">&lt;</span>ConfigurationName<span style="color: #000000; font-weight: bold;">&gt;</span>: Assembles and uploads the artifacts belonging to a configuration.
Pattern: clean<span style="color: #000000; font-weight: bold;">&lt;</span>TaskName<span style="color: #000000; font-weight: bold;">&gt;</span>: Cleans the output files of a task.
&nbsp;
To see all tasks and <span style="color: #c20cb9; font-weight: bold;">more</span> detail, run with --all.
&nbsp;
BUILD SUCCESSFUL
&nbsp;
Total <span style="color: #000000; font-weight: bold;">time</span>: <span style="color: #000000;">4.871</span> secs</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2012/02/29/quick-shell-function-to-bootstrap-a-gradle-groovy-project/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Finding and Purging Big Files From Git History</title>
		<link>http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history/</link>
		<comments>http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 06:58:13 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=566</guid>
		<description><![CDATA[On a recent grails project, we&#8217;re using a git repo that was originally converted from a SVN repo with a ton of large binary objects in it (lots of jar files that really should come from an ivy/maven repo). The .git directory was over a gigabyte in size and this made it very cumbersome to [...]]]></description>
			<content:encoded><![CDATA[<p>On a recent grails project, we&#8217;re using a git repo that was originally converted from a SVN repo with a ton of large binary objects in it (lots of jar files that really should come from an ivy/maven repo).  The <code>.git</code> directory was over a gigabyte in size and this made it very cumbersome to clone and manipulate.</p>
<p>We decided to leverage git&#8217;s history rewriting capabilities to make a much smaller repository (and kept our previous repo as a backup just in case).</p>
<p>Here are a few questions/answers that I figured out how to answer with git and some shell commands:</p>
<h4>What object SHA is associated with each file in the Repo?</h4>
<p>Git has a unique SHA that it associates with each object (such as files which it calls blobs) throughout it&#8217;s history.</p>
<p>This helps us find that object and decide whether it&#8217;s worth deleting later on:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> rev-list <span style="color: #660033;">--objects</span> <span style="color: #660033;">--all</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-k</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">&gt;</span> allfileshas.txt</pre></div></div>

<p>Take a look at the resulting <code>allfileshas.txt</code> file for the full list.  </p>
<h4>What Unique Files Exist Throughout The History of My Git Repo?</h4>
<p>If you want to see the unique files throughout the history of your git repo (such as to grep for .jar files that you might have committed a while ago):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">    <span style="color: #c20cb9; font-weight: bold;">git</span> rev-list <span style="color: #660033;">--objects</span> <span style="color: #660033;">--all</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-k</span> <span style="color: #000000;">2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span> -d\  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">uniq</span></pre></div></div>

<h4>How Big Are The Files In My Repo?</h4>
<p>We can find the big files in our repo by doing a <code>git gc</code> which makes git compact the archive and stores an index file that we can analyse.</p>
<p>Get the last object SHA for all committed files and sort them in biggest to smallest order:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> <span style="color: #c20cb9; font-weight: bold;">gc</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">git</span> verify-pack <span style="color: #660033;">-v</span> .git<span style="color: #000000; font-weight: bold;">/</span>objects<span style="color: #000000; font-weight: bold;">/</span>pack<span style="color: #000000; font-weight: bold;">/</span>pack-<span style="color: #000000; font-weight: bold;">*</span>.idx <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #ff0000;">&quot;^\w+ blob\W+[0-9]+ [0-9]+ [0-9]+$&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-k</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-n</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">&gt;</span> bigobjects.txt</pre></div></div>

<p>Take that result and iterate through each line of it to find the SHA, file size in bytes, and real file name (you also need the allfileshas.txt output file from above):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">for</span> SHA <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span> -d\  <span style="color: #000000; font-weight: bold;">&lt;</span> bigobjects.txt<span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$SHA</span> bigobjects.txt<span style="color: #7a0874; font-weight: bold;">&#41;</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$SHA</span> allfileshas.txt<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1,$3,$7}'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> bigtosmall.txt
<span style="color: #000000; font-weight: bold;">done</span>;</pre></div></div>

<p>(there&#8217;s probably a more efficient way to do this, but this was fast enough for my purposes with ~50k files in our repo)</p>
<p>Then, just take a look at the bigtosmall.txt file to see your biggest file culprits.</p>
<h4>Purging a file or directory from history</h4>
<p>Use filter-branch to remove the file/directory (replace <code>MY-BIG-DIRECTORY-OR-FILE</code> with the path that you&#8217;d like to delete relative to the root of the git repo:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> filter-branch <span style="color: #660033;">--prune-empty</span> <span style="color: #660033;">--index-filter</span> <span style="color: #ff0000;">'git rm -rf --cached --ignore-unmatch MY-BIG-DIRECTORY-OR-FILE'</span> <span style="color: #660033;">--tag-name-filter</span> <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #660033;">--</span> <span style="color: #660033;">--all</span></pre></div></div>

<p>Then clone the repo and make sure to not leave any hard links with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #660033;">--no-hardlinks</span> <span style="color: #c20cb9; font-weight: bold;">file</span>:<span style="color: #000000; font-weight: bold;">///</span>Users<span style="color: #000000; font-weight: bold;">/</span>yourUser<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>full<span style="color: #000000; font-weight: bold;">/</span>repo<span style="color: #000000; font-weight: bold;">/</span>path repo-clone-name</pre></div></div>

<p>You can use this command from the parent directory that contains your git repository and it&#8217;s clone to see how much space each of them take, and how much you&#8217;ve shrunk the repo in size:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>     <span style="color: #666666; font-style: italic;"># add the -h flag to see the output in human readable size formats, just like ls -lah vs ls -la</span></pre></div></div>

<p>With these commands, I was able to reduce the file size of our repo with a few thousand commits down below the size of the checked out repository (more than an order of magnitude smaller).  I only removed old binary files, we still have full history for all code files.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to use kdiff3 as a 3-way merge tool with mercurial, git, and Tower.app</title>
		<link>http://naleid.com/blog/2012/01/12/how-to-use-kdiff3-as-a-3-way-merge-tool-with-mercurial-git-and-tower-app/</link>
		<comments>http://naleid.com/blog/2012/01/12/how-to-use-kdiff3-as-a-3-way-merge-tool-with-mercurial-git-and-tower-app/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 06:29:08 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=523</guid>
		<description><![CDATA[There are a few very nice looking, mac-like diff tools for OSX (Kaleidoscope and Changes come to mind), but none for doing &#8220;real&#8221; merges. By this, I mean real, 3-way merges with all of the information you need in front of you. There are no good-looking, &#8220;mac-like&#8221; merge tools, but if you swallow your pride [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few very nice looking, mac-like diff tools for OSX (<a href="http://www.kaleidoscopeapp.com/" onclick="pageTracker._trackPageview('/outgoing/www.kaleidoscopeapp.com/?referer=');">Kaleidoscope</a> and <a href="http://connectedflow.com/changes/" onclick="pageTracker._trackPageview('/outgoing/connectedflow.com/changes/?referer=');">Changes</a> come to mind), but none for doing &#8220;real&#8221; merges.  By this, I mean real, <a href="http://en.wikipedia.org/wiki/3-way_merge#Three-way_merge" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/3-way_merge_Three-way_merge?referer=');">3-way merges</a> with all of the information you need in front of you.</p>
<p>There are no good-looking, &#8220;mac-like&#8221; merge tools, but if you swallow your pride there are a few different options for 3-way merges, including <a href="http://www.araxis.com/merge_mac/" onclick="pageTracker._trackPageview('/outgoing/www.araxis.com/merge_mac/?referer=');">Araxis Merge ($$$!)</a>, <a href="http://www.sourcegear.com/diffmerge/downloads.php" onclick="pageTracker._trackPageview('/outgoing/www.sourcegear.com/diffmerge/downloads.php?referer=');">DiffMerge</a>, <a href="http://www.deltopia.com/compare-merge-sync/macosx/" onclick="pageTracker._trackPageview('/outgoing/www.deltopia.com/compare-merge-sync/macosx/?referer=');">DeltaWalker</a>, and <a href="http://en.wikipedia.org/wiki/Apple_Developer_Tools#FileMerge" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Apple_Developer_Tools_FileMerge?referer=');">FileMerge</a> which comes free with XCode.</p>
<p>I&#8217;ve tried them all, and find them all confusing.  They all tend use a 3-pane display to do the merging with your file in the left pane, the file you&#8217;re merging in the right pane, and the messy half-merged file in the middle.</p>
<p>That&#8217;s not enough information.</p>
<p>A 3-way merge actually has four important sources of information:<span id="more-523"></span></p>
<ul>
<li><code>LOCAL</code> &#8211; your file with the changes you&#8217;ve made to it</li>
<li><code>REMOTE</code> &#8211; the file you&#8217;re merging in, possibly authored by someone else</li>
<li><code>BASE</code> &#8211; the common ancestor file that <code>LOCAL</code> and <code>REMOTE</code> came from</li>
<li><code>MERGE_RESULT</code> &#8211; the file resulting from the merge where you resolve conflicts</li>
</ul>
<p>You often need to see all four of these pieces of information to make intelligent choices.  Where you came from (<code>LOCAL</code>), where the other person&#8217;s changes came from (<code>REMOTE</code>), where you both started (<code>BASE</code>) and where you are now (<code>MERGE_RESULT</code>).</p>
<p>Most other 3-way merge tools either conflate or omit the <code>BASE</code> and that can make it harder to see what the right thing to do is.</p>
<p><a href="http://kdiff3.sourceforge.net/" onclick="pageTracker._trackPageview('/outgoing/kdiff3.sourceforge.net/?referer=');">Kdiff3</a> is my merge tool of choice.  It&#8217;s not pretty; it&#8217;s cross-platform <a href="http://en.wikipedia.org/wiki/Qt_(framework)" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Qt_framework?referer=');">Qt</a> based so it has a very old-school linux GUI feel to it.  But like linux, it&#8217;s functional and can help you quickly be productive once you get over the learning curve.</p>
<p>If you&#8217;ve got 2 heads that you need to merge in your current repository:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/2_heads_need_to_merge.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/2_heads_need_to_merge.png" alt="" title="2_heads_need_to_merge" width="403" height="107" class="aligncenter size-full wp-image-526" /></a><br />
We made this modification to <code>file.txt</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">--git</span> a<span style="color: #000000; font-weight: bold;">/</span>file.txt b<span style="color: #000000; font-weight: bold;">/</span>file.txt
<span style="color: #660033;">---</span> a<span style="color: #000000; font-weight: bold;">/</span>file.txt
+++ b<span style="color: #000000; font-weight: bold;">/</span>file.txt
<span style="color: #000000; font-weight: bold;">@@</span> -<span style="color: #000000;">1</span>,<span style="color: #000000;">1</span> +<span style="color: #000000;">1</span>,<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">@@</span>
-BASE: common_ancestor
+LOCAL: <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">in</span> current working branch</pre></div></div>

<p>and they made this change to the same file and line:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">--git</span> a<span style="color: #000000; font-weight: bold;">/</span>file.txt b<span style="color: #000000; font-weight: bold;">/</span>file.txt
<span style="color: #660033;">---</span> a<span style="color: #000000; font-weight: bold;">/</span>file.txt
+++ b<span style="color: #000000; font-weight: bold;">/</span>file.txt
<span style="color: #000000; font-weight: bold;">@@</span> -<span style="color: #000000;">1</span>,<span style="color: #000000;">1</span> +<span style="color: #000000;">1</span>,<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">@@</span>
-BASE: common_ancestor
+REMOTE: other branch we<span style="color: #ff0000;">'re merging in</span></pre></div></div>

<p>If you run your SCM&#8217;s merge command (here, in mercurial: <code>hg merge -r 2</code>), and have kdiff3 configured as your merge tool, you&#8217;ll get a pop-up window like this:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/kdiff3_merge_window_fixed.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/kdiff3_merge_window_fixed.png" alt="" title="kdiff3_merge_window_fixed" width="1241" height="512" class="alignleft size-full wp-image-555" /></a><br />
As you can see, it shows you all 4 pieces of information, <code>BASE</code>, <code>LOCAL</code>, and <code>REMOTE</code> on top, and the <code>MERGE_RESULT</code> file on the bottom.  It currently has a <code>Merge Conflict</code> that you need to fix.</p>
<p>You can move from one unresolved conflict to the next using the triple up and triple-down colored arrows in the middle of the tool bar.  When a conflict is highlighted, you can press any combination of the A, B, and C buttons in the toolbar.  Pressing one of those buttons will resolve the conflict with the code from pane A, B, or C on top.  So if the <code>LOCAL</code> file (your file) had the right changes in it, you&#8217;d press B.</p>
<p>It&#8217;s possible to press more than one button if code from multiple panes is valid.  You can also directly edit the file in the <code>MERGE_RESULT</code> pane to make manual changes if the correct merge is not the exact text in A/B/C.</p>
<p>Another option, if you want to take all of the changes from one file and discard any changes from the others, is to go to the &#8220;Merge&#8221; menu and pick one of &#8220;Choose A Everywhere&#8221;, &#8220;Choose B Everywhere&#8221;, or &#8220;Choose C Everywhere&#8221;.</p>
<p>Once you&#8217;ve resolved your file, simply save it (cmd-S) and quit out of kdiff3.  Your SCM should see the <code>MERGE_RESULT</code> no longer has any merge conflicts and will mark it as resolved, ready for you to commit it.  If there are other files with merge conflicts, you can repeat the process with those files.</p>
<h2>Installing kdiff3</h2>
<p>Installing kdiff3 is as easy as <a href="http://sourceforge.net/projects/kdiff3/files/kdiff3/" onclick="pageTracker._trackPageview('/outgoing/sourceforge.net/projects/kdiff3/files/kdiff3/?referer=');">downloading the latest version from sourceforge</a> and copying it to your <code>/Applications</code> directory.</p>
<p>The app is a simple wrapper around a Qt-based application.  It can be run from the command line at <code>/Applications/kdiff3.app/Contents/MacOS/kdiff3</code>.  You can make a symlink of that into your path, but I assume in the instructions below only that you&#8217;ve got kdiff3 in your <code>/Applications</code> folder.</p>
<h2>Mercurial Integration</h2>
<p>Mercurial command line integration is pretty easy.  Just open up your <code>~/.hgrc</code> file (or create one if you don&#8217;t have it already), and add this to it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>extdiff<span style="color: #7a0874; font-weight: bold;">&#93;</span>
cmd.kdiff3 = <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>kdiff3.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>kdiff3
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>merge-tools<span style="color: #7a0874; font-weight: bold;">&#93;</span>
kdiff3.args = <span style="color: #007800;">$base</span> <span style="color: #007800;">$local</span> <span style="color: #007800;">$other</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">$output</span></pre></div></div>

<p>That configures kdiff3 as your merge tool of choice, so it should pop up automatically when you hit a merge conflict.  You can also use it as a diff tool:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg kdiff3 <span style="color: #660033;">-r</span> revision_to_compare_to</pre></div></div>

<h2>Git Command-Line Integration</h2>
<p>To configure the git command line to use kdiff3 as a diff and merge tool, add this to your ~/.gitconfig:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>difftool <span style="color: #ff0000;">&quot;kdiff3&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    path = <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>kdiff3.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>kdiff3
    trustExitCode = <span style="color: #c20cb9; font-weight: bold;">false</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>difftool<span style="color: #7a0874; font-weight: bold;">&#93;</span>
    prompt = <span style="color: #c20cb9; font-weight: bold;">false</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #c20cb9; font-weight: bold;">diff</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    tool = kdiff3
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mergetool <span style="color: #ff0000;">&quot;kdiff3&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
    path = <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>kdiff3.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>kdiff3
    trustExitCode = <span style="color: #c20cb9; font-weight: bold;">false</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mergetool<span style="color: #7a0874; font-weight: bold;">&#93;</span>
    keepBackup = <span style="color: #c20cb9; font-weight: bold;">false</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>merge<span style="color: #7a0874; font-weight: bold;">&#93;</span>
    tool = kdiff3</pre></div></div>

<p>Now you can use the external tool commands to look at diffs:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> difftool <span style="color: #7a0874; font-weight: bold;">&#91;</span>revision_sha<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>and fix unresolved merge conflicts:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">git</span> mergetool</pre></div></div>

<h2>Git Tower Integration</h2>
<p>I&#8217;m normally a pretty hard-core command line user, but I still sometimes find the places I get myself in git confusing enough that I&#8217;m willing to use a GUI to get myself out.  I think that <a href="http://www.git-tower.com/" onclick="pageTracker._trackPageview('/outgoing/www.git-tower.com/?referer=');">git-tower</a> is the best git GUI available right now. </p>
<p>It can show you diff files and lets you browse through history in it&#8217;s UI. It also lets you do a number of basic and mid-level commands (adding, committing, rebasing, squashing commits, cherry-picking, etc), but it doesn&#8217;t have a built-in diff or merge tool.  </p>
<p>It does come with the ability to integrate with a few different merge tools out of the box, but not kdiff3.  </p>
<p>After a little digging around, I found a generic <a href="http://www.git-tower.com/files/applicationHelp/pgs/Integration_DiffTools.html" onclick="pageTracker._trackPageview('/outgoing/www.git-tower.com/files/applicationHelp/pgs/Integration_DiffTools.html?referer=');">post showing how configure Tower with a plist file and a shim shell script</a>, but nothing specific to kdiff3.</p>
<p>I figured out how to get Tower and kdiff3 to play nice with each other, and have the instructions and files in a <a href="https://github.com/tednaleid/git-tower-kdiff3-shim" onclick="pageTracker._trackPageview('/outgoing/github.com/tednaleid/git-tower-kdiff3-shim?referer=');">GitHub repository</a>.  To get it working, just clone the repository to a temporary directory, and run the install.sh script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>tmp
<span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>github.com:tednaleid<span style="color: #000000; font-weight: bold;">/</span>git-tower-kdiff3-shim.git 
<span style="color: #7a0874; font-weight: bold;">cd</span> git-tower-kdiff3-shim
.<span style="color: #000000; font-weight: bold;">/</span>install.sh</pre></div></div>

<p>It simply copies the plist file and the shim script into the appropriate directories (and Tower is <i>very</i> picky about those locations).</p>
<p>Then you need to go into Tower&#8217;s Preferences->Git Config control panel, and choose kdiff3 as the diff and merge tool:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/tower_preferences.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/tower_preferences.png" alt="" title="tower_preferences" width="764" height="386" class="alignleft size-full wp-image-542" /></a><br />
For a quick rundown of how Tower works with kdiff3 as a merge tool, here&#8217;s an example where we&#8217;ve got one commit where we made changes to locally:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/my_master.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/my_master.png" alt="" title="my_master" width="1416" height="822" class="alignleft size-full wp-image-534" /></a><br />
And another commit on <code>origin/master</code> where someone else made changes to the same piece of code:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/their_master.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/their_master.png" alt="" title="their_master" width="1416" height="822" class="alignleft size-full wp-image-536" /></a><br />
We&#8217;ve pulled it down and now have 2 heads within our repository. To fix this, we need to merge and resolve the conflicts, hit the merge button and we&#8217;ll get an error message because there are conflicts that git can&#8217;t resolve automatically:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/tower-conflict.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/tower-conflict.png" alt="" title="tower-conflict" width="1416" height="822" class="alignleft size-full wp-image-540" /></a><br />
If you highlight a file with merge conflicts, and then hit the &#8220;Merge Tool&#8221; button, it will bring up kdiff3 and let us use it to resolve the issue:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/kdiff3-merge.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/kdiff3-merge.png" alt="" title="kdiff3-merge" width="1257" height="512" class="alignleft size-full wp-image-545" /></a><br />
Fix the merge conflicts in kdiff3 (ex: press &#8220;C&#8221; to change it to &#8220;Goodbye Cruel World&#8221;), save it, and quit out of kdiff3. Tower should see that the file has had it&#8217;s conflicts resolved and lets you commit the merge and carry on.</p>
<p>You can also use Kdiff3 as a regular diff tool if you don&#8217;t like looking at diff files.  Just choose a file that you&#8217;ve modified to diff:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/tower-diff.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/tower-diff.png" alt="" title="tower-diff" width="1416" height="822" class="alignleft size-full wp-image-547" /></a><br />
Press the &#8220;Diff Tool&#8221; button, and it&#8217;ll pop up in kdiff3:<br />
<a href="http://naleid.com/blog/wp-content/uploads/2012/01/tower-kdiff3.png"><img src="http://naleid.com/blog/wp-content/uploads/2012/01/tower-kdiff3.png" alt="" title="tower-kdiff3" width="1257" height="512" class="alignleft size-full wp-image-548" /></a><br />
Kdiff3 might be homely, but it&#8217;s easy to use once you understand how it works.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2012/01/12/how-to-use-kdiff3-as-a-3-way-merge-tool-with-mercurial-git-and-tower-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting a Clojure REPL in Vim with VimClojure, Nailgun, and Leiningen</title>
		<link>http://naleid.com/blog/2011/12/19/getting-a-clojure-repl-in-vim-with-vimclojure-nailgun-and-leiningen/</link>
		<comments>http://naleid.com/blog/2011/12/19/getting-a-clojure-repl-in-vim-with-vimclojure-nailgun-and-leiningen/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 07:13:32 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[clojure]]></category>
		<category><![CDATA[command line]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=505</guid>
		<description><![CDATA[Having a Clojure REPL (Read Eval Print Loop) right inside Vim makes it easier to test ideas, get documentation, and explore your code. There are a few hoops that you need to jump through to enable it, but the payoff is worth it. Install Leiningen Leiningen isn&#8217;t required, but it makes managing the classpath for [...]]]></description>
			<content:encoded><![CDATA[<p>Having a Clojure REPL (Read Eval Print Loop) right inside Vim makes it easier to test ideas, get documentation, and explore your code.  There are a few hoops that you need to jump through to enable it, but the payoff is worth it.</p>
<p><span id="more-505"></span><br />
<h2>Install Leiningen</h2>
<p>Leiningen isn&#8217;t required, but it makes managing the classpath for your REPL quite a bit easier and automates the inclusion of the files in your project so that they can be used in the REPL.  </p>
<p>If you&#8217;ve already got clojure installed and are managing your classpath some other way, you&#8217;ll want to modify the nailgun server script below to remove the call to <code>lein</code> and ensure you&#8217;re getting clojure and other classes in the ng-server&#8217;s classpath.</p>
<p>Install <a href="https://github.com/technomancy/leiningen" onclick="pageTracker._trackPageview('/outgoing/github.com/technomancy/leiningen?referer=');">Leiningen</a> if you don&#8217;t have it already.</p>
<p>Download the <a href="https://raw.github.com/technomancy/leiningen/stable/bin/lein" onclick="pageTracker._trackPageview('/outgoing/raw.github.com/technomancy/leiningen/stable/bin/lein?referer=');"><code>lein</code> script</a>.</p>
<p>Put it somewhere on your <code>PATH</code> (such as <code>/usr/local/bin</code> or <code>~/bin</code>).</p>
<p>Set it to be executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x lein</pre></div></div>

<p>Then, tell it to self-install with this command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lein self-install</pre></div></div>

<p>Now you should have a working <code>lein</code> installation:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lein <span style="color: #7a0874; font-weight: bold;">help</span></pre></div></div>

<p>And you can create a new clojure project skeleton, with clojure 1.3.0 all ready to go with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lein new myproj</pre></div></div>

<p>It creates a skeleton project rectory and a <code>project.clj</code> file that you can use to hold lib dependencies.</p>
<p>Go into that project and you can use lein to go into a repl, get the project&#8217;s classpath, run tests, etc.  Use <code>lein help</code> to see the full list of commands.</p>
<h2>Install VimClojure in Vim</h2>
<p>Install the <a href="https://github.com/vim-scripts/VimClojure" onclick="pageTracker._trackPageview('/outgoing/github.com/vim-scripts/VimClojure?referer=');">VimClojure plugin</a> in vim.</p>
<p>Hopefully, you&#8217;re already using Tim Pope&#8217;s vim script management script <a href="https://github.com/tpope/vim-pathogen " onclick="pageTracker._trackPageview('/outgoing/github.com/tpope/vim-pathogen?referer=');">Pathogen</a>.</p>
<p>If so, you should be able to just clone VimClojure into your bundle ectory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> .vim<span style="color: #000000; font-weight: bold;">/</span>bundle
<span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>vim-scripts<span style="color: #000000; font-weight: bold;">/</span>VimClojure.git</pre></div></div>

<p>If you&#8217;re not using Pathogen, install the plugin with your normal process.</p>
<p>Edit your <code>.vimrc</code>, make sure you have these settings if they&#8217;re not already there (they need to be after the method that calls pathogen to install bundles):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">filetype off
call pathogen<span style="color: #666666; font-style: italic;">#runtime_append_all_bundles()</span>
...
filetype plugin indent on
syntax on</pre></div></div>

<p>and add these items to your <code>.vimrc</code></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">let</span> g:vimclojure<span style="color: #666666; font-style: italic;">#HighlightBuiltins = 1</span>
<span style="color: #7a0874; font-weight: bold;">let</span> g:vimclojure<span style="color: #666666; font-style: italic;">#ParenRainbow = 1</span></pre></div></div>

<p>To test that VimClojure is installed OK, edit a clojure file (like this sample one modified from <code>(source +)</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="clojure" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defn</span> myplus
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>x<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span>cast Number x<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>x y<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">.</span> clojure<span style="color: #66cc66;">.</span>lang<span style="color: #66cc66;">.</span>Numbers <span style="color: #66cc66;">&#40;</span>add x y<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>x y <span style="color: #66cc66;">&amp;</span> more<span style="color: #66cc66;">&#93;</span>
     <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">reduce</span> myplus <span style="color: #66cc66;">&#40;</span>myplus x y<span style="color: #66cc66;">&#41;</span> more<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>If the parenthesis are differently colored in matched pairs, that means that &#8220;rainbow&#8221; parenthesis are enabled and the plugin is working.  It should look something like this:</p>
<p><a href="http://naleid.com/blog/wp-content/uploads/2011/12/rainbow_parens.png"><img src="http://naleid.com/blog/wp-content/uploads/2011/12/rainbow_parens.png" alt="" title="rainbow_parens" width="512" height="187" class="aligncenter size-full wp-image-515" /></a></p>
<p>You&#8217;ll also want to update the <a href="https://bitbucket.org/kotarak/vimclojure/src/tip/vim/doc/clojure.txt" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/kotarak/vimclojure/src/tip/vim/doc/clojure.txt?referer=');">helptags documentation</a> for VimClojure:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:helptags ~<span style="color: #000000; font-weight: bold;">/</span>.vim<span style="color: #000000; font-weight: bold;">/</span>bundle<span style="color: #000000; font-weight: bold;">/</span>VimClojure<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Now you can lookup help for VimClojure:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">:<span style="color: #7a0874; font-weight: bold;">help</span> VimClojure</pre></div></div>

<p>You&#8217;ve now got a functioning VimClojure installation that can already be pretty helpful.  If you want to get an integrated REPL installed, there&#8217;s a bit more to do.</p>
<h2>Setting up Nailgun to work with VimClojure</h2>
<p>This part is the trickiest part (in the github docs, they say &#8220;Here be Dragons&#8221;).  I think the biggest difficulty is that they don&#8217;t show you how to configure/launch the nailgun server, we&#8217;ll go through those steps.</p>
<p><a href="http://www.martiansoftware.com/nailgun/background.html" onclick="pageTracker._trackPageview('/outgoing/www.martiansoftware.com/nailgun/background.html?referer=');">Nailgun</a> is a server that runs an instance of the JVM.  On startup, you tell it what classpath this JVM should run with.  Then, with a nailgun client, you can send it additional classes to execute within that JVM and it can show you the output.</p>
<p>It makes things much faster as the Nailgun server is already running hot when you send it things to execute.  You don&#8217;t pay any JVM startup penalty.</p>
<p><strong>Warning: If you&#8217;ve previously tried to install nailgun through homebrew, it will not work with clojure.  The server jar that homebrew uses is half the size of the server jar that we&#8217;re going to be using for clojure.  Uninstall it or put the things below earlier in the classpath.</strong></p>
<h4>Compile the VimClojure nailgun client</h4>
<p>We need to compile the VimClojure nailgun client.  You can either download the <a href="http://kotka.de/projects/vimclojure/vimclojure-nailgun-client-2.3.0.zip" onclick="pageTracker._trackPageview('/outgoing/kotka.de/projects/vimclojure/vimclojure-nailgun-client-2.3.0.zip?referer=');">sources</a> directly or else <a href="https://bitbucket.org/kotarak/vimclojure" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/kotarak/vimclojure?referer=');">clone the bitbucket repo</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hg clone https:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>kotarak<span style="color: #000000; font-weight: bold;">/</span>vimclojure</pre></div></div>

<p>Go into the client directory and <code>make</code> the ng client executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> vimclojure<span style="color: #000000; font-weight: bold;">/</span>client  <span style="color: #666666; font-style: italic;"># or cd vimclojure-nailgun-client</span>
<span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>This will create an executable called <code>ng</code> in the current directory.  Copy that somewhere in your path (likely the same place you put <code>lein</code> above).</p>
<p>You should now be able to type <code>ng</code> and have it spit out help text.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> ng
Usage: ng class <span style="color: #7a0874; font-weight: bold;">&#91;</span>--nailgun-options<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>args<span style="color: #7a0874; font-weight: bold;">&#93;</span>
          <span style="color: #7a0874; font-weight: bold;">&#40;</span>to execute a class<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   or: ng <span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>--nailgun-options<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>args<span style="color: #7a0874; font-weight: bold;">&#93;</span>
          <span style="color: #7a0874; font-weight: bold;">&#40;</span>to execute an aliased class<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   or: <span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>--nailgun-options<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>args<span style="color: #7a0874; font-weight: bold;">&#93;</span>
          <span style="color: #7a0874; font-weight: bold;">&#40;</span>to execute an aliased class, where <span style="color: #ff0000;">&quot;alias&quot;</span>
           is both the <span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #000000; font-weight: bold;">for</span> the class and a symbolic
           <span style="color: #c20cb9; font-weight: bold;">link</span> to the ng client<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
where options include:
   --nailgun-D<span style="color: #000000; font-weight: bold;">&lt;</span>name<span style="color: #000000; font-weight: bold;">&gt;</span>=<span style="color: #000000; font-weight: bold;">&lt;</span>value<span style="color: #000000; font-weight: bold;">&gt;</span>   set<span style="color: #000000; font-weight: bold;">/</span>override a client environment variable
   <span style="color: #660033;">--nailgun-version</span>           print product version and <span style="color: #7a0874; font-weight: bold;">exit</span>
   <span style="color: #660033;">--nailgun-showversion</span>       print product version and <span style="color: #7a0874; font-weight: bold;">continue</span>
   <span style="color: #660033;">--nailgun-server</span>            to specify the address of the nailgun server
                               <span style="color: #7a0874; font-weight: bold;">&#40;</span>default is localhost<span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #660033;">--nailgun-port</span>              to specify the port of the nailgun server
                               <span style="color: #7a0874; font-weight: bold;">&#40;</span>default is <span style="color: #000000;">2113</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
   <span style="color: #660033;">--nailgun-help</span>              print this message and <span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<h4>Setting up Nailgun Server</h4>
<p>Download latest <a href="http://clojars.org/repo/vimclojure/server/" onclick="pageTracker._trackPageview('/outgoing/clojars.org/repo/vimclojure/server/?referer=');">server jar from clojars</a> (currently <a href="http://clojars.org/repo/vimclojure/server/2.3.0/server-2.3.0.jar" onclick="pageTracker._trackPageview('/outgoing/clojars.org/repo/vimclojure/server/2.3.0/server-2.3.0.jar?referer=');">2.3.0</a>).</p>
<p>Put that jar somewhere that you won&#8217;t delete it, and then add an export for that location in your .bashrc/.vimrc, ex:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">VIMCLOJURE_SERVER_JAR</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/lib/vimclojure/server-2.3.0.jar&quot;</span></pre></div></div>

<p>Now save this script as <code>ng-server</code> and put it somewhere in your path and make it executable:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$VIMCLOJURE_SERVER_JAR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error! Need to define location of VimClojure nailgun server jar with:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;export VIMCLOJURE_SERVER_JAR=&lt;location&gt;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$VIMCLOJURE_SERVER_JAR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Error! Unable to find VimClojure nailgun server jar at '<span style="color: #007800;">$VIMCLOJURE_SERVER_JAR</span>'&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">LEIN_CLASSPATH</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>lein classpath<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #007800;">$LEIN_CLASSPATH</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Warning! Unable to get classpath from lein, just using existing classpath, expecting clojure jars to be available&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">NG_CLASSPATH</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$VIMCLOJURE_SERVER_JAR</span>:<span style="color: #007800;">$LEIN_CLASSPATH</span>:<span style="color: #007800;">$CLASSPATH</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> java <span style="color: #660033;">-server</span> <span style="color: #660033;">-cp</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NG_CLASSPATH</span>&quot;</span> vimclojure.nailgun.NGServer
java <span style="color: #660033;">-server</span> <span style="color: #660033;">-cp</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$NG_CLASSPATH</span>&quot;</span> vimclojure.nailgun.NGServer</pre></div></div>

<p>Then add this to your .vimrc setup:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #ff0000;">&quot; this should only be necessary if you don't have the ng client in your PATH
let vimclojure#NailgunClient = &quot;</span><span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>your<span style="color: #000000; font-weight: bold;">/</span>ng<span style="color: #ff0000;">&quot;
let vimclojure#WantNailgun = 1</span></pre></div></div>

<p>Now, from the root of a lein project, make sure you&#8217;re dependencies are updated:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lein deps   <span style="color: #000000; font-weight: bold;">//</span> puts things defined <span style="color: #000000; font-weight: bold;">in</span> project.clj into .<span style="color: #000000; font-weight: bold;">/</span>lib by default</pre></div></div>

<p>Without additional configuration, you&#8217;ll likely just have the clojure-1.3.0.jar in there.</p>
<p>The script above leverages lein to create a classpath that the nailgun server can use.  If you run <code>lein classpath</code>, you&#8217;ll see what it will use:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> lein classpath
<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>clojure-test<span style="color: #000000; font-weight: bold;">/</span>myproj<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">test</span>:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>clojure-test<span style="color: #000000; font-weight: bold;">/</span>myproj<span style="color: #000000; font-weight: bold;">/</span>test-resources:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>clojure-test<span style="color: #000000; font-weight: bold;">/</span>myproj<span style="color: #000000; font-weight: bold;">/</span>src:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>clojure-test<span style="color: #000000; font-weight: bold;">/</span>myproj<span style="color: #000000; font-weight: bold;">/</span>classes:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>clojure-test<span style="color: #000000; font-weight: bold;">/</span>myproj<span style="color: #000000; font-weight: bold;">/</span>resources:<span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>tnaleid<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>workspace<span style="color: #000000; font-weight: bold;">/</span>clojure-test<span style="color: #000000; font-weight: bold;">/</span>myproj<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>clojure-1.3.0.jar</pre></div></div>

<p>Now, you should be able to start up a nailgun server from the root of a lein project and have it automatically pull in all dependencies, ready to recieve client requests.</p>
<p>Open up the src/leinprojectname/core.clj file in vim.  Then press</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">\sr</pre></div></div>

<p>to get a REPL window that you can interact with.  (if you&#8217;ve remapped localleader to something else, replace <code>\</code> with your custom key)</p>
<p>There are quite a few other things you can do with the REPL, check out <code>:help VimClojure</code> and go down to <code>Keybindings</code> for more details.</p>
<p>Here are some good starter ones:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">\el  - <span style="color: #7a0874; font-weight: bold;">eval</span> current line
\eb  - <span style="color: #7a0874; font-weight: bold;">eval</span> current visual block selected
\ef  - <span style="color: #7a0874; font-weight: bold;">eval</span> current <span style="color: #c20cb9; font-weight: bold;">file</span>
&nbsp;
\sr  - start interactive REPL
\sR  - start interactive REPL initialized to have same namespace <span style="color: #c20cb9; font-weight: bold;">as</span> current buffer
&nbsp;
\si  - prompt <span style="color: #000000; font-weight: bold;">for</span> input and lookup with <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">source</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
\fd  - prompt <span style="color: #000000; font-weight: bold;">for</span> input and lookup with <span style="color: #7a0874; font-weight: bold;">&#40;</span>find-doc<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<h2>The Pain is Over, Now Reap the Rewards</h2>
<p>Once all this configuration is done, it should be as easy as running the server in a lein project:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ng-server</pre></div></div>

<p>And then editing your files in vim accessing the embedded REPL whenever you need it.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2011/12/19/getting-a-clojure-repl-in-vim-with-vimclojure-nailgun-and-leiningen/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Dropbox to Share (most of) Your Home Directory Across Multiple Computers</title>
		<link>http://naleid.com/blog/2011/10/03/using-dropbox-to-share-your-home-directory-across-multiple-computers/</link>
		<comments>http://naleid.com/blog/2011/10/03/using-dropbox-to-share-your-home-directory-across-multiple-computers/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 02:44:11 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[shortcut]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=433</guid>
		<description><![CDATA[I&#8217;m a very happy customer of Dropbox. It allows painless syncing of files across multiple computers without extra features to complicate it. The top rated answer on Quora to the question &#8220;Why is Dropbox more popular than other programs with similar functionality?&#8221; sums things up perfectly. One of my favorite uses of Dropbox is to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a very happy customer of <a href="http://dropbox.com" onclick="pageTracker._trackPageview('/outgoing/dropbox.com?referer=');">Dropbox</a>.   It allows painless syncing of files across multiple computers without extra features to complicate it.  The <a href="http://www.quora.com/Dropbox/Why-is-Dropbox-more-popular-than-other-programs-with-similar-functionality/answer/Michael-Wolfe" onclick="pageTracker._trackPageview('/outgoing/www.quora.com/Dropbox/Why-is-Dropbox-more-popular-than-other-programs-with-similar-functionality/answer/Michael-Wolfe?referer=');">top rated answer on Quora</a> to the question &#8220;Why is Dropbox more popular than other programs with similar functionality?&#8221; sums things up perfectly.</p>
<p>One of my favorite uses of Dropbox is to sync almost all of the non-machine specific configuration files and directories in my home directory across all my OSX computers (currently my iMac, MacBook Air, and my work laptop).  </p>
<p>Doing this lets me make a configuration change to one computer and have it almost instantly available on any other computer without any manual steps.</p>
<p>This is especially important for my zshell and Vim configurations as I&#8217;m always tweaking those, but it&#8217;s also helpful to have my Documents, Downloads and Pictures shared.</p>
<p>I have a folder in my <code>Dropbox</code> directory called <code>home</code>, I use a script called <code>link.sh</code> to automatically create symlinks in my home directory to the things I&#8217;ve got stored in Dropbox.</p>
<p><code>Dropbox/home</code> currently has these files and directories in it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.ackrc
.dbvis
.groovy
.gvimrc
.hg
.hgignore_global
.ssh
.subversion
.vim
.viminfo
.vimrc
.zshenv
Desktop-starling.local<span style="color: #000000; font-weight: bold;">/</span>   <span style="color: #666666; font-style: italic;"># unique Desktop for my MacBook Air</span>
Desktop-kestrel.local<span style="color: #000000; font-weight: bold;">/</span>    <span style="color: #666666; font-style: italic;"># unique Desktop for my iMac</span>
Desktop-thrush.local<span style="color: #000000; font-weight: bold;">/</span>     <span style="color: #666666; font-style: italic;"># unique Desktop for my work MacBook Pro</span>
Documents<span style="color: #000000; font-weight: bold;">/</span>
Downloads<span style="color: #000000; font-weight: bold;">/</span>
Pictures<span style="color: #000000; font-weight: bold;">/</span>
bin<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>My <code>Dropbox/home</code> directory also has a shell script in it called <code>link.sh</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /usr/bin/env bash</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">dirname</span> <span style="color: #007800;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> linkFile<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">LINK_TO_NAME</span>=<span style="color: #007800;">$2</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$LINK_TO_NAME</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">LINK_TO_NAME</span>=<span style="color: #007800;">$1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$LINK_TO_NAME</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;**** Found existing <span style="color: #007800;">$LINK_TO_NAME</span>, skipping...&quot;</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-h</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$LINK_TO_NAME</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Already symlinked <span style="color: #007800;">$LINK_TO_NAME</span>, skipping...&quot;</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Linking $1 to <span style="color: #007800;">$LINK_TO_NAME</span>&quot;</span>
        <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #007800;">$PWD</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$1</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$LINK_TO_NAME</span> 
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> F <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-a1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> link.sh <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> Desktop <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;^..?$&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">&quot;^.*un~$&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> .DS_Store<span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    linkFile <span style="color: #007800;">$F</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HOSTNAME</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;Desktop-<span style="color: #007800;">$HOSTNAME</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    linkFile <span style="color: #ff0000;">&quot;Desktop-<span style="color: #007800;">$HOSTNAME</span>&quot;</span> <span style="color: #ff0000;">&quot;Desktop&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span> 
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unable to find Desktop-<span style="color: #007800;">$HOSTNAME</span> to link to Desktop&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>What the script does is:</p>
<ol>
<li><code>cd</code> into the directory that the script is located in (it only symlinks files in the same directory)
<li>list out all of the files and directories in the same directory as the script</li>
<li>filter out the things we don&#8217;t want to link (like <code>.</code>, <code>..</code>, the <code>link.sh</code> script itself, etc)</li>
<li>For all of the files/directories that pass the filter, call <code>linkFile</code> to create a symlink in the current user&#8217;s home directory as long as there isn&#8217;t already a file or a symlink there</li>
<li>Then look for a file called <code>Desktop-$HOSTNAME</code> where <code>$HOSTNAME</code> is the name of the current machine and create a <code>~/Dropbox</code> symlink to it if it&#8217;s found.
</ol>
<p>It should be safe and non-destructive and only create symlinks when there isn&#8217;t anything else there with the same name.</p>
<p>I didn&#8217;t have my <code>Pictures</code>, <code>Documents</code>, and <code>Downloads</code> in my Dropbox for quite a while and was able to get away with the free 2GB plan. I recently upgraded to a paid Dropbox plan as I wanted those directories shared as well (though I exclude a couple of them from my work MacBook Pro).</p>
<p>For &#8220;special&#8221; directories like <code>Desktop</code>, <code>Pictures</code>, <code>Documents</code>, and <code>Downloads</code>, I needed to use <code>sudo rm -r [dirname]</code> to remove it before I could create the symlink (BACKUP THE DIRECTORY FIRST).   </p>
<p>I&#8217;ve been using this for over a year, and haven&#8217;t noticed any apps that care that those directories are symlinks.</p>
<p>Also?  I have used this shell script many times on my systems, and I think it&#8217;s safe, but <strong>PLEASE</strong> backup before using it, or deleting any directories.  An adult crying is not a pretty sight :).</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2011/10/03/using-dropbox-to-share-your-home-directory-across-multiple-computers/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Smart Bash/Zsh Aliases to Run Appropriate Grails Version</title>
		<link>http://naleid.com/blog/2011/09/26/smart-bash-zsh-aliases-to-run-appropriate-grails-version/</link>
		<comments>http://naleid.com/blog/2011/09/26/smart-bash-zsh-aliases-to-run-appropriate-grails-version/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 03:46:39 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=423</guid>
		<description><![CDATA[I&#8217;m currently on a project that has a couple of different apps that are using different versions of grails that need to be run concurrently. Switching a symlink no longer fit the way I needed to work so I came up with a couple bash/zsh aliases that are smart about the version of grails for [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently on a project that has a couple of different apps that are using different versions of grails that need to be run concurrently.  <a href="http://naleid.com/blog/2009/03/08/bashzsh-aliases-to-switch-groovy-and-grails-version/">Switching a symlink</a> no longer fit the way I needed to work so I came up with a couple bash/zsh aliases that are smart about the version of grails for the current directory.</p>
<p>These aliases work for both the <code>grails</code> as well as the <code>grails-debug</code> commands (for attaching a remote debugger).</p>
<p>If there is an <code>application.properties</code> file in the current directory, we can find the current version of grails for the app.</p>
<p>If there isn&#8217;t an <code>application.properties</code> file in the current directory, the script just defaults to whatever version of grails you&#8217;ve already set up as your default through the standard <code>$GRAILS_HOME</code> environment variable.  You can use the <a href="http://naleid.com/blog/2009/03/08/bashzsh-aliases-to-switch-groovy-and-grails-version/">grails symlink switching aliases</a> that I created previously to easily move this between versions.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">grails</span>=<span style="color: #ff0000;">&quot;execute_grails_version grails&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> grails-debug=<span style="color: #ff0000;">&quot;execute_grails_version grails-debug&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> execute_grails_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">GRAILS_CMD</span>=<span style="color: #007800;">$1</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> application.properties <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GRAILS_VERSION</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> app.grails.version application.properties <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">'s/.*=(.*)/\1/'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GRAILS_HOME</span>=<span style="color: #ff0000;">&quot;/usr/local/grails-<span style="color: #007800;">$GRAILS_VERSION</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;application.properties found, using <span style="color: #000099; font-weight: bold;">\$</span>GRAILS_HOME of <span style="color: #007800;">$GRAILS_HOME</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">else</span> 
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;application.properties NOT found, leaving <span style="color: #000099; font-weight: bold;">\$</span>GRAILS_HOME as <span style="color: #007800;">$GRAILS_HOME</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$GRAILS_HOME</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ERROR: Unable to find <span style="color: #000099; font-weight: bold;">\$</span>GRAILS_HOME directory at <span style="color: #007800;">$GRAILS_HOME</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$GRAILS_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$GRAILS_CMD</span> <span style="color: #007800;">$*</span>
    <span style="color: #007800;">$GRAILS_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$GRAILS_CMD</span> <span style="color: #007800;">$*</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>UPDATE: There are a few situations where aliases aren&#8217;t available (or are a pain to get available) such as when code is being executed as part of another application rather than from the command line.  To get around this, these scripts (created by a co-worker of mine, <a href="http://twitter.com/#!/sjurgemeyer" onclick="pageTracker._trackPageview('/outgoing/twitter.com/_/sjurgemeyer?referer=');">@sjurgemeyer</a>) could be put in your <code>PATH</code>, ahead of your <code>$GRAILS_HOME/bin</code> and used instead of the aliases above:</p>
<p>grails:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails-version grails <span style="color: #007800;">$*</span></pre></div></div>

<p>grails-debug:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">grails-version grails-debug <span style="color: #007800;">$*</span></pre></div></div>

<p>grails-version:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">GRAILS_CMD</span>=<span style="color: #007800;">$1</span>
<span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> application.properties <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GRAILS_VERSION</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> app.grails.version application.properties <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">'s/.*=(.*)/\1/'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GRAILS_HOME</span>=<span style="color: #ff0000;">&quot;/usr/local/grails-<span style="color: #007800;">$GRAILS_VERSION</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;application.properties found, using <span style="color: #000099; font-weight: bold;">\$</span>GRAILS_HOME of <span style="color: #007800;">$GRAILS_HOME</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span> 
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;application.properties NOT found, leaving <span style="color: #000099; font-weight: bold;">\$</span>GRAILS_HOME as <span style="color: #007800;">$GRAILS_HOME</span>&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$GRAILS_HOME</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ERROR: Unable to find <span style="color: #000099; font-weight: bold;">\$</span>GRAILS_HOME directory at <span style="color: #007800;">$GRAILS_HOME</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$GRAILS_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$GRAILS_CMD</span> <span style="color: #007800;">$*</span>
<span style="color: #007800;">$GRAILS_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$GRAILS_CMD</span> <span style="color: #007800;">$*</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2011/09/26/smart-bash-zsh-aliases-to-run-appropriate-grails-version/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Groovy Script Using Redis to Pick Conference Lottery Winners</title>
		<link>http://naleid.com/blog/2011/06/28/groovy-script-using-redis-to-pick-conference-lottery-winners/</link>
		<comments>http://naleid.com/blog/2011/06/28/groovy-script-using-redis-to-pick-conference-lottery-winners/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 04:29:03 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[redis]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=386</guid>
		<description><![CDATA[At the end of gr8conf today there were quite a few door prize giveaways. Winners were picked using a printout with attendees listed in (I&#8217;m assuming) random order. The guys running the lottery were going down the list and calling off names. This was right after my talk on using Redis with Groovy and I [...]]]></description>
			<content:encoded><![CDATA[<p>At the end of <a href="http://gr8conf.us" onclick="pageTracker._trackPageview('/outgoing/gr8conf.us?referer=');">gr8conf</a> today there were quite a few door prize giveaways.  Winners were picked using a printout with attendees listed in (I&#8217;m assuming) random order.  The guys running the lottery were going down the list and calling off names.</p>
<p>This was right after <a href="http://naleid.com/blog/2011/06/27/redis-groovy-and-grails-presentation-at-gr8conf-2011-and-gum/">my talk on using Redis with Groovy</a> and I thought to myself, &#8220;this is a perfect example of where a quick redis script could automate this and make it a bit more groovy&#8221;.  So I threw together this script in about 15 minutes:<br />
<span id="more-386"></span></p>
<div style="background-color: #fff">
<script src="https://bitbucket.org/tednaleid/groovy-util/src/tip/redis/pickLotteryWinner.groovy?embed=t"></script>
</div>
<p>The majority of the script is just parsing command line options, the redis portion is very small.</p>
<p>It populates a set of conference attendees from a text file if there isn&#8217;t already a set of people there (my <a href="https://bitbucket.org/tednaleid/groovy-util/src/tip/redis/conference-attendees.txt" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/groovy-util/src/tip/redis/conference-attendees.txt?referer=');">sample file</a> just uses <a href="http://gr8conf.us/home/speakers" onclick="pageTracker._trackPageview('/outgoing/gr8conf.us/home/speakers?referer=');">conference speakers</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>redis.<span style="color: #006600;">exists</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;conference-attendees&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #aaaadd; font-weight: bold;">File</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;./conference-attendees.txt&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #FFCC33;">eachLine</span> <span style="color: #66cc66;">&#123;</span> redis.<span style="color: #006600;">sadd</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;conference-attendees&quot;</span>, it<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Next, it pops a random attendee out of the set of all attendees that haven&#8217;t won prizes yet:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> winner <span style="color: #66cc66;">=</span> redis.<span style="color: #006600;">spop</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;conference-attendees&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>It will then add that winner to a hash of prizes mapped to winners.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">redis.<span style="color: #006600;">hset</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;prize-winners&quot;</span>, prize, winner<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>The winner is then printed to stdout with println.  Pipe the command it through <a href="http://naleid.com/blog/2011/05/17/big-a-quick-shellapplescriptlaunchbar-script-to-shout-results/">big</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> .<span style="color: #000000; font-weight: bold;">/</span>pickLotteryWinner.groovy Groovy <span style="color: #000000; font-weight: bold;">in</span> Action 2nd Edition <span style="color: #000000; font-weight: bold;">|</span> big</pre></div></div>

<p>and you&#8217;ll get something like this:</p>
<p><a href="http://naleid.com/blog/wp-content/uploads/2011/06/winner.png"><img src="http://naleid.com/blog/wp-content/uploads/2011/06/winner.png" alt="" title="winner" width="750" height="114" class="aligncenter size-full wp-image-393" /></a></p>
<p>If someone isn&#8217;t around to claim the prize, just run the script again with that same prize and it&#8217;ll replace the last person picked in the hash of prizes to winners.</p>
<p>Forget who won a prize?  Just run it with <code>-l</code> to list all prize winners so far:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">def</span> printPrizeWinner<span style="color: #66cc66;">&#40;</span>prize, winner<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #993399;">println</span> <span style="color: #ff0000;">&quot;$winner wins $prize&quot;</span> <span style="color: #66cc66;">&#125;</span>
...
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>options.<span style="color: #ff0000;">'list'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">def</span> prizeWinners <span style="color: #66cc66;">=</span> redis.<span style="color: #006600;">hgetAll</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;prize-winners&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #993399;">println</span> <span style="color: #ff0000;">&quot;Prize winners so far:&quot;</span>
    prizeWinners.<span style="color: #663399;">each</span> <span style="color: #66cc66;">&#123;</span> prize, winner <span style="color: #66cc66;">-&gt;</span> printPrizeWinner<span style="color: #66cc66;">&#40;</span>prize, winner<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#125;</span>
    <span style="color: #aaaadd; font-weight: bold;">System</span>.<span style="color: #006600;">exit</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Pipe that through <a href="http://naleid.com/blog/2011/05/17/big-a-quick-shellapplescriptlaunchbar-script-to-shout-results/">big</a> and you&#8217;ll get this:</p>
<p><a href="http://naleid.com/blog/wp-content/uploads/2011/06/list-winners.png"><img src="http://naleid.com/blog/wp-content/uploads/2011/06/list-winners.png" alt="" title="list-winners" width="728" height="169" class="aligncenter size-full wp-image-392" /></a></p>
<p>I love how flexible Redis is, and how easy it makes solving problems.  If I had been given this problem before redis, I probably would have hacked together something ugly that persisted/read JSON from the file system or maybe a small grails app with Prizes and Winners.  With redis, this is a 15 minute problem (and an hour blog post :), instead of a problem that takes an hour or two to solve.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2011/06/28/groovy-script-using-redis-to-pick-conference-lottery-winners/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Replace Grails Console with the Editor of Your Choice</title>
		<link>http://naleid.com/blog/2011/04/25/replace-grails-console-with-the-editor-of-your-choice/</link>
		<comments>http://naleid.com/blog/2011/04/25/replace-grails-console-with-the-editor-of-your-choice/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 04:25:42 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=315</guid>
		<description><![CDATA[The grails console has a number of disadvantages that make it a little clunky to use: You can&#8217;t attach it to a running grails instance, you need to run grails console from scratch You can&#8217;t pass it parameters, such as the name of a script you&#8217;ve saved It&#8217;s a swing app, which is always a [...]]]></description>
			<content:encoded><![CDATA[<p>The grails console has a number of disadvantages that make it a little clunky to use:</p>
<ul>
<li>You can&#8217;t attach it to a running grails instance, you need to run <code>grails console</code> from scratch</li>
<li>You can&#8217;t pass it parameters, such as the name of a script you&#8217;ve saved</li>
<li>It&#8217;s a swing app, which is always a little wonky in it&#8217;s keybindings and it&#8217;s behavior</li>
<li>It&#8217;s not <i>&lt;insert your chosen editor&gt;</i></li>
</ul>
<p>I got tired of these limitations so I decided to do something about it.  I put together a groovy script that uses <a href="http://groovy.codehaus.org/modules/http-builder/download.html" onclick="pageTracker._trackPageview('/outgoing/groovy.codehaus.org/modules/http-builder/download.html?referer=');">HTTPBuilder</a> to POST groovy code to a running Grails app that has the <a href="http://www.grails.org/Console+Plugin" onclick="pageTracker._trackPageview('/outgoing/www.grails.org/Console+Plugin?referer=');">grails console plugin</a> installed. </p>
<p>If you&#8217;re running this in any non-development environment, you&#8217;ll want to ensure that it&#8217;s behind some form of authentication.  The most popular grails security plugin is Burt Beckwith&#8217;s <a href="http://www.grails.org/plugin/spring-security-core" onclick="pageTracker._trackPageview('/outgoing/www.grails.org/plugin/spring-security-core?referer=');">spring security core</a>, so this script comes with built-in support for that.</p>
<p>This script makes it easy to call from any editor that allows you to execute scripts (pretty much every programmer&#8217;s editor on the market).   At the bottom of the post, I show how to integrate it with Vim (my editor of choice), but it&#8217;d be just as easy to script it from TextMate, JEdit, IntelliJ, Eclipse, etc.  Any editor that can take the file you&#8217;re currently editing and pass it to a shell script.</p>
<p>Here&#8217;s my Vim session with a grails script at the bottom and the output from that grails script in another window at the top.  </p>
<p><a href="http://naleid.com/blog/wp-content/uploads/2011/04/vim_grails_console1.png"><img src="http://naleid.com/blog/wp-content/uploads/2011/04/vim_grails_console1.png" alt="Using Vim as a Grails Console" title="vim_grails_console" width="725" height="417" class="aligncenter size-full wp-image-338" /></a></p>
<p><span id="more-315"></span>This is the script that makes the magic happen (<a href="https://github.com/tednaleid/groovy-util/blob/master/src/main/groovy/postCode.groovy" onclick="pageTracker._trackPageview('/outgoing/github.com/tednaleid/groovy-util/blob/master/src/main/groovy/postCode.groovy?referer=');">linked from github</a> so any future tweaks will be reflected below), just grab a copy and save it somewhere in your path.  </p>
<div style="background-color: #fff">
<script src="http://gist-it.appspot.com/github/tednaleid/groovy-util/raw/master/src/main/groovy/postCode.groovy"></script>
</div>
<p><br/></p>
<p>If you execute the script without any parameters, it&#8217;ll show you the usage syntax:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> postCode.groovy 
usage: postCode.groovy <span style="color: #7a0874; font-weight: bold;">&#91;</span>-u username<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>-p password<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #660033;">-b</span> baseUrl <span style="color: #c20cb9; font-weight: bold;">file</span>
 -b,--baseurl <span style="color: #000000; font-weight: bold;">&lt;</span>baseUrl<span style="color: #000000; font-weight: bold;">&gt;</span>     The required base url to auth<span style="color: #000000; font-weight: bold;">/</span>post to, ex:
                            http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>myapp<span style="color: #000000; font-weight: bold;">/</span>
 -p,--password <span style="color: #000000; font-weight: bold;">&lt;</span>password<span style="color: #000000; font-weight: bold;">&gt;</span>   The password to authenticate with
 -u,--user <span style="color: #000000; font-weight: bold;">&lt;</span>user<span style="color: #000000; font-weight: bold;">&gt;</span>           The username to authenticate with, null
                            username<span style="color: #000000; font-weight: bold;">/</span>password skips authentication</pre></div></div>

<p>It uses the nifty CliBuilder that&#8217;s comes with recent versions of Groovy to parse command line arguments.   If your project doesn&#8217;t have any authentication, you can simply call it with the <code>-b</code> argument to let it know where your app is running and pass it a script to execute on that running instance:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">postCode.groovy <span style="color: #660033;">-b</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>myapp<span style="color: #000000; font-weight: bold;">/</span> scriptToRun.groovy 
... results of scriptToRun.groovy ...</pre></div></div>

<p>If your project IS using the spring security plugin for authentication, you can add a username and a password to use for authentication:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">postCode.groovy <span style="color: #660033;">-u</span> admin <span style="color: #660033;">-p</span> sekrit <span style="color: #660033;">-b</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>myapp<span style="color: #000000; font-weight: bold;">/</span> scriptToRun.groovy
... results of scriptToRun.groovy ...</pre></div></div>

<p>The first time that you run it, it might take a little while to run because the Grape <code>Grab</code> annotation is downloading the HTTPBuilder jars and it&#8217;s dependencies.</p>
<p>UPDATE: 8/7/2011 The below is no longer necessary with the new @GrabExclude to ignore the groovy dependency.<br />
<strike><br />
One sort of screwy thing that I&#8217;ve found with the default Grape settings is that it really isn&#8217;t that smart about what dependencies it should download again when they&#8217;re already satisfied.  This can cause a ~30 second pause every time the script is run, which is unacceptable.  I posted a <a href="http://groovy.329449.n5.nabble.com/HTTP-Client-grape-resolve-takes-30-seconds-on-groovy-1-7-10-dependency-td4309356.html" onclick="pageTracker._trackPageview('/outgoing/groovy.329449.n5.nabble.com/HTTP-Client-grape-resolve-takes-30-seconds-on-groovy-1-7-10-dependency-td4309356.html?referer=');">message on the Groovy mailing list</a> and the <a href="http://spring-java-ee.blogspot.com/2011/04/fixing-slow-grab-dependencies-issue.html" onclick="pageTracker._trackPageview('/outgoing/spring-java-ee.blogspot.com/2011/04/fixing-slow-grab-dependencies-issue.html?referer=');">tl;dr fix</a> for it is to increase the <code> ivy.cache.ttl.default</code> timeout in your ~/.groovy/grapeConfig.xml file (use <a href="http://svn.codehaus.org/groovy/tags/GROOVY_1_7_10/src/main/groovy/grape/defaultGrapeConfig.xml" onclick="pageTracker._trackPageview('/outgoing/svn.codehaus.org/groovy/tags/GROOVY_1_7_10/src/main/groovy/grape/defaultGrapeConfig.xml?referer=');">this as a template</a> if you don&#8217;t have the file).</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ivysettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ivy.cache.ttl.default&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;15m&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> 
...</pre></div></div>

<p></strike></p>
<h2>Example Use with Spring Security Core Plugin</h2>
<p>Here&#8217;s a quick demo project where the console plugin is protected by the Spring Security Core plugin.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">grails create<span style="color: #66cc66;">-</span>app demo<span style="color: #66cc66;">-</span>post<span style="color: #66cc66;">-</span>code
cd demo<span style="color: #66cc66;">-</span>post<span style="color: #66cc66;">-</span>code
grails install<span style="color: #66cc66;">-</span>plugin console</pre></div></div>

<p>Install the spring-security-core plugin and create the default User and Role domain classes.</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">grails install<span style="color: #66cc66;">-</span>plugin spring<span style="color: #66cc66;">-</span>security<span style="color: #66cc66;">-</span>core
grails s2<span style="color: #66cc66;">-</span>quickstart com.<span style="color: #006600;">example</span> User Role</pre></div></div>

<p>Edit <code>grails-app/conf/Config.groovy</code> and add a rule next to the other spring security configuration stating only <code>ROLE_ADMIN</code> users can get to the console plugin:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">grails.<span style="color: #006600;">plugins</span>.<span style="color: #006600;">springsecurity</span>.<span style="color: #006600;">controllerAnnotations</span>.<span style="color: #006600;">staticRules</span> <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#91;</span>
   <span style="color: #ff0000;">'/console/**'</span>: <span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'ROLE_ADMIN'</span><span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#93;</span></pre></div></div>

<p>Now we&#8217;ll need an <code>admin</code> user in <code>grails-app/conf/BootStrap.groovy</code> that has permission to execute code in the console.  Edit the bootstrap file to look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">com.example.*</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> BootStrap <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">def</span> springSecurityService
&nbsp;
    <span style="color: #000000; font-weight: bold;">def</span> init <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span> servletContext <span style="color: #66cc66;">-&gt;</span>
        <span style="color: #000000; font-weight: bold;">def</span> adminRole <span style="color: #66cc66;">=</span> Role.<span style="color: #006600;">findByAuthority</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'ROLE_ADMIN'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">?</span>: <span style="color: #000000; font-weight: bold;">new</span> Role<span style="color: #66cc66;">&#40;</span>authority: <span style="color: #ff0000;">'ROLE_ADMIN'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>failOnError: <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #000000; font-weight: bold;">def</span> adminUser <span style="color: #66cc66;">=</span> User.<span style="color: #006600;">findByUsername</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'admin'</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">?</span>: <span style="color: #000000; font-weight: bold;">new</span> User<span style="color: #66cc66;">&#40;</span>
            username: <span style="color: #ff0000;">'admin'</span>, password: springSecurityService.<span style="color: #006600;">encodePassword</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'sekrit'</span><span style="color: #66cc66;">&#41;</span>, enabled: <span style="color: #000000; font-weight: bold;">true</span>
        <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>failOnError: <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">!</span>adminUser.<span style="color: #006600;">authorities</span>.<span style="color: #CC0099;">contains</span><span style="color: #66cc66;">&#40;</span>adminRole<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> UserRole.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span>adminUser, adminRole<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">def</span> destroy <span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As you can see, we&#8217;ve created an <code>admin</code> user with the password <code>sekrit</code>.</p>
<p>Now, create a sample script to run in the grails context, something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #a1a100;">com.example.*</span> 
&nbsp;
<span style="color: #993399;">println</span> <span style="color: #ff0000;">&quot;User count = ${User.count()}&quot;</span></pre></div></div>

<p>Now run the app with <code>grails run-app</code> and in another terminal window execute the postCode.groovy script and give it the credentials and the base url to post it to.  If you&#8217;ve got everything set up, you should see that there&#8217;s one User in the database (the admin user that we bootstrapped in :).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span> postCode.groovy <span style="color: #660033;">-u</span> admin <span style="color: #660033;">-p</span> sekrit <span style="color: #660033;">-b</span> http:<span style="color: #000000; font-weight: bold;">//</span>localhost:<span style="color: #000000;">8080</span><span style="color: #000000; font-weight: bold;">/</span>demo-post-code test.groovy
&nbsp;
User count = <span style="color: #000000;">1</span></pre></div></div>

<h2>Integrating With Vim</h2>
<p>My vimscript skills are pretty much non-existent, and I&#8217;m sure there&#8217;s a better way to do this, but here&#8217;s the code that I&#8217;ve got in <a href="https://bitbucket.org/tednaleid/vimrc/src" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/vimrc/src?referer=');">my .vimrc</a> to bind F7 to executing the current buffer as plain groovy, and binds F8 to executing it as a grails script, with full binding.</p>
<p>Shift-F7/F8 will close the execution window.  If you highlight a part of your code in visual mode, it will just post the highlighted code rather than the whole file.</p>
<p>You can also override the default user/password/base url in a grails session by overriding any of these values, either directly in the vimscript or by setting the appropriate environment variable:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>grails_user = <span style="color: #000000;">$</span>DEFAULT_GRAILS_USER
<span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>grails_password = <span style="color: #000000;">$</span>DEFAULT_GRAILS_PASSWORD
<span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>grails_base_url = <span style="color: #000000;">$</span>DEFAULT_GRAILS_BASE_URL</pre></div></div>

<p>So to test the above script, I&#8217;d use this in my .zshrc/.bashrc/.profile:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEFAULT_GRAILS_USER</span>=<span style="color: #ff0000;">'admin'</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEFAULT_GRAILS_PASSWORD</span>=<span style="color: #ff0000;">'sekrit'</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEFAULT_GRAILS_BASE_URL</span>=<span style="color: #ff0000;">'http://localhost:8080/demo-post-code'</span></pre></div></div>

<p>and this script to temporarily change the values using the current directory for the BASE_URL and optionally passing in a user and password</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># example usage from root of grails directory: grailsBaseUrlReset myUsername myOtherPassword</span>
<span style="color: #000000; font-weight: bold;">function</span> grailsBaseUrlReset<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEFAULT_GRAILS_BASE_URL</span>=<span style="color: #ff0000;">&quot;http://localhost:8080/<span style="color: #007800;">${PWD##*/}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DEFAULT_GRAILS_BASE_URL set to <span style="color: #007800;">$DEFAULT_GRAILS_BASE_URL</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEFAULT_GRAILS_USER</span>=<span style="color: #007800;">$1</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DEFAULT_GRAILS_USER set to <span style="color: #007800;">$DEFAULT_GRAILS_USER</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DEFAULT_GRAILS_PASSWORD</span>=<span style="color: #007800;">$2</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;DEFAULT_GRAILS_PASSWORD set to <span style="color: #007800;">$DEFAULT_GRAILS_PASSWORD</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>You can change them temporarily in vim by changing a value for your current grails session, just hit colon and change the value:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #000000;">:</span><span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>grails_password = <span style="color: #C5A22D;">&quot;reallyReallySekrit&quot;</span></pre></div></div>

<p>(or you could add them to a different file that you source independently)</p>
<p>Here&#8217;s the full script, just add it to your <code>~/.vimrc</code> and make sure the <code>postCode.groovy</code> script is in your path and you should be set to go:</p>

<div class="wp_syntax"><div class="code"><pre class="vim" style="font-family:monospace;"><span style="color: #804040;">function</span><span style="color: #000000;">!</span> s<span style="color: #000000;">:</span>copy_groovy_buffer_to_temp<span style="color: #000000;">&#40;</span>first, last<span style="color: #000000;">&#41;</span><span style="color: #adadad; font-style: italic;">
  &quot; groovy/java scripts can't start with a # and tempname's normally do</span>
  <span style="color: #804040;">let</span> src = <span style="color: #25BB4D;">substitute</span><span style="color: #000000;">&#40;</span><span style="color: #25BB4D;">tempname</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #C5A22D;">&quot;[^<span style="">\/</span>]*$&quot;</span>, <span style="color: #C5A22D;">&quot;vim_&amp;.groovy&quot;</span>, <span style="color: #C5A22D;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #adadad; font-style: italic;"> 
&nbsp;
  &quot; put current buffer's content in a temp file</span>
  silent <span style="color: #804040;">exe</span> <span style="color: #C5A22D;">&quot;: &quot;</span> <span style="color: #000000;">.</span> a<span style="color: #000000;">:</span>first <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;,&quot;</span> <span style="color: #000000;">.</span> a<span style="color: #000000;">:</span>last <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot;w &quot;</span> <span style="color: #000000;">.</span> src
&nbsp;
  <span style="color: #804040;">return</span> src
endfunction
&nbsp;
<span style="color: #804040;">function</span><span style="color: #000000;">!</span> s<span style="color: #000000;">:</span>select_new_temp_buffer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">let</span> temp_file = <span style="color: #25BB4D;">tempname</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #adadad; font-style: italic;">
&nbsp;
  &quot; open the preview window to the temp file</span>
  silent <span style="color: #804040;">exe</span> <span style="color: #C5A22D;">&quot;:pedit! &quot;</span> <span style="color: #000000;">.</span> temp_file<span style="color: #adadad; font-style: italic;">
&nbsp;
  &quot; select the temp buffer as active </span>
  wincmd P<span style="color: #adadad; font-style: italic;">
&nbsp;
  &quot; set options for temp buffer</span>
  <span style="color: #804040;">setlocal</span> <span style="color: #668080;">buftype</span>=nofile
  <span style="color: #804040;">setlocal</span> <span style="color: #668080;">noswapfile</span>
  <span style="color: #804040;">setlocal</span> <span style="color: #804040;">syntax</span>=none
  <span style="color: #804040;">setlocal</span> <span style="color: #668080;">bufhidden</span>=<span style="color: #25BB4D;">delete</span>
&nbsp;
  <span style="color: #804040;">return</span> temp_file
endfunction
&nbsp;
<span style="color: #804040;">function</span><span style="color: #000000;">!</span> Groovy_eval_vsplit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #25BB4D;">range</span>
  <span style="color: #804040;">let</span> temp_source = s<span style="color: #000000;">:</span>copy_groovy_buffer_to_temp<span style="color: #000000;">&#40;</span>a<span style="color: #000000;">:</span>firstline, a<span style="color: #000000;">:</span>lastline<span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">let</span> temp_file = s<span style="color: #000000;">:</span>select_new_temp_buffer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #adadad; font-style: italic;">
&nbsp;
  &quot; replace current buffer with groovy's output</span>
  silent <span style="color: #804040;">execute</span> <span style="color: #C5A22D;">&quot;:%! groovy &quot;</span> <span style="color: #000000;">.</span> temp_source <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; 2&gt;&amp;1 &quot;</span>
&nbsp;
  wincmd p<span style="color: #adadad; font-style: italic;"> &quot; change back to the source buffer</span>
endfunction
&nbsp;
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy vmap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #668080;">&lt;F7&gt;</span> <span style="color: #000000;">:</span><span style="color: #804040;">call</span> Groovy_eval_vsplit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #668080;">&lt;CR&gt;</span>
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy nmap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #668080;">&lt;F7&gt;</span> mzggVG<span style="color: #000000;">&lt;</span>F7<span style="color: #000000;">&gt;</span>`z
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy imap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #668080;">&lt;F7&gt;</span> <span style="color: #000000;">&lt;</span>Esc<span style="color: #000000;">&gt;&lt;</span>F7<span style="color: #000000;">&gt;</span>a
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy <span style="color: #804040;">map</span> <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #000000;">&lt;</span>S<span style="color: #000000;">-</span>F7<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span>wincmd P<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;:</span>q<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;</span>
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy imap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #000000;">&lt;</span>S<span style="color: #000000;">-</span>F7<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>Esc<span style="color: #000000;">&gt;&lt;</span>S<span style="color: #000000;">-</span>F7<span style="color: #000000;">&gt;</span>a<span style="color: #adadad; font-style: italic;">
&nbsp;
&nbsp;
&quot; set these up as environment variables on your system, or override</span><span style="color: #adadad; font-style: italic;">
&quot; per session by using ':let g:grails_user = foo'</span>
<span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>grails_user = <span style="color: #000000;">$</span>DEFAULT_GRAILS_USER
<span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>grails_password = <span style="color: #000000;">$</span>DEFAULT_GRAILS_PASSWORD
<span style="color: #804040;">let</span> g<span style="color: #000000;">:</span>grails_base_url = <span style="color: #000000;">$</span>DEFAULT_GRAILS_BASE_URL
&nbsp;
<span style="color: #804040;">function</span><span style="color: #000000;">!</span> Grails_eval_vsplit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #25BB4D;">range</span>
  <span style="color: #804040;">let</span> temp_source = s<span style="color: #000000;">:</span>copy_groovy_buffer_to_temp<span style="color: #000000;">&#40;</span>a<span style="color: #000000;">:</span>firstline, a<span style="color: #000000;">:</span>lastline<span style="color: #000000;">&#41;</span>
  <span style="color: #804040;">let</span> temp_file = s<span style="color: #000000;">:</span>select_new_temp_buffer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
  <span style="color: #804040;">if</span> <span style="color: #25BB4D;">strlen</span><span style="color: #000000;">&#40;</span>g<span style="color: #000000;">:</span>grails_user<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&gt;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #adadad; font-style: italic;">
      &quot; replace current buffer with grails' output</span>
      silent <span style="color: #804040;">execute</span> <span style="color: #C5A22D;">&quot;:%! postCode.groovy -u &quot;</span> <span style="color: #000000;">.</span> g<span style="color: #000000;">:</span>grails_user <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; -p &quot;</span> <span style="color: #000000;">.</span> g<span style="color: #000000;">:</span>grails_password <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; -b &quot;</span> <span style="color: #000000;">.</span> g<span style="color: #000000;">:</span>grails_base_url <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; &quot;</span> <span style="color: #000000;">.</span> temp_source <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; 2&gt;&amp;1 &quot;</span>
  <span style="color: #804040;">else</span> 
      silent <span style="color: #804040;">execute</span> <span style="color: #C5A22D;">&quot;:%! postCode.groovy -b &quot;</span> <span style="color: #000000;">.</span> g<span style="color: #000000;">:</span>grails_base_url <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; &quot;</span> <span style="color: #000000;">.</span> temp_source <span style="color: #000000;">.</span> <span style="color: #C5A22D;">&quot; 2&gt;&amp;1 &quot;</span>
  <span style="color: #804040;">endif</span>
&nbsp;
  wincmd p<span style="color: #adadad; font-style: italic;"> &quot; change back to the source buffer</span>
endfunction
&nbsp;
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy vmap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #668080;">&lt;F8&gt;</span> <span style="color: #000000;">:</span><span style="color: #804040;">call</span> Grails_eval_vsplit<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #668080;">&lt;CR&gt;</span>
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy nmap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #668080;">&lt;F8&gt;</span> mzggVG<span style="color: #000000;">&lt;</span>F8<span style="color: #000000;">&gt;</span>`z
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy imap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #668080;">&lt;F8&gt;</span> <span style="color: #000000;">&lt;</span>Esc<span style="color: #000000;">&gt;&lt;</span>F8<span style="color: #000000;">&gt;</span>a
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy <span style="color: #804040;">map</span> <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #000000;">&lt;</span>S<span style="color: #000000;">-</span>F8<span style="color: #000000;">&gt;</span> <span style="color: #000000;">:</span>wincmd P<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;:</span>q<span style="color: #000000;">&lt;</span>CR<span style="color: #000000;">&gt;</span>
<span style="color: #804040;">au</span> <span style="color: #25BB4D;">BufNewFile</span>,<span style="color: #25BB4D;">BufRead</span> <span style="color: #000000;">*.</span>groovy imap <span style="color: #668080;">&lt;silent&gt;</span> <span style="color: #000000;">&lt;</span>S<span style="color: #000000;">-</span>F8<span style="color: #000000;">&gt;</span> <span style="color: #000000;">&lt;</span>Esc<span style="color: #000000;">&gt;&lt;</span>S<span style="color: #000000;">-</span>F8<span style="color: #000000;">&gt;</span>a</pre></div></div>

<p>If you&#8217;re not a Vim user, it should be easy to integrate with any other editor that allows you to pass the current file to a shell command and display the results.  I went a little extra with the vimscript to allow it to post the current buffer (or selected lines within that buffer) without having to save to disk first.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2011/04/25/replace-grails-console-with-the-editor-of-your-choice/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Running Redis as a User Daemon on OSX with launchd</title>
		<link>http://naleid.com/blog/2011/03/05/running-redis-as-a-user-daemon-on-osx-with-launchd/</link>
		<comments>http://naleid.com/blog/2011/03/05/running-redis-as-a-user-daemon-on-osx-with-launchd/#comments</comments>
		<pubDate>Sun, 06 Mar 2011 03:02:17 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[redis]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=292</guid>
		<description><![CDATA[If you&#8217;re developing on the mac using redis and want it to start automatically on boot, you&#8217;ll want to leverage the OSX launchd system to run it as a User Daemon. A User Daemon is a non-gui program that runs in the background as part of the system. It isn&#8217;t associated with your user account. [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re developing on the mac using <a href="http://redis.io" onclick="pageTracker._trackPageview('/outgoing/redis.io?referer=');">redis</a> and want it to start automatically on boot, you&#8217;ll want to leverage the OSX <code>launchd</code> system to run it as a <a href="http://developer.apple.com/library/mac/#technotes/tn2005/tn2083.html" onclick="pageTracker._trackPageview('/outgoing/developer.apple.com/library/mac/_technotes/tn2005/tn2083.html?referer=');">User Daemon</a>.  A User Daemon is a non-gui program that runs in the background as part of the system.  It isn&#8217;t associated with your user account.  If you only want redis to launch when a particular user logs in, you&#8217;ll want to make a User Agent instead.</p>
<p>From the command line, create a plist file as root in the <code>/Library/LaunchDaemons</code> directory with your favorite text editor:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>io.redis.redis-server.plist</pre></div></div>

<p>Paste in the following contents and modify it to point it to wherever you&#8217;ve got <code>redis-server</code> installed and optionally pass the location of a config file to it (delete the redis.conf line if you&#8217;re not using one):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plist</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Label<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>io.redis.redis-server<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ProgramArguments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/local/bin/redis-server<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/optional/path/to/redis.conf<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RunAtLoad<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You&#8217;ll then need to load the file (one time) into launchd with <code>launchctl</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl load <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>io.redis.redis-server.plist</pre></div></div>

<p>Redis will now automatically be started after every boot.  You can manually start it without rebooting with:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl start io.redis.redis-server</pre></div></div>

<p>You can also shut down the server with</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl stop io.redis.redis-server</pre></div></div>

<p>Or you could add these aliases to your bash/zsh rc file:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">redisstart</span>=<span style="color: #ff0000;">'sudo launchctl start io.redis.redis-server'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">redisstop</span>=<span style="color: #ff0000;">'sudo launchctl stop io.redis.redis-server'</span></pre></div></div>

<p>If you&#8217;re having some sort of error (or just want to watch the logs), you can just fire up <code>Console.app</code> to watch the redis logs to see what&#8217;s going on.</p>
]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2011/03/05/running-redis-as-a-user-daemon-on-osx-with-launchd/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Grails &#8220;run-script&#8221; updated for Grails 1.3.5</title>
		<link>http://naleid.com/blog/2010/12/03/grails-run-script-updated-for-grails-1-3-5/</link>
		<comments>http://naleid.com/blog/2010/12/03/grails-run-script-updated-for-grails-1-3-5/#comments</comments>
		<pubDate>Sat, 04 Dec 2010 04:45:04 +0000</pubDate>
		<dc:creator>tednaleid</dc:creator>
				<category><![CDATA[command line]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://naleid.com/blog/?p=242</guid>
		<description><![CDATA[UPDATE: This script has been merged into the Grails 1.3.6 release so it&#8217;ll be part of core Grails with the next version of grails. You&#8217;ll only need to get it manually for versions earlier than that. A while ago, I created a grails script that allowed the execution of a groovy script within the grails [...]]]></description>
			<content:encoded><![CDATA[<p><em>UPDATE: This script <a href="http://jira.codehaus.org/browse/GRAILS-6015" onclick="pageTracker._trackPageview('/outgoing/jira.codehaus.org/browse/GRAILS-6015?referer=');">has been merged into the Grails 1.3.6 release</a> so it&#8217;ll be part of core Grails with the next version of grails.  You&#8217;ll only need to get it manually for versions earlier than that.</em></p>
<p>A while ago, <a href="http://naleid.com/blog/2008/03/31/using-gant-to-execute-a-groovy-script-within-the-grails-context-updated/">I created a grails script</a> that allowed the execution of a groovy script within the grails context.  Using this gant script gives you access to all of the grails domain objects, hibernate session, and other plugins that you have installed into the app, all from the command line.</p>
<p>It had rotted a bit in the grails 1.3 days (I&#8217;d last updated it for grails 1.2), but finally got around to updating it to work with the latest version of grails (currently 1.3.5).</p>
<p>I&#8217;ve created <a href="http://bitbucket.org/tednaleid/grails-run-script" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-run-script?referer=');">a mercurial repository to hold a test project</a> for <a href="http://bitbucket.org/tednaleid/grails-run-script/src/default/scripts/RunScript.groovy" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-run-script/src/default/scripts/RunScript.groovy?referer=');">the script</a> so that it&#8217;s easy for me to verify that it works with the latest version of grails.</p>
<p>If you don&#8217;t have mercurial installed, you can just <a href="http://bitbucket.org/tednaleid/grails-run-script/raw/default/scripts/RunScript.groovy" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-run-script/raw/default/scripts/RunScript.groovy?referer=');">get the raw version of the file</a> and save it in the &#8220;scripts&#8221; directory of your grails application.</p>
<p>Then you can create a groovy script that you&#8217;d like to execute (often to bootstrap data, or run some periodic process) and execute it with:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">grails run<span style="color: #66cc66;">-</span>script path<span style="color: #66cc66;">-</span>to<span style="color: #66cc66;">-</span>script/scriptName.<span style="color: #006600;">groovy</span></pre></div></div>

<p>I often create my groovy scripts within a &#8220;grails console&#8221; and get them to work there, then save them for later execution by &#8220;run-script&#8221;.</p>
<p>You can see it in action by cloning the sample project out on bitbucket and executing <a href="http://bitbucket.org/tednaleid/grails-run-script/src/default/userScripts/createBook.groovy" onclick="pageTracker._trackPageview('/outgoing/bitbucket.org/tednaleid/grails-run-script/src/default/userScripts/createBook.groovy?referer=');">the sample script</a> I have in it:</p>

<div class="wp_syntax"><div class="code"><pre class="groovy" style="font-family:monospace;">hg clone ssh:<span style="color: #808080; font-style: italic;">//hg@bitbucket.org/tednaleid/grails-run-script</span>
cd grails<span style="color: #66cc66;">-</span>run<span style="color: #66cc66;">-</span>script
grails run<span style="color: #66cc66;">-</span>script userScripts/createBook.<span style="color: #006600;">groovy</span></pre></div></div>

<p>Which shows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Welcome to Grails 1.3.5 - http:<span style="color: #000000; font-weight: bold;">//</span>grails.org<span style="color: #000000; font-weight: bold;">/</span>
Licensed under Apache Standard License <span style="color: #000000;">2.0</span>
....<span style="color: #000000; font-weight: bold;">&lt;</span><span style="color: #c20cb9; font-weight: bold;">more</span> grails output<span style="color: #000000; font-weight: bold;">&gt;</span>...
Running script userScripts<span style="color: #000000; font-weight: bold;">/</span>createBook.groovy ... ...
it worked<span style="color: #000000; font-weight: bold;">!</span>
Script userScripts<span style="color: #000000; font-weight: bold;">/</span>createBook.groovy <span style="color: #7a0874; font-weight: bold;">complete</span><span style="color: #000000; font-weight: bold;">!</span> ...
Application context shutting down...
Application context shutdown.</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://naleid.com/blog/2010/12/03/grails-run-script-updated-for-grails-1-3-5/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

