3 May 2016

Finnish Sima

Recipe:

4 litres of drinking water

340 grams white sugar

340 grams brown sugar

4 small lemons

0.5 dl molasses or 0.5 dl honey

5 cloves (optional)

1⁄4 teaspoon yeast

Directions

Warning: Steer clear of glass bottles, as they can explode under pressure.

Wash the lemons, peel thinly, and remove the pith.

Slice the lemons thinly and place them with the peel.

Bring half the water to the boil and add the lemons, peel, cloves, honey or molasses and sugar. I actually boil the peel with the water, but it’s not so important.

Stir until the sugar dissolves, and leave to stand covered for about half an hour to an hour.

Add the rest of the water cold. When the liquid temperature matches the yeast activation temperature, add it.

Cover with a dry cloth and keep at room temperature for about 48 hours, or at 24 hours in a warmer, dry place.

Put several raisins into clean bottles, then strain the liquid into them.

Loosely cork the bottles and store them somewhere dark at room temperature.

The mead is ready when the raisins rise to the surface, but if you want a more alcoholic mead, you should perhaps keep an airlock on one bottle to monitor the fermentation. When it slows, you can tighten the bottle lids and store in the fridge.

Fermentation airlock

14 April 2016

How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

Well this has been tested on Ubuntu 14.04 LTS, but it could work on your linux distro too.

Anyway, here is a quick tutorial for using Apache’s virtual hosts to organise sites to be developed locally.

Note: If you are working with a framework like CodeIgniter and need to modify URLs, you’ll need to activate mod_rewrite. See https://www.digitalocean.com/community/tutorials/how-to-set-up-mod_rewrite for more details. tldr;

sudo a2enmod rewrite

Create the folder. I’m using example.dev as the test site. Note: I’ve used .dev because I have a plugin that forces the browser to request sites that support https to change the url from, for example http://example.com to https://example.com This will then take you to the online web page instead of the local one.

sudo mkdir -p /var/www/example.dev/public_html

Allow current user privileges to that folder

sudo chown -R $USER:$USER /var/www/example.dev/public_html

Create a test page

nano /var/www/example.dev/public_html/index.html

and add for example,

<html>
  <head>
    <title>This is example.dev</title>
  </head>
  <body>
    <h1>Success! We are running example.dev on virtual hosts!</h1>
  </body>
</html>

Make a copy of your default virtual host file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.dev.conf

Edit the copy you just created

sudo nano /etc/apache2/sites-available/example.dev.conf

Change the following lines to point to example.dev

<VirtualHost *:80>
    ServerAdmin admin@example.dev
    ServerName example.dev
    ServerAlias www.example.dev
    DocumentRoot /var/www/example.dev/public_html
</VirtualHost>

Enable the virtual host file with the a2ensite tool

sudo a2ensite example.dev.conf

Restart apache

sudo service apache2 restart

Edit your local hosts file

sudo nano /etc/hosts

Add the line

127.0.0.1 example.dev

Test it. Open a browser and type

http://example.dev

Remember, this will now send you your local site example.dev instead of the actual example.dev online (if such a site exists).

You can delete or comment those local host entries after you’ve finished developing your site.

Update

I recently discovered ubuntu disables the functionality of the .htaccess file by default. If you intend to use it during local development, you will need to add this to your example.dev.conf file.

<Directory /var/www/example.dev/public_html >
    # AllowOverride All allows using .htaccess
    AllowOverride All
</Directory>

so the /etc/apache2/sites-available/example.dev.conf will look like this

<VirtualHost *:80>
    ServerName example.dev
    ServerAlias www.example.dev
    ServerAdmin admin@example.dev
    DocumentRoot /var/www/example.dev/public_html

    <Directory /var/www/example.dev/public_html >
        # AllowOverride All allows using .htaccess
        AllowOverride All
    </Directory>
</VirtualHost>

Update 2

If you want to process url routes make further changes

<Directory /var/www/example.dev/public_html >
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all      
</Directory>

12 April 2016

Give your home web server a domain name on the web

If you want to host your own web server on the WWW from home, this tutorial will give you a static domain name if you have a dynamic ip address. I assume you have a device to act as a web server, like the RaspberryPi, and know how to forward ports.

Step one, sign up for a ydns account from https://ydns.io/. Google your ip address and input it in the static ip address field (don’t worry about the field being static for now).

Next install ddclient

sudo apt-get install ddclient

Ignore the setup screen for now, we’ll change that later.

Now sign up for an account at https://www.dnsomatic.com/. Select ydns from the list of providers when prompted.

With your account information, edit

sudo nano /etc/ddclient.conf

Have it look like

