• Home
  • Blogger
  • Github
  • Travel
  • The Tank Project
skip to main | skip to sidebar

Steven Occhipinti

A braindump.

Vi mode for Bash

So it turns out bash has a vi mode!
(Can't believe I didn't know about this earlier)

To enable vi mode, just type this into your shell:
$> set -o vi

That will enable it for this shell so you can try it out, and if you like it, add that line to your ~/.bashrc file for future.

One really useful vi-mode command is pressing 'v' from command mode. This will put your current command line into vim to modify.

To get more help on the commands available in vi-mode, take a look at the bottom of this man page:
$> man 3 readline

To get more information on the various options available for bash, take a look at:
$> help set

I'm going to give it ago in the coming weeks to see if its actually useful or not.

So far, I've found one small annoyance, I use ctrl+l to clear the terminal, but with the vi key bindings enabled, this only works from command mode (you have to hit ESC first).
To fix this, I added this to my ~/.bashrc file:
bind -m vi-insert 'Control-l: clear-screen'

These commands could also be added to /etc/inputrc, but I'm happy to leave these 2 lines together in my ~/.bashrc so its easier to remember.
Posted by Steve at 09:22 1 comments
Labels: bash , linux , vim Email This BlogThis! Share to X Share to Facebook

PhpRemoteAdmin

If you've ever used PhpMyAdmin before, you'll know it can be quite handy, especially for people like me who always forget SQL's syntax.
I even use it for simple tasks just so I can see what SQL it generated and it even has a handy "Create PHP Code" button to give me a baseline to start hacking the query to suit my situation.

This is great for local setups, but sometimes I need to do a query a production database where PhpMyAdmin is not installed and its alot easier to inspect the data of big tables with a gui (at least for me anyway).

Another helpful tip that I picked up from my new work place (thanks Rich) is to make PhpMyAdmin connect to a remote database via an SSH tunnel.
It requires a small config change to PhpMyAdmin, but it works a charm!

To differentiate between a tunnelled database and the local one, you need to configure your web server to serve up PhpMyAdmin from an additional URL, such as http://localhost/phpremoteadmin in addition to the standard http://localhost/phpmyadmin.

I added a second alias for PhpMyAdmin in /etc/apache2/conf.d/phpmyadmin.conf to look like this:

Alias /phpmyadmin /usr/share/phpmyadmin
Alias /phpremoteadmin /usr/share/phpmyadmin

Then, I modified my /etc/phpmyadmin/config.inc.php to include this:

// If phpremoteadmin is requested, use an ssh tunnel on 6666
// Note: This doesn't create the tunnel, use ~/bin/mysql_remote
if (substr_count($_SERVER["REQUEST_URI"], "phpremoteadmin") > 0) {
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['port'] = '6666';
$cfg['Servers'][$i]['host'] = '127.0.0.1';
}

Basically that means if the request is for /phpremoteadmin, look for the database on port 6666 instead of the preconfigured database port.

You'l have to reload apache for these changes to take effect:
sudo /etc/init.d/apache2 reload

Then you need a SSH tunnel from your local port 6666 to the servers port 3306 (where mysql is normally listening). To create this tunnel, you can use:

ssh -L 6666:localhost:3306 $USER@$HOST

But, to make it easier, I use (a slight variation) of this script:

#!/bin/sh

if [ $# -lt 1 ] || [ $# -gt 2 ]; then
  echo "Usage: $0 host1 [host2]"
  exit 2
fi

USER="steve"
HOST=$1

DBHOST="localhost"
[ -z "$2" ] || DBHOST="$2"

echo "Browse to: http://localhost/phpremoteadmin"
ssh -L 6666:$DBHOST:3306 $USER@$HOST

The script also allows you to pass in an optional argument of the host where the database is.
By default, that is localhost (the remote server's localhost).
This is useful if you can only ssh to a gateway server and the database is on another server within that remote network that you wouldn't normally be able to ssh directly to.

This has been really helpful, so I wanted to share :)
Posted by Steve at 12:56 6 comments
Labels: apache , lamp , linux , mysql , php Email This BlogThis! Share to X Share to Facebook

Bash auto-complete

There are a ton of extended auto-completions that come with Ubuntu, but they are disabled by default.

Have a look in the /etc/bash_completion.d/ directory for the programs that have specific auto-completes (such as apt-get, git, apache2ctl, etc.).

To get all the extra auto-completion-goodness, all you have to do is source /etc/bash_completion in your profile.

I added this is my .bashrc, but there may already be a commented out block for this in the stock .bashrc file for ubuntu:
# Enable bash completion in interactive shells
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
Posted by Steve at 15:40 0 comments
Labels: bash , linux , ubuntu Email This BlogThis! Share to X Share to Facebook

Can't open file for writing

E212: Can't open file for writing
Press ENTER or type command to continue
If you use vim, you have probably come across this error before.
It normally happens when you don't have permission to write to your chosen destination.

The temporary solution has traditionally been to save your changes to somewhere where you do have permissions (such as /tmp or ~), then use sudo to cp it across, or re-open the file in vim with sudo.

A collegue at work showed me a great trick to get around this when it happens (Thanks Rich). All you have to do is add this to your .vimrc file:
 command! W w !sudo tee % > /dev/null
Then when you come across this error again, instead of of using :w you can use :W and it will prompt you for your sudo password before saving.
Works brilliantly!
Posted by Steve at 23:09 0 comments
Labels: linux , vim Email This BlogThis! Share to X Share to Facebook

Flashy Prezis @ DDD

DDD Melbourne was on at Swinburne Uni on last weekend and a couple of friends and I went along.

This event was more targeted at Microsoft technologies, but there was a bit of other stuff to keep me interested.
I got to see some pretty neat JavaScript stuff, learned a thing or two about the vast range of Microsoft technologies, got to re-visit Android 101 and eat plenty of junk food!
I love that us nerds love pizza and cake! :)

