22 December 2016

Creating backups of database rows

I came across a situation where I needed to make a backup of every row either newley insterted, or updated in my database. I didn’t want to share the latest backed up data on the same table, but then needed a way to reference the pk id of the original row when the data from that row was created for the first time.

MySQL has a handy function called LAST_INSERT_ID() which get’s the last inserted row id just executed. CodeIgniter also has a very easy way to get this value $this->db->insert_id();, which can be assigned to a variable and used with an insert statement, to create a reference to the backup of the new row in the backup table. You'll probably also want to do this under a table lock to prevent concurrent operations.

I don’t know whether this is the best way to do backups. This is just something I came up with. I should probably lookup how others do it at some point :P

15 December 2016

My essential web development tools, processes, libraries

This post will be continuously updated/revised.

Visualisation

Charts and graphs: https://gionkunz.github.io/chartist-js/

Charts and graphs: http://www.chartjs.org/

Sortable tables: http://tablesorter.com/docs/

Vertical slides: http://alvarotrigo.com/pagePiling/#page1

Front-end customisation

tablecloth.js is a jQuery plugin that helps you easily style HTML tables along with some simple customizations.

List.js adds search, sort, filters and flexibility to plain HTML lists, tables, or anything.

Select 2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

scrollMonitor allows you to receive events when elements enter or exit a viewport.

ScrollReveal - Easy scroll animations for web and mobile browsers.

Parsley is JavaScript form validation library, based on jQuery.

Dev tools

Emmet Re:View - A browser extension for displaying responsive web-pages in a side-by-side views to quickly test how it looks at different resolutions and devices.

MailTrap - Safe email testing for dev teams.

References

Learn Layout teaches the CSS fundamentals that are used in any website’s layout.

Language libraries

The Voca library offers helpful functions to make string manipulations comfortable

Front-end libraries

W3.CSS is a modern CSS framework with built-in responsiveness. It's based on Google's material design, and is extremely light and easy to work with.

Resolving issues using Google's smtp email with Codeigniter

So 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 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 ;)

9 November 2016

Responsive font sizes

When designing for mobile, a lot of things have to move and scale. One of those things are fonts and their size must be adjusted to look good for various screen sizes. One way to do this is with a base measurement in % and the em measurement which is relative to the base measurement.

Let’s see some code…

body {
    font-size: 100%; /* This is the base value */
}

.font-regular {
    font-size: 1em;
}

.font-large {
    font-size: 1.5em;
}
.font-extra-large {
    font-size: 2em; 
}

Now when the base size changes all the font sizes are updated accordingly. You can also use this base for things like margins etc…

Responsive horizontal menu

Here is how I do a simple responsive horizontal menu where the elements are equally spaced.

CSS for four items…

.menu-item {
    width: 24%;
    margin: 0 0.5%;
    float left;
}

Adjust the percentage as required.

6 November 2016

Awesome WordPress plugins

Here is a list of my favourite WordPress plugins.

JavaScript AutoLoader

http://petersplugins.com/free-wordpress-plugins/javascript-autoloader

This Plugin allows you to load additional JavaScript files without the need to change files in the Theme directory. To load additional JavaScript files just put them into a directory named jsautoload.

Clicking the JavaScript AutoLoader question mark icon on the Plugin page will show you the following…

Possible paths to store your JavaScript files

Child Theme Directory

Current Path: /var/www/example.dev/public_html/wp/wp-content/themes/eaterstop-pro-child/jsautoload

Theme Directory

Current Path: /var/www/example.dev/public_html/wp/wp-content/themes/eaterstop-pro/jsautoload

General Directory

Current Path: /var/www/example.dev/public_html/wp/wp-content/jsautoload

To make sure your JS code runs after everything has loaded, run it in the following function

window.onload = function() { 
    // your code here
}

BackUpWordPress

By: http://hmn.md

BackUpWordPress is one of several free solutions available to wordpress owners. It is my preferred one because it has an uncomplicated user interface, and gives you the option to either schedule back-ups of just the database, or everything.

Easy WP SMTP

By: https://wp-ecommerce.net

Easy WP SMTP simply allows you to send email via SMTP from your WordPress Blog. Why would you want to do this? I recently had a client’s hosting provider move to a cloud based platform and remove support for php’s mail (sendmail) function. The plugin allows wordpress to use any smtp mail account (including your hosts email service) to send mail. It also apparently helps keep mail sent from wordpress out of people’s spam folders.

5 September 2016

Step-through Debugging with xdebug for php

Here is how to set up step-through debugging for php on various editors that support it. The install was on Ubnuntu 14.04.

Install by running

sudo apt-get install php5-xdebug

Next, open /etc/php5/apache2/php.ini and add the following (check the specific xdebug folder name)…

This part was giving me a message that "Module 'xdebug' already loaded". Not including the following line seems to have dismissed that message.

zend_extension="/usr/lib/php5/20121212/xdebug.so"

In the same file, find the commented line

; report_zend_debug = 0 

and uncomment it. This line apparently activates the debugging of data, but only with an installed debugger like xdebug.

Finally in php.ini, add the following settings.
Note 1: with these settings, the debugger will connect to your editor for every script it executes.
Note 2: xdebug.remote_connect_back=1 is not safe for production servers according to https://atom.io/packages/php-debug

xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true

Save up and restart apache for changes to take effect.

sudo service apache2 restart

I had this working in both Atom and Visual Studio Code editors by installing the extension php-debug.

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.

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.