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.

18 March 2016

Customise your Blogger template's CSS

My blog's design is based on Awesome Inc's template (the grey one), which is customised with my own CSS.

To inject your own CSS and customise your blog's design, just navigate to Template; click the Customise button; Click the Advanced link; click the Add CSS link.

Here is my CSS. Note: These CSS styles won't work when viewed on mobile devices, but you can still apply some styles (like text colour and background colour) via the regular advanced editor. Oh, and one more thing...if you don't want example code leaking out of your pre tags you'll have to hard code style="white-space:pre-wrap;" into your tag in the html editor.


body { 
  background-color: #4e89a4; 
}

h1.title, widget.header, .header h1, .Header h1 a,  { 
  color: lightblue; 
}

/* Code area */
pre {
  background: #e6e6e6;
  padding: 15px;
  color: black;
  /* Wrap text inside pre */
  white-space: pre-wrap;       /* CSS 3 */
  white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
  white-space: -pre-wrap;      /* Opera 4-6 */
  white-space: -o-pre-wrap;    /* Opera 7 */
  word-wrap: break-word;       /* Internet Explorer 5.5+ */
}

/* Widget right-side area */
.main-inner .widget { 
  padding-top: 5px;
  border: 0px solid white; 
  box-shadow: none;
  -webkit-box-shadow: none;
  border-bottom: 3px solid lightgrey
}

/* Widget main area */
.date-outer { 
  padding-top: 15px;
  border: 0px solid white; 
  box-shadow: none;
  -webkit-box-shadow: none;
  border-bottom: 3px solid lightgrey
}

/* 
Bottom panel where it has the "Home" link. 
Note, this needs to be an id 
*/
#blog-pager { 
  padding-top: 15px;
  border: 0px solid white; 
  box-shadow: none;
  -webkit-box-shadow: none;
  border-bottom: 3px solid lightgrey
}

.blog-feeds, a.feed-link:link, a.feed-link:visited, a.feed-link:hover, a.feed-link:active { 
  color: white;
}

/* Footer */
.footer-fauxborder-left { 
  border: 0px solid white; 
  box-shadow: none;
  -webkit-box-shadow: none;
  background: lightgrey none repeat scroll 0 0
}

17 March 2016

Preserve paragraph tags in Blogger

This is paragraph Text!

I realised the Blogger editor will strip your paragraph tags if you change between the HTML and Compose editor views. To keep your paragraph tags, stay in the HTML editor and never switch. :)

You might also want to select "Use br tag" in the post's Options menu unless you want extra line breaks appearing where there are new lines.

Issues using Google’s smtp email with Codeigniter

This took me days to figure out, so hence a blog-post.

I’ve been looking for an easy way to test apps that use email locally. Using an online smtp service like gmail is in my opinion, much easier than setting up a local mail server. The natural choice for me was gmail since I have already created some test accounts for development there (It’s best not to mix personal and dev accounts for reasons which will be apparent later on). However, I did run into a couple of issues trying this with CodeIgniter.

Issue 1

With your dev account open, go here https://www.google.com/settings/security/lesssecureapps and turn on access for less secure apps. Thanks to http://www.wpsitecare.com/gmail-smtp-settings/ for that.

Issue 2

After loading CodeIgniter’s email library, the following line is essential to send email

$this->email->set_newline("\r\n"); // in the controller

or add the equivalent to the email config file (see example below)

$config['newline'] = "\r\n"; // essential to use double quotes here!!!

(Update: I’ve found more info on that issue here).

After checking off these two points, you can now proceed to send smtp email locally.

Here is a quick example

In application/config, create a file called email.php (it will be automatically recognised by CodeIgniter). Add the following

<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

// SMTP config
$config['mailtype'] = 'html'; // default is text
$config['protocol'] = 'smtp';
$config['charset'] = 'utf-8';
//$config['newline'] = "\r\n"; // essential to use double quotes here!!!
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['smtp_user'] = 'your_dev_email@gmail.com';
$config['smtp_pass'] = 'Your_Password';

In your controller, add

$this->load->library('email');
$this->email->set_newline("\r\n"); // will fail without this line!!!

$this->email->from('your_dev_email@gmail.com', 'Your_Name');
$this->email->to('another_dev_email@gmail.com');
$this->email->subject('Email Test');
$this->email->message('Test_mail controller.');

if($this->email->send()){
  $data['message'] = "Mail sent...";
}
else {
    $data['message'] = "Sorry Unable to send email...";
}

$this->load->view('your_view', $data);

Then check the output in your_view by echoing the $message variable, and of course check your email 😉

About this blog

Ok, you win google

I decided to move my old blog content to google's blogger.com. Hopefully this will allow me to use Adsense, and also improve my google SEO so people will be able to discover my content more easily. Having a .tk domain made this very difficult as google treats these domains as spammer sites.

So what will I be journalling in this blog? Well, I try to code as much as I can, but I also like to 'make' things. What king of things? Check out the side panel for more info ;)

Update: A friend suggested I list the reasons Google gave. The email I received was in Finnish, so here is a translated version of the specific reasons in English.

  • It is important that the Google ads on sites seem to offer significant value to users. As a publisher, you must provide unique and relevant content that gives users a reason to visit your site.
  • Do not place ads on auto-generated pages or pages with original content is low or where the original content is not at all.
  • Your site should also provide a good user experience through clear navigation and organization. Then users can move easily from page to page and find what they are looking.

What I understood from this...

In the first two points, Google are basically accusing me of ripping-off other content creators. They even mention the method I supposingly use, auto-generated pages as a possible method of doing this. For the record, I have never done this, although I have gone through various free domains in the past years, and content (hosted on the same server) could be cached on those old domains, which I have previously owned.

I have no idea what to say about the third point, but my site used WordPress and all posts were relevantly tagged. The site itself featured the various menus and sidebars to help the user navigate and find content. During my studies, I actually won a client competition for the best WordPress site design, chosen by the client who used the site for their business. So are Google saying WordPress is not a worthy product to feature in its search results?

I'm going to speculate here that the reason my site was rejected here was simply because it had a .tk domain name. I also had problems getting my site to appear at all within search results, usually by copy and pasting either the post's title or a chunk of relevant unique text into the search input. I basically had to put the sentence or title "in quotes" so it retuned only exact matches. Come to your own conclusions -- I already have.