Image

How to use Vim auto-complete

How to use Vim auto-complete

By  •  Vim

Beginning version 7, Vim started to introduce its auto-complete feature. By default it works by being able to auto-complete words that already existed in the file being edited. If enabled, it can also auto-complete syntax for various programming languages.

To use the Vim auto-complete feature, just hit Ctrl + n while in insert mode, and you’ll get a list of word suggestions as in the following example;

To make the list cycle backwards, hit Ctrl + p. You can also use the arrow keys to move up and down the list.

How to build a Debian chroot environment

By  •  Debian

You can easily create a base Debian system using debootstrap. To have a usable chroot environment, you’ll also need to mount both the dev and proc filesystems. Follow these steps for more details.

  1. Create a directory that you want to use for the base system (chroot-debian in this case).

    mkdir chroot-debian
  2. Create a base system using debootstrap

    sudo debootstrap sid chroot-debian http://mirror.pacific.net.au/debian/

    You can change sid to stable to use the stable distribution, and to use Debian mirror closer to your physical location for faster download speed.

  3. Mount proc and dev filesystem

    sudo mount -o bind /dev chroot-debian/dev
    sudo mount -o bind /proc chroot-debian/proc
  4. Start chrooting

    sudo chroot chroot-debian /bin/bash
  5. Once done, exit the session and don’t forget to unmount the dev and proc filesystem

    sudo umount chroot-debian/dev chroot-debian/proc

How to disable password authentication in SSH

SSH is by default configured to allow password login. You can disable password authentication if you’re in favour of public key authentication by following these steps;

  1. Set PasswordAuthentication to no in /etc/ssh/sshd_config

    PasswordAuthentication no
  2. Reload or restart SSH

How to convert PuTTY’s .ppk to SSH key

By  •  PuTTY

You won’t be able to directly use your PuTTY‘s key in Linux‘s OpenSSH because the keys are of different format. You’ll need to first convert PuTTY‘s key to OpenSSH‘s key format by following these steps;

  1. Download PuTTY Key Generator (puttygen.exe) from the following URL

    https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
  2. Launch the program and click on the Load button and select your PuTTY‘s key file, which normally ends with .ppk extension.

  3. Enter the key’s passphrase if prompted.
  4. Details of the imported key will be displayed.
  5. Go to Conversions → Export OpenSSH key from the menu.
  6. Save your converted key to a new file and location.

How to use download accelerator for Linux from the command line

By  •  Linux

From the man page, axel is a program that downloads a file from a FTP or HTTP server through multiple connection, each connection downloads its own part of the file.

Unlike most other programs, Axel downloads all the data directly to the destination file, using one single thread. It just saves some time at the end because the program doesn’t have to concatenate all the downloaded parts.

The following is an example of using axel to download a Linux kernel;

$ axel http://www.kernel.org/pub/linux/kernel/v2.2/linux-2.2.26.tar.bz2
Initializing download: http://www.kernel.org/pub/linux/kernel/v2.2/linux-2.2.26.tar.bz2
File size: 15754692 bytes
Opening output file linux-2.2.26.tar.bz2
State file found: 140628 bytes downloaded, 15614064 to go.
Starting download

[  1%] [0            1           2            3           ] [  17.3KB/s] [14:38]

It accept the following options;

--max-speed=x           -s x    Specify maximum speed (bytes per second)
--num-connections=x     -n x    Specify maximum number of connections
--output=f              -o f    Specify local output file
--search[=x]            -S [x]  Search for mirrors and download from x servers
--no-proxy              -N      Just don't use any proxy server
--quiet                 -q      Leave stdout alone
--verbose               -v      More status information
--alternate             -a      Alternate progress indicator

How to auto-complete CSS syntax in Vim

By  •  Vim

Being the language used in website designs, CSS is one of the language supported by Vim’s auto-complete feature.

To start using the feature, enter the following while in Vim’s command mode.

:set omnifunc=csscomplete#CompleteCSS

That will enable CSS auto-completion in Vim. To use it, press Ctrl + x followed by Ctrl + o while partially typing CSS codes.

The following is a sample screenshot.

You can use the arrow key to navigate through the list to choose your desired auto-complete suggestion.

How to remove edit link in Display Wiki Page plugin

By  •  DokuWiki

Display Wiki Page is a DokuWiki plugin that enables embedding of a wiki page in anywhere of your site from the template. The following is an example as used in the sidebar of this site to display the category page.

If you noticed, there’s and Edit link at the end of the page. While this is convenient, you might not want that to appear for some reason.

To remove it, go to you DokuWiki’s installation directory, and edit this file.

plugins/displaywikipage/code.php

In there, comment out the following line.

if ($perm >= AUTH_EDIT)
{
  // create and add the 'edit' button
  $result .='<div class="secedit2"><a href="' . DOKU_BASE . 'doku.php?id=' . $wikipagename . '&amp;do=edit'
  . '">' . $lang['btn_secedit'] . '</a></div>';
}

After saving the file, the Edit link should no longer appear at the bottom of the page.

How to maximize browser window using Javascript

The key to maximizing the browser window in Javascript is the window.resizeTo() function, which would resize the window to any specified size. The function somehow needs to get the screen’s width and height to be supplied as parameter, and the window itself need to be moved to the top left corner of the screen using the window.moveTo() function so that it will be displayed in full.

The following example will maximize the browser window as the page loads:

<html>
<head>
	<script language="JavaScript">
		window.moveTo(0, 0);
		window.resizeTo(screen.width, screen.height)
	</script>
</head>
</html>

The browser window will maximize if a user click on the URL as in the following example:

<html>
<head>
	<script language="JavaScript">
		function maximizeme(){
			window.moveTo(0, 0);
			window.resizeTo(screen.width, screen.height)
		}
	</script>
</head>
<body>
	<a href="javascript:onclick=maximizeme()">Maximize</a>
</body>
</html>

The function seem to longer be supported by modern browsers

How to shutdown Windows machine remotely using Linux

By  •  Linux

The easiest way to shutdown a Windows machine from Linux is by using Samba’s net command. The following command will send an RPC call to the Windows machine, telling it to shutdown;

$ net rpc SHUTDOWN -C "Comment here" -f -I xxx.xxx.xxx.xxx -U username%password

If successful, we’ll be presented with the following mesage;

Shutdown of remote machine succeeded

Change “Comment here” with whatever shutdown comment that you would like for the shutdown, and replace xxx.xxx.xxx.xxx with the IP address of the Windows machine that we are to shutdown. A valid username and password also need to be supplied as a parameter to the the -U switch.

For this command to be successful, the user we use must have shutdown privilege on the windows machine. The Windows machine also need to have RPC enabled, and no firewall is blocking port 135 as the port used by RPC. The net command itself however is only available if Samba is installed.

Top