MinimalVS.NET: How to make Visual Studio 2010 a little more TextMate-y

If, like me, you use TextMate at home and Visual Studio at work, then you might find this handy. I like the short cuts used in TextMate (and almost all applications on Linux/OsX) to close windows and navigate open tabs.

  • Grab the “Monaco” font here and install that mofo.
  • Then, grab my Ultimate TextMate settings file here (right click, save as). This Theme is a variant of Rob Conery’s Vibrant Theme. I added JS and CSS settings and tweaked the C# settings a bit.
  • Find and remove all bindings to “CTRL+W” and re-assign it to “File.Close”
  • Install the “Windows Productivity Tools” here
  • Next, find the “Window.NextDocumentWellTab” short cut (added by Productivity Tools) and unmap it from all commands. Add “ALT+SHIFT+]” for next tab
  • Then, find the “Window.PreviousDocumentWellTab” short cut (added by Productivity Tools) and unmap it from all commands. Add “ALT+SHIFT+[“ for previous tab
  • Find the “View.SolutionExplorer” shortcut and map it to “ALT+D”
  • Find the “Window.CloseToolWindow” and map it to “ALT+X”

Note: I have cheated a bit on the last two as we don’t have a Command key, but hopefully I made it a bit simpler.

The last thing to do, is to move SolutionExplorer to the left side and remove all toolbars and tool windows. Now you should have a very clean Visual Studio and can use Resharper’s GoTo commands to navigate your solution and only use “ALT+D” and “ALT+X” to show/hide the SolutionExplorer when needed.

A challenge for you: Try to go a whole day without using the mouse. In fact, put that bugger far out of reach behind your computer.


PS: I didn’t include the Keyboard shortcuts in the settings file, as I thought you might like to mix an match those to your preference.

Using Dalli client with Heroku Memcache plugin in Sinatra

Today we are going to learn how to use the Memcache plugin on Heroku in a Sinatra app. We will be using a gem called ‘Dalli’. Memcache means ‘a general-purpose distributed memory caching system’ or in other words, something cool, fast and easy to use for speeding up your website. The way to do this is to cache certain parts of your application for a specific time period (ttl) so that users on your site would share the same data output and not need to trigger the data collection mechanism for each request.

Lets get to it! First we have to enable the Memcache plugin on heroku, so go ahead and find the plugin (see screenshot) and add it to your app.

The 5MB version is free and should be adequate enough for your average blog, brochure website. In a commercial website, don’t be surprised if the number is closer to 20GB.

Adding the Memcache plugin would add the necessary environment variables that ‘Dalli’ needs to use. So, lets go ahead and add ‘Dalli’ to our Gemfile….

gem 'dalli'

and install it…

bundle install

Next we need to set up ‘Dalli’ in our rack_app.rb

require 'sinatra'
require 'erb'
require 'dalli'

set :cache, Dalli::Client.new
set :enable_cache, true
set :short_ttl, 400
set :long_ttl, 4600

get '/' do
  erb :index
end

You can play around with the :short_ttl and :long_ttl times to find the best setting for your content, but it wouldn’t be frowned upon to cache certain things for hours or even days (ie. ‘Post of the week’ promotion on your homepage).

Next we simply need to store our data in ‘Dalli’ whenever we want to cache it, and remember to look for it before using our time consuming fetching mechanism. We will do this with a CacheKey.

get '/' do

  @todays_posts = get(:todays_posts)
  erb :index

end

def get(key, time_to_live=settings.long_ttl)

  if(!settings.enable_cache)
    return some_really_complicated_dataretrieval(key);
  end
  if(settings.cache.get(key) == nil)
    settings.cache.set(key, some_really_complicated_dataretrieval(key), ttl=time_to_live+rand(100))
  end

  return settings.cache.get(key)

end

Note that I added a rand(100) to the TTL. This is so that when the cache refreshes, it doesn’t refresh all the items with the same TTL at once. This would cause a small hiccup in performance at that time. Thats it! That should be all you need to use Memcache on Heroku using Sinatra.