protocol=dyndns2
use=web, web=myip.dnsomatic.com
ssl=yes
server=updates.dnsomatic.com
login=your_dnsomatic_username_here
password='your_dnsomatic_password_here'
your_ydns_domain_name_here

This file should already be root only access so no need to chmod it to 600. Test everything went ok by running

sudo ddclient

and you should see your ip address output in the console.

Double check by checking the service page at dnsomatic (hit refresh page). Your current ip will now appear in the Status column and History file. Also check My Hosts in ydns, but if it fails only in ydns, it’s likely a configuration issue you made between dnsomatic and ydns.

ddclient will incremently contact dnsomatic if your ip address changes. dnsomatic will contact ydns if this happens too. This is how the static ip address entry in ydns becomes a more dynamic one.

One more note, if you want to change the default time the ddclient deamon activates to check your ip address (default is 300 seconds), the setting is in

sudo nano /etc/default/ddclient

I set mine to 600 (once every ten minutes).

11 April 2016

Getting my wifi working on a new bare bones Debian install

Here’s a quick way to get connected to your wireless network. Note, your router will have to have dhcp enabled. This won’t work for other networks — you’ll need a network manager for that.

Login as su and edit

nano /etc/network/interfaces

At the end of the file, add this

auto wlan0
iface wlan0 inet dhcp
        wpa-ssid the_ssid_name_of_your_network
        wpa-psk your_network_password

As this file now contains your network password, make sure only root can access it.

chmod 600 /etc/network/interfaces

Reboot for changes to take effect.

10 April 2016

Display in-page PHP error reporting

In-browser/in-page errors are by default turned off in php runing on apache. Obviously, you’ll only want to do this during the development phase and not when you go to production.

Here’s how to turn on PHP’s in-page error reporting on Ubuntu when developing locally.

Method 1

Open

sudo nano /etc/php5/apache2/php.ini

Locate

display_errors = Off

Replace the parameter ‘Off’ with ‘On’.

display_errors = On

Restart Apache

sudo /etc/init.d/apache2 restart

Method 2

Create a .htaccess file in your app’s root directory.

Add these three lines

php_value error_reporting -1 
php_value display_errors stdout 
php_flag display_startup_errors on

31 March 2016

Minecraft server on a eeePC

Intro

This tutorial is for getting a minecraft server running on Linux.

I originally made this for the Raspberry Pi, but since my model was the earlier Model-B with only 265MB ram, it wasn’t enough to run the server. Here, I have modified the tutorial for the net install (minimal) version of Debian Linux. The only thing I added during the install process was ssh. When prompted, don’t bother installing things like a web server etc… You don’t actually need ssh, but I find it convinient for my pruposes.

I hear minecraft servers require a good ammount of memory to run (even if the server is just for you and a few friends). It doesn’t require much processing power though. Like I mentioned earlier, I got this up and running on a moderatly overclicked raspberry pi with 256mb of memory, but it would fail after a few moments with just one user. My current succsessful setup is on an old eeePC 701 with 2GB ram. This tutorial expects you have Debian Linux installed, but most other linux systems would probably be fine too.

Another important thing to note is bandwidth allowance. Checkout this page to estimate how many users you can host: http://canihostaminecraftserver.com/

Setup

Log in as root (su). Get Oricle’s JDK —see http://www.webupd8.org/2014/03/how-to-install-oracle-java-8-in-debian.html for more info.

Follow the intructions there. While you are logged in as root, grab git too.

apt-get install git-core 

Next, sign out of root and with your regular user account, create a folder for your minecraft server and cd into it

mkdir minecraft
cd minecraft

Next you’ll need Spigot. Simply put, Spigot is the most widely-used modded Minecraft server software in the world. [Link].

Spigot uses a program called BuildTools to get and build the latest version of the server from GitHub (this is why we downloaded git earlier).

So to get BuildTools

wget https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar

BuildTools.jar shound now be in ~/minecraft

Next run BuildTools to build your minecraft server (this may take some time).

java -jar BuildTools.jar

Launch the server.

Depending on how much memory your server has, you’ll need to change the Xms and Xmx memory allocation. Xms is the memory allocated to starting up Java, and Xmx is the memory allocated once something is running on it (I think).

java -Xms1024M -Xmx1024M -jar /home/$USER/minecraft/spigot.jar nogui

Note: These values are system specific. Change them to meet the requirements of your system. The minecraft server is now running.

Plugins

Note: Before installing any plugins, make sure you’ve run the server succssfully once. This will create a plugins folder for you to install your server plugins.

To keep the server running smoothly, install this plugin

cd ~/minecraft/plugins
wget http://ci.shadowvolt.com/job/NoSpawnChunks/lastSuccessfulBuild/artifact/target/NoSpawnChunks.jar

Post install

