Archive

Archive for September, 2013

Create and start VirtualBox VM from command-line

September 28, 2013 Leave a comment
Categories: ubuntu Tags:

Securing an Ubuntu server

September 26, 2013 Leave a comment

Some tips on installing/securing an Ubuntu server:

Categories: ubuntu Tags:

ssh

September 26, 2013 Leave a comment

Some notes about ssh

Install the sshd server:

sudo apt-get install openssh-server

Server start/stop/status/restart:

sudo service ssh {start|stop|status|restart}

Server config file:

/etc/ssh/sshd_config    # make a backup first

Here you can change the port (which is a good idea), disable PermitRootLogin, etc. You can also add these two lines to the end:

UseDNS no
AllowUsers USERNAME

Where USERNAME is the username of the user who can log in. Only (s)he can log in, nobody else.

Log in to a non-standard port:

ssh username@host -p PORT
Categories: ubuntu Tags:

HTML: add syntax-highlight to textarea

September 26, 2013 1 comment

Problem
You have an HTML form with a textarea where you want to accept some source code. You want to turn this simple textarea into a fancy input area that adds syntax highlighting.

Solution
I tried EditArea, and it suits my needs. See this SO page for more alternatives.

EditArea

EditArea is a free javascript editor for source code. This editor is designed to edit souce code files in a textarea. The main goal is to allow text formatting, search and replace and real-time syntax highlight (for not too heavy text).” (source)

For Python support, I had to add these lines to the HTML source:

<script language="javascript" type="text/javascript" src="../editarea/edit_area/edit_area_full.js"></script>
<script language="javascript" type="text/javascript">
editAreaLoader.init({
    id : "src_input"       // textarea id
    ,syntax: "css"          // syntax to be uses for highgliting
    ,start_highlight: true      // to display with highlight mode on start-up
    ,syntax: "python"
    ,replace_tab_by_spaces: 4
});
</script>

Related work

  • Ace (it seems a more professional solution)

Ubuntu: disable Alt to launch HUD

September 26, 2013 Leave a comment

Problem
In Ubuntu (with Unity), Alt launches the HUD. Fine. However, if you have a Windows in VirtualBox and you want to switch windows in the guest VM with Alt+TAB, that damn HUD always appears in the host. How to disable it?

Solution
I found the solution here.

In short: top right corner, System settings… -> Keyboard -> Shortcuts tab -> Launchers. Assign a new key to “Key to show the HUD“, or disable it completely by pressing the Backspace.

Categories: ubuntu, windows Tags: , , , ,

mkdir && cd

September 24, 2013 Leave a comment

Frustration
Has it ever happened to you?

$ mkdir something
$ cd something

Damn, that’s 2 commands. How to simplify it?

Solution

$ pwd
/home/jabba
$ mdgo something    # mdgo stands for: mkdir-go
$ pwd
/home/jabba/something

That is, the command “mdgo” creates a directory and enters in it. An alternative name could be “mdcd“.

If you want this alias, add the following lines to your ~/.bashrc:

mkdir_go()
{
if [[ -z "$1" ]]
then
    echo "Usage: mdgo <dir>"
else
    mkdir $1; cd $1
fi
}
alias mdgo=mkdir_go
Categories: bash Tags: ,

GyerekTV.hu [hu]

September 24, 2013 Leave a comment

This post is written in Hungarian.


A GyerekTV.hu azzal a céllal jött létre, hogy a gyerkőcök olyan meséket is láthassanak a weben, amiket a tv nem közvetít. Főleg a régebbi, klasszikus meséket helyezzük középpontba. Véleményünk szerint amíg a gyerekek ezen az oldalon nézik a jobbnál-jobb meséket, nem fognak a televízió előtt ülni és esetleg a nem nekik való műsorba futni.

Igyekszünk folyamatosan bővíteni a kínálatot!
Jelenleg 55 mesekategória és 1500+ meserész található oldalunkon!
” (source)

Ajánló

Categories: fun Tags: , ,

VirtualBox: accessing the guest from the host

September 23, 2013 Leave a comment

Problem
In a VirtualBox guest machine I wanted to set up a web server for testing purposes. How to access the guest’s web server from the host?

Solution
In the guest’s network settings, normally you already have a NAT network adapter. This way the guest can access the Internet.

But how to establish a network communication between the host and the guest? In the guest’s network settings, select the tab “Adapter 2”. At home “Bridged Adapter” worked for me.

However, at my workplace “Bridged Adapter” didn’t work. After some research I wanted to try “Host-only Adapter”, but I ran into a difficulty. I couldn’t add a host-only adapter, I got the following error message: “no host-only network adapter selected”. And the GUI didn’t offer anything in the dropdown list :(

FeBc6

Fortunately I found the solution here. The image above was also borrowed from askubuntu.com.

For future references, I quote the steps here:

Probably, the virtual host-only network wasn’t set up yet. Here’s is how you can fix this:

  1. From the main menu, select File > Preferences (Ctrl+G) – NOT the settings of a single vm
  2. Select Network in the list on the left
  3. You should see an empty white box with “Host-only Networks” at the top. On the right, there are three buttons to manage them. Click the topmost one (with a green plus symbol). A new Host-only network will be created and added to the list.

Normally, the settings of the new network will be ok, but for completeness, I give the default values here. You can access the settings for the host-only network through the screwdriver button on the right.

  • Adapter:
    • IPv4 address: 192.168.56.1
    • IPv4 Network Mask: 255.255.255.0
  • DHCP server:
    • Enable server: checked
    • Server Address: 192.168.56.100
    • Server Mask: 255.255.255.0
    • Lower Address Bound: 192.168.56.101
    • Upper Address Bound: 192.168.56.254

You can change these settings to your liking, as long as they’re consistent.

Thanks to Bert Van Vreckem for this great answer.

Guest’s IP address
Executing “ifconfig” in the guest, you’ll get its IP address. Mine is under “eth1”, next to “inet addr:”. Try to ping the guest from the host and vice versa. They should work :)

Categories: network Tags: , , ,

alias with an argument

September 21, 2013 Leave a comment

Problem
In bash, you want to write an alias that receives an argument.

Solution
Well, you can’t do that in bash. But there is a workaround: call a bash function, and the function can treat the argument.

Let’s see a concrete example. While working with Python virtual environments, I wanted to be able to activate a virtual env. easily with the command “workon <DIR>“, where “workon” would be an alias and “<DIR>” is the name of a directory. (Detailed post is here.)

Add the following lines to your ~/.bashrc:

func_workon()
{
if [[ -z "$1" ]]
then
    echo "Usage: workon <venv>"
else
    . $1/bin/activate
fi
}
alias workon=func_workon
Categories: bash, python Tags: ,

a cool colorized prompt for bash

September 21, 2013 1 comment

Problem
You want a cool colorized bash prompt.

Solution
While hunting for a prompt that I could use with virtualenv (post here), I found a prompt that is way cooler than the default bash prompt. I made a fork of it, you can find it here.

Note that it’s not me who wrote it. I just changed one line :)

Usage
Save the file above as ~/.bash_prompt and add the following line to the end of your ~/.bashrc:

source ~/.bash_prompt

Screenshot
workon

Categories: bash Tags: ,