Sunday, February 10, 2013

Sublime Text 3 Quick Install and Setup for Rails on Linux

Sublime Text 3 Beta is now open to non-registered users (27 June 2013).
Sublime Package Control for ST3 is currently in Alpha.

Install ST3


Download latest deb build from http://www.sublimetext.com/3
Install (double click) then copy / paste your licence
If you have a conflict with ST2 then remove it (see below) or download the tarball

sudo apt-get remove --purge sublime-text-2
sudo apt-get autoremove

Install Package Control

http://wbond.net/sublime_packages/package_control/installation#ST3

cd /home/username/.config/sublime-text-3/Packages
git clone https://github.com/wbond/sublime_package_control.git "Package Control"
cd "Package Control"
git checkout python3


Add some Basic User Settings (adjust according to your preferences)
Preferences > Settings - User
{
"color_scheme": "Packages/RailsCasts Colour Scheme/RailsCastsColorScheme.tmTheme",
"detect_indentation": false,
"font_face": "Consolas",
"font_size": 13,
"ignored_packages":
[
"Vintage"
],
"scroll_past_end": false,
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": true
}

Use Package Control to install a Theme
Popular packages are: RailsCasts Colour Scheme, Theme - Soda, Solarized Color Scheme

Update your Preferences > Settings - User to swap
Use Package Control to install syntax highlighting
Haml, Sass, Less, Coffeescript select them as defaults for the corresponding filetypes (click on the current filetype at the bottom right of ST3 window).

ERB Insert and Toggle Commands
https://github.com/eddorre/SublimeERB

Add to User Keybinding File
[
  { "keys": ["ctrl+shift+."], "command": "erb" }
]

Run Tests in the console
Install RubyTest https://github.com/maltize/sublime-text-2-ruby-tests

You must run Sublime Text 3 from the command line (subl)

control shift t Run all tests in the file
control shift e Run last test

There are issues with Colour output and esc characters - you may prefer to use the linux terminal

Create a plugin to Open file in browser
Tools > New plugin...

Copy code below / paste / save as OpenBrowser.py
# OpenBrowser.py
import sublime, sublime_plugin
import webbrowser

class OpenBrowserCommand(sublime_plugin.TextCommand):
   def run(self,edit):
      url = self.view.file_name()
      webbrowser.open_new(url)

Add to User Keybindings to Open file in new browserPreferences > Key Bindings - User

Copy code below / paste / save
[
  { "keys": ["ctrl+shift+b"], "command": "open_browser" }
]

Monday, September 17, 2012

Install pgAdmin for PostgreSQL 9.2 on Ubuntu 12.04


The Ubuntu 12.04 package manager will install pgadmin3 version 1.14 which does not support PostgreSQL 9.2.

Warning:
The server you are connecting to is not a version that is supported by this release of pgAdmin III.
pgAdmin III may not function as expected.
Supported server versions are 8.2 to 9.1.

Remove the current pgAdmin version


sudo apt-get remove pgadmin3


Install pgAdmin version 1.16 using a ppa


sudo apt-add-repository ppa:voronov84/andreyv
sudo apt-get update
sudo apt-get install pgadmin3


Update: If you are having trouble with the method above (see comments below) try the .deb install.

pgAdmin 1.16 (amd64)
pgAdmin 1.16 (i386)


Saturday, September 15, 2012

Replace PostgreSQL 9.1 with 9.2 in Ubuntu 12.04

Recently released PostgreSQL 9.2 comes with a heap of new features and improvements over 9.1.

These are the steps I took to remove 9.1 and install PostgreSQL 9.2 in Ubuntu 12.04.

Warning: This procedure is suitable for test and development environments only as it will wipe out all 9.1 databases


1. List currently installed postgres packages


sudo dpkg -l | grep postgres


2. Remove postgresql-9.1

*these packages were on my system

sudo apt-get --purge remove postgresql postgresql-9.1 postgresql-client-9.1 postgresql-client-common postgresql-common postgresql-doc postgresql-doc-9.1


3. Install postgresql-9.2 with official ppa


sudo add-apt-repository ppa:pitti/postgresql
sudo apt-get update
sudo apt-get install postgresql-9.2

If you cannot add the repository
sudo: add-apt-repository: command not found

Install this package

sudo apt-get install python-software-properties


4. Check postgresql is set to the default port 5432


sudo netstat -lp | grep postgresql


5. Reset to default port if necessary


sudo gedit /etc/postgresql/9.2/main/postgresql.conf

port = 5432 *change the port value in the conf file

sudo /etc/init.d/postgresql reload


6. Setup your project database / user and database.yml


PostgreSQL Setup for Rails Development (skip to step 2)


Sunday, August 12, 2012

Could not find a JavaScript runtime

Devs new to Linux will hit a 'Could not find a JavaScript runtime' error when trying to start a rails server.

The reason for this is Linux, by default, does not have an interface to a JavaScript engine.

Use one of these methods to install the interface required:

  1. Add The Ruby Racer gem to your Gemfile assets group:

    group :assets do
      gem 'therubyracer'
    end

    * Its a bit of a memory hog (Heroku discourage it) and you need to add it to every project you spin up on that machine.


  2. Install the Node.js package to your machine:

    sudo apt-get install nodejs

    * Distro specific installation: Installing Node.js by Package Manager