Before you actually play on the server, you obviously have to open a port on your router — the default port is 25565 (allow both TCP and UDP).

Admin commands

Use these commands “as is” in the Linux command line or prefix with / if you are an admin in the game.

op yourself with the command

op [your minecraft username]

To stop, type either into the command line or in the game if you are op

stop or /stop

More commands can be found here

Configuration

Open the config file in ~/minecraft

nano server.properties

Some settings you may want to change

server-name=A Debian Bukkit Server
max-players=4
motd=A Minecraft Server

27 March 2016

Circular buttons

Now and again you have to make a round (circular) button. This is how I did it.

https://jsfiddle.net/n2fole00/L2m1us5t/

html

<button type="button" class="btn-round btn-lg">
    <span>29</span>
</button>  

css

.btn-round {
    color: white;
    font-weight:bold;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: red;
    border: none; 
    outline: none; /* remove focus after click event */
}

.btn-round.btn-lg {
    font-size: 24px;
    width: 48px;
    height: 48px;
}

.btn-round.btn-sm {
    font-size: 17px;
    width: 34px;
    height: 34px;
}

.btn-round.btn-xs {
    font-size: 12px;
    width: 24px;
    height: 24px;
}

26 March 2016

Detecting different mouse button clicks

The following example demonstrates capturing left, middle, and right mouse clicks with jQuery –along with changing element text, and toggling viability. It was made for my daughter who is into magic, and scored me some dad points.

JSFiddle: https://jsfiddle.net/n2fole00/t3aL5zmq/

<head><script src="https://code.jquery.com/jquery-2.2.0.min.js"></script></head>

<div style="margin-left:auto;margin-right:auto;text-align:center">
    <br><br>
    <h2>Are you a magician?<br>Can you make the cat appear and disappear?</h2>
    <br>
    <button type="button" style="font-size:x-large">Show me cat!</button>
    <br>
    <img src="insert_cat_pic_here">
</div>

<script>

$( "img" ).toggle(); // hide on img on init

// disable right click context menu
$('*').contextmenu( function() {
    return false;
});

$('button').mousedown(function(event) {
    switch (event.which) {
        case 1:
            break;
        case 2:
            break;
        case 3:
            // show cat
            $( "img" ).toggle();
            // change text of button
            if ($(this).text() == "Show me cat!") 
            { 
                $(this).text("Make cat disappear!"); 
            } 
            else 
            { 
                $(this).text("Show me cat!"); 
            }; 
            break;
        default:
            alert('You have a strange Mouse!');
    }
});

</script>

23 March 2016

Detecting change in state of a group of checkbox elements

Here’s how you can detect the original state of some checkboxes (or radio buttons). So to be clear, it will report if the state has changed and if the state has reverted back to its original state combination. It can be modified for all kinds of input elements and is handy, for example, when you want to offer a user a save option when a change is made to their original configuration.

Fiddle: https://jsfiddle.net/n2fole00/z40bm13g/

<head><script src="https://code.jquery.com/jquery-2.2.0.min.js"></script></head>

<input type="checkbox" name="id_1" id="id_1" value="id_1" checked="checked" />One
<input type="checkbox" name="id_2" id="id_2" value="id_2" />Two
<input type="checkbox" name="id_3" id="id_3" value="id_3" checked="checked" />Three

<br>Same state?: <span id="show">true</span>

<script>

// initial state object 
var initial = $(':checkbox').map(function(){ 
    return this.checked 
});

// detect clicks to checkboxs, radiogroups...
$( ':checkbox' ).click(function() {
    // assign user input to a comparing object 
    var change = $(':checkbox').map(function(){ 
        return this.checked 
    });
    // compare the Objects and output the result
    $('#show').text( 
        JSON.stringify(initial) === JSON.stringify(change)
    );
});

</script>

20 March 2016

Making Water-Soluble Calcium

Certain plant fertilizers are difficult to come by where I live, so I tried making water-soluble (and plant available) calcium following this guide — Natural Farming: Water-Soluble Calcium.

I think it turned out pretty good. Things to note;

  • I used white vinegar which was 10% acetic acid.
  • I added twice the volume of vinegar to crushed egg shells.
  • I agitated the solution daily for the first week.
  • I kept the paper towel on the glass the whole time.
  • I kept it going until all the vinegar had evaporated. This took about 3-4 weeks.

Water soluble calcium finished product.

The original guide I followed seems to collect liquid, where I collected crystals that form around the edges of the glass as the vinegar evaporated.

The result is Calcium acetate (I think).

I’ll dissolve about 1ml of the crystals to 1 liter of water, and apply as a foliar spray to my chilli plants and see if it helps with the fruit setting problems I’ve been having.

This has turned out to be a fun little science experiment.