View posts for » January, 2009

Backing up and restoring MySQL databases

Back up:
mysqldump -u myuser -p mydb > dump.sql

Restore:
mysql -u myuser -p mydb < dump.sql

Comments (2)

Create new MySQL database and user

mysql -u root -p
mysql> create database dbname default character set utf8;
mysql> grant usage on *.* to dbuser@localhost identified by 'userpass';
mysql> grant all privileges on dbname.* to dbuser@userpass ;
mysql -u dbuser -p'userpass' dbname

Comments (0)

Configure folder visibility in Textmate

I like Texmate to show all the hidden folders and files, except .DS_Store and .Thumbs.db.

Open Preferences->Advanced->Folder References

Empty Folder pattern and put in File pattern: !(.DS_Store|Thumbs.db)

Comments (0)

Opening rubygems in Textmate

Create /usr/local/bin/mategem with:

Make it executable:
chmod +x /usr/local/bin/mategem

To autocomplete with tab add this to ~/.profile:

Reload:
source ~/.profile

Now to list all gems:
mategem [tab][tab]

The original tutorial.

Comments (0)

My most used Texmate shortcuts

control+shift+w: wrap text with tag
control+sift+command+w: wrap each line with tag
control+shift+l: wrap text with link to clipboard’s url
command+/: comment

control+shift+.: open erb code

command+control+t: select bundle window
command+shift+t: go to symbol window

command+shift+l: select line
control+shift+d: duplicate line
command+control+up/down: move line

command+alt+right/left: change tab

def+tab: function
cla+tab: class
tc+tab: test case
ase+tab: assert equal

Comments (0)

Grep in project for Textmate

If you are working in a bit big project and you try to Find in Project with Textmate, probably it’ll get frozen. The grep in project command is much more effective. Download it and double click on it. It replaces the Command+Shift+F default. More info.

Comments (0)

Install Haml and Sass Textmate Bundles

In one of my last projects I had the opportunity to try Haml and Sass. I’m quite happy with it: the code is neat and clear, forcing the developers to maintain it correctly nested (something less usual as it should be), plus some other advantages like the CSS variables or output styles.

To highlight properly in Textmate install the Bundles:

cd ~/Library/Application\ Support/TextMate/Bundles
svn co "http://macromates.com/svn/Bundles/trunk/Bundles/Ruby Haml.tmbundle"
svn co "http://macromates.com/svn/Bundles/trunk/Review/Bundles/Ruby Sass.tmbundle"

Reload bundles (Bundles->Bundle Editor->Reload Bundles)

Comments (0)

Install Git Textmate bundle

cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://gitorious.org/git-tmbundle/mainline.git Git.tmbundle

In the TextMate preferences, advanced tab, shell variables, set the TM_GIT variable to point to /opt/local/bin/git (if installed via MacPorts).

Reload bundles (Bundles->Bundle Editor->Reload Bundles).

Now it works as the SVN bundle, but pressing Ctrl+Shift+G.

Comments (0)

Update SVN user and password, through https

If you have a svn+ssh repository and you change the username or password, you’ll need to authenticate again checking out the code:

svn co svn+ssh://[email protected]/path/to/project project

But if the service is through https, you’ll need a special option in the command:

svn co --username user https://server.com/path/to/project project

Comments (0)

Deploy Sinatra applications in Dreamhost

Dreamhost is a great hosting, and now that they use Phusion Passenger (mod_rails), we can host Rack based applications, like Sinatra.

Adding the great repository hosting by github, we can have a professional deploying system for our home made projects.

  • Create the folder structure:
    myapp/
      public/
      tmp/
      views/

  • Create your sinatra app, myapp/mywebapp.rb
  • Create the Passenger rackup file, myapp/config.ru
  • In panel.dreamhost.com go to Manage Domains -> Add Domain/Sub Domain.
  • Fill the domain/subdomain to host the application, enable mod_rails (Passenger), and add /public to the web directory.
  • Install sinatra:

    Connect to your host via SSH

    ssh [email protected]

    gem install sinatra

    This will install sinatra for your user in ~/.gem

Now we could upload via FTP the application to the new domain generated.

If we need to restart the app, just create a restart.txt file in the tmp folder

touch tmp/restart.txt

But we want to use git as repository of the code, and capistrano for the deployment instead of upload manually. This are the steps:

  • Go to github.com and create the new repository.
  • Go to your project folder initialize git, commit and push to our new repository:
    cd myapp
    git init
    git add .
    git commit -m'first import'
    git remote add origin [email protected]:user/project.git
    git push origin master
  • Configure capistrano;
    cd myapp
    mkdir config
    capify .

    Edit config/deploy.rb

  • Be sure that you have empty the domain folder in the server, and setup the capistrano structure:
    cap deploy:setup
  • In Dreamhost edit your domain and add /current/public to the web directory.
  • Now you can deploy:
    cap deploy
  • After this steps, Passenger couldn’t find the sinatra gem again, but was solved installing it again. Weird…

    Now you can also restart the app with:
    cap deploy:restart

Comments (0)