Simply Ian

The personal blog of Ian Macalinao

Setting Up Virtual Hosts in Apache

| Comments

Today, I wanted to put my downloads on a different domain from my screenshots. Not wanting to manage multiple servers for no reason, I set up virtual hosts, also known as vhosts. Basically, depending on what domain you visit my web server from, you will get a different website. This is actually very simple to set up.

First, navigate to your apache2 directory and go to the sites-available directory within it. On my Debian system, this is at /etc/apache2/sites-available/. In this directory, you’ll see a bunch of files. Each one of these files is a config file that can be enabled or disabled individually; this is called a site.

To set up vhosting, you should first disable the default website. Use the command sudo a2dissite default to do this.

Next, add the rest of your websites. Here is the very simple config file I use:

1
2
3
4
5
6
7
8
9
<VirtualHost *:80>
    ServerName domain.you.want.to.use.com
    DocumentRoot /var/www/sitefiles/
    <Directory /var/www/sitefiles/>
        Options Indexes FollowSymLinks MultiViews
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Save this to a file with the name of the site, no extension. I named my site screenshots for example.

Obviously, replace domain.you.want.to.use.com with the domain you want to use for the website. (For my screenshot website, this is s.giza.us.) The document root is the folder that contains the files at the root of your website. For me that’s /var/www/screenshots.

Lastly, type sudo a2ensite sitename where sitename is whatever you named that file. Then, restart apache with sudo service apache2 restart, and all is well. For any additional domains, create more config files with that information, replacing all of the relevant stuff. Enjoy your awesome new vhosted website!

Including Dependencies in Your Gradle Build Script’s Classpath

| Comments

In a recent project, I wanted to use SnakeYAML in my Gradle build script. This is pretty easy to do; all you have to do is add the following to your script:

1
2
3
4
5
6
7
8
9
10
11
buildscript {
    repositories {
        mavenCentral()
        // ...etc
    }

    dependencies {
        classpath group: 'org.yaml', name: 'snakeyaml', version: '1.5'
        // ..etc
    }
}

This is the same as the repositories {} and dependencies {} sections of the build script. After doing this, feel free to use your libraries anywhere in your build script. Don’t forget to import the classes you use!

Adding a Provided JAR as a Dependency in a Gradle Project

| Comments

Adding a JAR as a dependency is simple in Gradle. In your dependencies {}, add the following line:

1
compile files('file.jar')

Where file.jar is the path to the JAR from the root directory of the repository. For example, if I had Dependency.jar at ./libs/Dependency.jar, I would use compile files('libs/Dependency.jar').

Up - a Useful File Sharing Tool Using SCP

| Comments

I created a tool today called up. Although it’s really simple, it gets the job done and it’s really useful.

Basically, to share a file, you just type up MyFile and it will upload that file to your remote server, returning the URL it is hosted at.

How to Run a Command on Startup on Linux

| Comments

I recently purchased a VPS to run my IRC client in. I wanted to start my IRC client in tmux on startup. The answer is simple: crontabs.

Run the following command on the user you want to run the command on:

1
crontab -e

This will open up the crontab of your current user. A crontab is basically a file stating a bunch of tasks that you want to run on some sort of schedule.

Next, add the following text to the file:

1
@reboot <command>

where <command> is, of course, the command you want to run. For example, on boot, I run a shell script that starts up my tmux stuff, so I have @reboot /usr/ian/tmux_start.sh.

Pretty simple, right? Crontabs have a lot more uses that you can probably find on Google.

Source: man cron and man crontab.

How to Change the Name of the JAR Produced in Gradle

| Comments

I don’t like the traditional JAR name assigned in Gradle. In Bukkit development, you usually make the JAR name the same as the plugin name. Here’s how you set the name of the JAR:

1
jar.baseName = 'JarName'

Where JarName would be the name of the jar generated in build/libs/.

Source: StackOverflow

How to Run a Specific Class Inside of a JAR

| Comments

My friend wanted me to test out his program, but it didn’t have a main class specified in the manifest. Here’s the solution:

1
java  -cp yourjar.jar com.yourpackage.YourClass

This will run the specified class as the main class.

Source: StackOverflow

Using Tmux Remotely Within a Local Tmux Session

| Comments

I often SSH to remote servers, and those servers usually have tmux installed. (tmux is better than Screen in every way) However, conflicts arise when you want to manipulate a remote tmux session within a local one. Ctrl-B refers to the local tmux session, not the remote one, and you have to press Ctrl-B twice to manipulate the remote one. This is pretty annoying. Fortunately, there is a solution to this.

There is one line you need to add to your ~/.tmux.conf (if this file doesn’t exist, create it):

1
bind-key -n C-a send-prefix

This binds the command send-prefix to Ctrl-A. Basically, you are sending a Ctrl-B (assuming you’ve left tmux at its defaults) directly to the server when you press Ctrl-A. This will let you manipulate the remote session with Ctrl-A and still use your local session with Ctrl-B. Pretty nice, eh?

Source: StackOverflow

How to Change the Theme of the XFCE Terminal

| Comments

I use XFCE as my primary desktop environment. It’s a fast, lightweight operating system that when combined with Synapse provides a great, lag-free computing experience.

As a typical developer and Linux user, I use the terminal quite a bit. XFCE’s terminal emulator has a pretty bland default theme. There is an awesome repository called Base16 that provides a wide selection of themes for the terminal.

To install one of these themes, you need to create a directory at ~/.config/Terminal/. Then, run the following command:

1
curl -L https://raw.githubusercontent.com/chriskempson/base16-xfce4-terminal/master/base16-default.dark.terminalrc >> ~/.config/Terminal/terminalrc

Replace the URL with the raw of whatever theme you want to use. Check out the Base16 website to preview all available themes. The changes should take effect next time you run a command; if not, just restart the terminal.

These themes are a huge step up compared to the default. Personally, I use the “Bright” theme. Have fun with a nice looking terminal!

Making Powerline Work With Tmux and ZSH

| Comments

After hearing good things about Powerline for a while, today I finally decided to install Powerline on tmux. However, it didn’t work when I followed the directions. Apparently, this is a common error.

To get it working, I placed the following in my ~/.tmux.conf, in addition to sourceing the powerline.conf:

1
set -g status-right '#(.local/bin/powerline tmux right)'

Basically, tmux does not load the PATH variable in your .zshrc. Therefore, you have to specify the path that powerline is installed at in your ~/.tmux.conf.

If this does not work, you can also try this:

1
tmux set -g status-right '#(/usr/local/share/python/powerline tmux right)'

This uses powerline if you installed it as root.

Source: an issue on the Github Powerline repository