Now as good as the day was, the topic I picked to blog about actually has nothing to do with the content of any of the talks.
This is partially because a fair amount of the MS tech stuff went over my head, but more to do with the website that I'm about to talk about is something I might consider for my own use in the future.

One of the speakers had a really neat presentation that kept the audiences attention with fancy transitions and clever choice of images and at the end of the presentation, we found out that it was all done through a site called prezi.com

Anyway, instead of me ranting on about it, it really has to be seen.
Here is a quick "Prezi" I knocked up, but this doesn't compare to the impressive prezi I saw at DDD:
http://prezi.com/8p2z_a_ua4mh/my-first-prezi/

Browsing through the community prezi's would probably give you a better Idea :)

Posted by Steve at 20:49 0 comments
Labels: websites Email This BlogThis! Share to X Share to Facebook

Flashy Prezis @ DDD

DDD Melbourne was on at Swinburne Uni on last weekend and a couple of friends and I went along.

This event was more targeted at Microsoft technologies, but there was a bit of other stuff to keep me interested.
I got to see some pretty neat JavaScript stuff, learned a thing or two about the vast range of Microsoft technologies, got to re-visit Android 101 and eat plenty of junk food!
I love that us nerds love pizza and cake! :)

Now as good as the day was, the topic I picked to blog about actually has nothing to do with the content of any of the talks.
This is partially because a fair amount of the MS tech stuff went over my head, but more to do with the website that I'm about to talk about is something I might consider for my own use in the future.

One of the speakers had a really neat presentation that kept the audiences attention with fancy transitions and clever choice of images and at the end of the presentation, we found out that it was all done through a site called prezi.com

Anyway, instead of me ranting on about it, it really has to be seen.
Here is a quick "Prezi" I knocked up, but this doesn't compare to the impressive prezi I saw at DDD:
http://prezi.com/8p2z_a_ua4mh/my-first-prezi/

Browsing through the community prezi's would probably give you a better Idea :)

Posted by Steve at 20:49 0 comments
Labels: websites Email This BlogThis! Share to X Share to Facebook
Newer Posts Older Posts Home

Blog Archive

  • ►  2013 (4)
    • ►  June (1)
    • ►  May (1)
    • ►  March (1)
    • ►  January (1)
  • ►  2012 (17)
    • ►  December (1)
    • ►  October (1)
    • ►  September (2)
    • ►  August (2)
    • ►  July (1)
    • ►  May (2)
    • ►  April (2)
    • ►  March (3)
    • ►  February (3)
  • ▼  2011 (33)
    • ►  December (1)
    • ►  November (3)
    • ►  October (3)
    • ►  September (4)
    • ►  August (3)
    • ►  July (4)
    • ▼  June (6)
      • Vi mode for Bash
      • PhpRemoteAdmin
      • Bash auto-complete
      • Can't open file for writing
      • Flashy Prezis @ DDD
      • Flashy Prezis @ DDD
    • ►  May (6)
    • ►  April (3)

Labels

android (5) apache (1) arch linux (1) arduino (1) bash (11) calendar (1) compiz (1) design (1) diff (1) email (1) gimp (1) git (3) github (2) gnome3 (1) Google (2) hacking (1) hardware (4) howto (1) htpc (1) java (1) lamp (1) linux (28) Mac (2) minecraft (2) mysql (1) netduino (1) nfs (1) parallel port (1) patch (1) photography (4) php (1) pidgin (2) printer (1) programming (6) python (1) rails (1) regex (5) review (3) ruby (3) Samsung Galaxy S3 (2) Samsung Series 9 (1) security (1) sed (3) ssh (1) sudo (1) tank (2) Toshiba Portege (1) troubleshooting (1) ubuntu (16) ui (2) unity (2) vim (5) webcam (1) websites (3) xbmc (1) xclip (1) xul (1)

Total Pageviews

Sparkline
 
Copyright (c) 2010 Steven Occhipinti. Designed by Conveyancing
High Deductible Health Insurance, Purchase Beats