<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Vincent Garrigues</title>
 <link href="https://garriguv.github.io//atom.xml" rel="self"/>
 <link href="https://garriguv.github.io//"/>
 <updated>2025-01-30T08:11:26+00:00</updated>
 <id>https://garriguv.github.io/</id>
 <author>
   <name>Vincent Garrigues</name>
   <email>hello@garriguv.io</email>
 </author>

 
 <entry>
   <title>Making the most of AppCode's file templates.</title>
   <link href="https://garriguv.github.io//2016/01/11/appcode-file-templates/"/>
   <updated>2016-01-11T00:00:00+00:00</updated>
   <id>https://garriguv.github.io//2016/01/11/appcode-file-templates</id>
   <content type="html">&lt;p&gt;AppCode’s File and Code templates are generated using &lt;a href=&quot;http://velocity.apache.org/engine/index.html&quot;&gt;Velocity&lt;/a&gt;, a Java-based template engine. Taking a few minutes to tweak the existing templates orr create new ones can end up saving you a ton of time down the line.&lt;/p&gt;

&lt;p&gt;What’s a template engine?&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A template processor (also known as a template engine or template parser) is software designed to combine one or more templates with a data model to produce one or more result documents. (&lt;a href=&quot;https://en.wikipedia.org/wiki/Template_processor&quot;&gt;Template processor&lt;/a&gt;)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can find the existing templates in &lt;em&gt;Preferences&lt;/em&gt; &amp;gt; &lt;em&gt;Editor&lt;/em&gt; &amp;gt; &lt;em&gt;File and Code templates&lt;/em&gt;. The data model is a set of predefined &lt;a href=&quot;https://www.jetbrains.com/idea/help/file-template-variables.html&quot;&gt;template variables&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${PROJECT_NAME}&lt;/code&gt; - the name of the current project.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${NAME}&lt;/code&gt; - the name of the new file which you specify in the New File dialog box during the file creation.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${USER}&lt;/code&gt; - the login name of the current user.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${DATE}&lt;/code&gt; - the current system date.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${TIME}&lt;/code&gt; - the current system time.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${YEAR}&lt;/code&gt; - the current year.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${MONTH}&lt;/code&gt; - the current month.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${DAY}&lt;/code&gt; - the current day of the month.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${HOUR}&lt;/code&gt; - the current hour.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${MINUTE}&lt;/code&gt; - the current minute.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${PRODUCT_NAME}&lt;/code&gt; - the name of the IDE in which the file will be created.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${MONTH_NAME_SHORT}&lt;/code&gt; - the first 3 letters of the month name. Example: Jan, Feb, etc.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${MONTH_NAME_FULL}&lt;/code&gt; - full name of a month. Example: January, February, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also add your own variables. They’ll be added to the file creation prompt:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://garriguv.github.io//assets/images/appcode-file-template.png&quot; alt=&quot;New file prompt&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Combining the template with the data model is actually very easy. A good example I came across is the creation of test files. Let’s say you want to write tests for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyClass&lt;/code&gt;, you need to create a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyClassSpec.h&lt;/code&gt; file. A good starting point for that file could be the following:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/garriguv/ede7618af6a2dcd57901.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;The problem is that it’s not possible to generate this file using only the predefined template variables, because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${NAME}&lt;/code&gt; will equal &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyClassSpecs&lt;/code&gt; and not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MyClass&lt;/code&gt;. You can either add another variable or use Velocity to get the desired result. We’ll look into the latter.&lt;/p&gt;

&lt;p&gt;It’s possible to execute Java code in velocity templates, which means that we can use Java’s &lt;a href=&quot;http://docs.oracle.com/javase/8/docs/api/index.html?java/lang/String.html&quot;&gt;String&lt;/a&gt; methods to manipulate the file name and extract the base class’ name:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/garriguv/03c61706a745f6f68cb4.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;In the end, this is what the Spec template looks like:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/garriguv/973112a964eed09ba2e1.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;That’s it!&lt;/p&gt;

&lt;p&gt;I’ve setup a quick project to experiment with [Velocity] templates, you’ll find it here: &lt;a href=&quot;https://github.com/garriguv/velocity&quot;&gt;https://github.com/garriguv/velocity&lt;/a&gt;&lt;/p&gt;
</content>
 </entry>
 
 <entry>
   <title>How to set up Mjolnir for window management</title>
   <link href="https://garriguv.github.io//2015/10/25/mjolnir/"/>
   <updated>2015-10-25T00:00:00+00:00</updated>
   <id>https://garriguv.github.io//2015/10/25/mjolnir</id>
   <content type="html">&lt;p&gt;After updating my mac to El Capitan, I was about to re-install my habitual window manager (&lt;a href=&quot;http://mizage.com/divvy/&quot;&gt;Divvy&lt;/a&gt;), but because it’s Sunday, and the grass is always greener elsewhere, I started looking for an alternative.&lt;/p&gt;

&lt;p&gt;The usual suspect showed up: &lt;a href=&quot;https://manytricks.com/moom/&quot;&gt;Moom&lt;/a&gt;. I used it before but as with &lt;a href=&quot;http://mizage.com/divvy/&quot;&gt;Divvy&lt;/a&gt;, there was something I didn’t quite like with it.&lt;/p&gt;

&lt;p&gt;But then I stumbled on a gem: &lt;a href=&quot;https://github.com/sdegutis/mjolnir&quot;&gt;Mjolnir&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Mjolnir is an OS X app that lets you automate common tasks using the language Lua.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, yeah. Something even less user friendly than a regular window manager, but I haven’t done any Lua yet and I can sync the config across multiple machines: SOLD. To top it off, the logo is awesome.&lt;/p&gt;

&lt;h3 id=&quot;how-to-make-mjolnir-resize-your-windows&quot;&gt;How to make Mjolnir resize your windows&lt;/h3&gt;

&lt;p&gt;First, install &lt;a href=&quot;https://github.com/sdegutis/mjolnir&quot;&gt;Mjolnir&lt;/a&gt; and enable accessibility:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://garriguv.github.io//assets/images/mjolnir-0.png&quot; alt=&quot;Enable accessibility in Mjolnir&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s install &lt;a href=&quot;http://www.lua.org/&quot;&gt;Lua&lt;/a&gt; and &lt;a href=&quot;https://luarocks.org/&quot;&gt;LuaRocks&lt;/a&gt; (The Lua package manager), we’ll use homebrew for this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ brew update
$ brew install lua
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then we need to install a few modules:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ luarocks install mjolnir.hotkey
$ luarocks install mjolnir.application
$ luarocks install mjolnir.bg.grid
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can find the entire list of modules here: &lt;a href=&quot;http://rocks.moonscript.org/search?q=mjolnir&quot;&gt;http://rocks.moonscript.org/search?q=mjolnir&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the fun starts, let’s create &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.mjolnir/init.lua&lt;/code&gt; and add a few window resize shortcuts:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/garriguv/49bd7e6fc048e0094346.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;While writing the scripts, use the Mjolnir console to reload the file. Just type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mjolnir.reload()&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://garriguv.github.io//assets/images/mjolnir-1.png&quot; alt=&quot;Mjolnir console&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You can install &lt;a href=&quot;https://github.com/sdegutis/mjolnir&quot;&gt;Mjolnir&lt;/a&gt;’s documentation in &lt;a href=&quot;https://kapeli.com/dash&quot;&gt;Dash&lt;/a&gt;. Just search for it in the &lt;em&gt;User contributed&lt;/em&gt; section.&lt;/p&gt;

&lt;p&gt;The above script is very basic and there’s a lot of repetition. Since we’re basically using a grid based layout, there’s already a module for that: &lt;a href=&quot;http://luarocks.org/modules/briangilbert/mjolnir.bg.grid&quot;&gt;mjolnir.bg.grid&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The program then becomes simpler and shorter:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/garriguv/ab65283e6b68bc88185e.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;Happy scripting!&lt;/p&gt;

&lt;p&gt;If you want to learn more, I can recommend this blog post: &lt;a href=&quot;http://thume.ca/howto/2014/12/02/using-mjolnir-an-extensible-osx-window-manager/&quot;&gt;Using Mjolnir&lt;/a&gt;&lt;/p&gt;

</content>
 </entry>
 
 <entry>
   <title>Slow AppCode? Here's how to fix it.</title>
   <link href="https://garriguv.github.io//2015/10/25/appcode-memory-limit/"/>
   <updated>2015-10-25T00:00:00+00:00</updated>
   <id>https://garriguv.github.io//2015/10/25/appcode-memory-limit</id>
   <content type="html">&lt;p&gt;I love AppCode, but sometimes it can get excruciatingly slow when working on large projects. A good thing to check in those cases is the memory usage. Here’s how to access it:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://garriguv.github.io//assets/images/appcode-memory.png&quot; alt=&quot;Showing AppCode&apos;s memory consumption&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You’ll now have a little memory indicator in the bottom right toolbar of the IDE. If you see that the memory fills up instantly when opening your project, then maybe it’s time to increase it.&lt;/p&gt;

&lt;p&gt;AppCode runs on the JVM, and you can change the JVM parameters. First, copy the default launch options to AppCode’s preferences directory:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ cp /Applications/AppCode.app/Contents/bin/appcode.vmoptions \
        ~/Library/Preferences/AppCode33
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then edit the copied &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;appcode.vmoptions&lt;/code&gt; file. You should change both the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Xmx&lt;/code&gt; (memory limit) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Xms&lt;/code&gt; (initial memory allocation) options.&lt;/p&gt;

&lt;p&gt;This set of values has been working pretty well so far:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/garriguv/c769aa160fc219269ed2.js&quot;&gt; &lt;/script&gt;

&lt;p&gt;You don’t necessarily have to go up to 4 GB of memory limit. But since the new MacBook Pro ships with 16 GB of memory, why not use some of it?&lt;/p&gt;
</content>
 </entry>
 

</feed>
