GIT Notes: Recording Changes

GIT Succinctly – free eBook from Synfusion Chapter 3 Recording Changes A ‘snapshot’ is a complete record of state of files, not of differences between other states. ‘staging’ allows you choose what changes go into the commit. To stage files, $ git add (can multiple files be listed here?) or to stage all, $ git…Read More

GIT Notes: Overview & Configuration

GIT Succinctly – free eBook from Synfusion Chapter 1 Overview working directory staging commited history development branch Chapter 2 Configuration Configuration file in home directory, $ cat ~/.gitconfig To git init a directory, $ git init &ltpath-to-directory&gt Omit path to git init current directory. Includes a directory ‘.git’. ‘clone’ downloads a complete copy of repo….Read More

Hardening SSH

SSH created key-pair More information on this topic at securing-your-server. On your local machine, create a 4096-bit RSA key-pair, $ ssh-keygen -b 4096 If you get a message to say that this already exists or to over write a file, then do not proceed, unless you want to create a new key-pair. If one exists,…Read More

Raspberry Pi 3 Express Application (part 8)

Check Node and npm are installed, $ node –version v7.4.0 $ npm –version 4.0.5 Install Express generator globally, $ npm install express-generator -g Check it, $ express –version 4.14.0 Create a new directory inside /opt/nodeserver $ mkdir tempGraph This will create several folders as well as the package.json file with all dependencies. Next install these…Read More

Raspberry Pi 3 DS18B20 Temperature Sensor (part 6)

Open /boot/config.txt $ sudo nano /boot/config.txt and add dtoverlay=w1-gpio to the end of the file. Reboot the system, $ sudo reboot Then run, $ sudo modprobe w1-gpio $ sudo modprobe w1-therm The change directory /sys/bus/w1/devices/ and list its contents, Change directory into 28-000006c87ee2 and then ‘cat w1_slave’. The ‘t=16125’ this a temperature reading of 16.125…Read More

Raspberry Pi 3 Node Server & systemd (part 5)

Run a simple Node server. Create the file and path, /opt/nodeserver/server.js const http = require(‘http’); const hostname = ‘0.0.0.0’; // listen on all ports const port = 8080; http.createServer((req, res) => { res.writeHead(200, { ‘Content-Type’: ‘text/plain’ }); res.end(‘Hello people, I am a server \n’ + new Date().toISOString()); }).listen(port, hostname, () => { console.log(‘Server running at…Read More

Raspberry Pi 3 Static IP Address & No-ip setup (part 3)

To set up a static IP address on the Pi 3 which will remain constant inside you LAN open /etc/dhcpcd.conf $ sudo nano dhcpcd.conf Add to the bottom of this file, interface eth0 static ip_address=192.168.1.30 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 interface wlan0 static ip_address=192.168.1.30 static routers=192.168.1.1 static domain_name_servers=192.168.1.1 Here 192.1.68.1.30 is the static ip address I…Read More

Setting up gh-pages

Login to github.com and create a new reporitory. Copy the link for this repository. It will look like this, https://github.com/<user-name>/<repo-name>.git On your local machine create a new directory, $ mkdir testGHpages cd into it $ cd testGHpages git init this directory $ git init Add a simple index.html file to this directory. <!doctype html> <html…Read More

D3.js Basic json Graph

Basic example of graphing using D3.js version 3 Useful links used for this post: http://alignedleft.com/tutorials/d3/axes https://square.github.io/intro-to-d3/ <!DOCTYPE html> <html lang=’en’> <head> <meta charset=’utf-8′> <script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js” type=”text/javascript”></script> <script type=”text/javascript” src=”https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.min.js”></script> <script src=”https://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.12/crossfilter.min.js” type=”text/javascript”></script> <script src=”http://cdnjs.cloudflare.com/ajax/libs/dc/1.7.5/dc.min.js” type=”text/javascript”></script> <script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js” type=”text/javascript”></script> <link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css”> <link rel=”stylesheet” href=”css/tempGraph.css”> <link href=”http://cdnjs.cloudflare.com/ajax/libs/dc/1.7.5/dc.min.css” rel=”stylesheet” type=”text/css”> <script src=”https://d3js.org/d3-array.v1.min.js”></script> <script src=”https://d3js.org/d3-collection.v1.min.js”></script> <script src=”https://d3js.org/d3-color.v1.min.js”></script> <script…Read More

Django: Multiple Pagination in a single Template

Assuming you would like to display two models in the same template each with their own pagination, here’s how to do it. views.py def myview(): Model_one = Model.objects.all() paginator = Paginator(Model_one, 6) page = request.GET.get(‘page1’) try: Model_one = paginator.page(page) except PageNotAnInteger: Model_one = paginator.page(1) except EmptyPage: Model_one = paginator.page(paginator.num_pages) Model_two = Model_other.objects.all() paginator = Paginator(Model_two,…Read More

Django-allauth Installation

There is a useful django-allauth video tutorial at Create third party Facebook login in Django. The document below simply follows that but only adds facebook social authentication. Documentation can be found at django-alluth documentation. django-allauth can also be installed by cloning from https://github.com/pennersr/django-allauth I am running Django 1.9.5 and will install django-allauth 0.25.2 Setup a…Read More

Part 7: Django Login, Logout & Registration

Login form: Adapted from the login tutorial at techand startup. Create a new app called ‘accounts’ $ python manage.py startapp accounts Add ‘accounts’ to settings.py INSTALLED_APPS = [ ‘accounts’, ‘django.contrib.admin’, ‘django.contrib.auth’, …………. Go to crudProject/views.py and add to the top of the file, from django.shortcuts import render_to_response Below that add, def loggedin(request): return render_to_response(‘registration/loggedin.html’) If you…Read More

Part 6: Django CRUD, Update

Continued from Part 5: Django CRUD, Delete Full code on https://github.com/shanegibney/djangoCRUD We may wish to update the model ‘Members’. Let us start by adding an edit icon to the table in ‘index.html’. <td><a href=”{% url ‘edit_new’ item.id %}”><span class=”glyphicon glyphicon-pencil”></span></a></td> If you are not using Bootstrap replace the span tags with ‘edit’. <td><a href=”{% url ‘edit_new’…Read More

Part 3: Django CRUD, Display Models

Continued from Part 2: Setting up Django, URL’s & Views Full code on https://github.com/shanegibney/djangoCRUD Add to the crudapp/models.py file from django.db import models In the same file create a model called ‘Members’ with columns for ‘first_name’, ‘last_name’ and ‘description’. This is equivalent to a table called ‘Members’ with fields for ‘first_name’, ‘last_name’ and ‘description’. class Members(models.Model): first_name =…Read More

Python Dictionary into HTML Template

The following Python code will find instances of {body} in a file template.html and replace it with a string. Then a new file index.html is created with this change. generate.py with open(‘template.html’,’r’) as template_file: template = template_file.read() tokens = {‘title’: ‘My Title in a Dictionary’, ‘header’:’Stuff for heading’, ‘body’: ‘The body stuff’, ‘footer’: ‘This is…Read More

Simple Python into HTML

The following Python code will find instances of {body} in a file template.html and replace it with a string. Then a new file index.html is created with this change. generate.py with open(‘template.html’,’r’) as template_file: template = template_file.read() content = template tokens = {‘body’: ‘Body stuff can go here’} replaced = ‘Body stuff can go here.’…Read More