
Migrations, tests and runserver in Django reusable apps
How do you create migration files, run unit tests and preview your Django app in the browser when developing a reusable app that is not nested inside a Django project?

Validate that only one of many parameters was provided in Python
Sometimes, a function or class constructor can take many possible parameters, but only one parameter can have a value
at any one time, excluding all others. One way to validate this is included in the Python standard library. Copying
from the uuid.py
module:
class UUID:
def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
int=None, version=None,
*, is_safe=SafeUUID.unknown):
if [hex, bytes, bytes_le, fields, int].count(None) != 4:
raise TypeError('one of the hex, bytes, bytes_le, fields, '
'or int arguments must be given')
The idea here is that since all five mutually exclusive parameters hex
, bytes
, bytes_le
, fields
and int
have a default value of None
, when one of them is specified during instatiation, there will then be four
parameters left with value None
.
Image credit: Wicklow Mountains, by Marcus Tan. In the Public Domain. Source.

Apache host configuration for a Django website
This is the Apache virtual host configuration for an older project that I don't use any more.

Mount an NTFS disk in Ubuntu
On a system that dual boots Windows and Ubuntu, I use this line in /etc/fstab
to have the NTFS Windows disk mounted
permanently in Ubuntu:
/dev/disk/by-uuid/1EBB57A121AFC448 /mnt/1TB auto nosuid,nodev,nofail,x-gvfs-show,uid=marios,gid=marios,permissions,dmask=022,fmask=133 0 0
Here's a list of options used in that line:
nosuid
: this is a security enhancement, preventing execution of files under the files' owner's permissios, from users other than the ownernodev
: this prevents the mounted filesystem from containing device filesnofail
: prevents error reports when the device is missing, but can mask failuresx-gvfs-show
: makes the device visible in the user interface, in the file exploreruid=marios
andgid=marios
: assign user and group ownership of new files to a specific userdmask=022
andfmask=133
: default permissions for newly created files and directories
Image credit: Library At Trinity College. In the Public Domain. Source.

My .vimrc
This is my pretty basic ~/.virmc
. Lines starting with a double quotation mark are comments:
" Make text pop out on dark backgrounds:
set bg=dark
" Always display line numbers:
set number
" TAB width is 4:
set tabstop=4
" ...and so is an INDENT:
set shiftwidth=4
" Make TAB insert an INDENT at the beginning of a line:
set smarttab
" TAB is 4 SPACES instead of one \t:
set expandtab
set modeline
Image credit: Wild Grazing - Sheep grazing on the southwest coast of Ireland. In the Public Domain. Source.

A small web application with Angular5 and Django
Django works well as the back-end of an application that uses Angular5 in the front-end. In my attempt to learn
Angular5 well enough to build a small proof-of-concept application, I couldn't find a simple working example of a
combination of the two frameworks, so I created one. I called this the Pizza Maker. It's available on GitHub, and
its documentation is in the README
.
If you have any feedback for this, please open an issue on GitHub.
Bootstrap
Dashboard Templates
This is a list of free (an in beer) Dashboard or Admin templates build on Bootstrap4. Some are released under well-known open source licenses (mostly MIT), and some have other restrictions, however all are gratis. These links tend to break over time, but often there are mirrors of the themes elsewhere, at least for the open source ones.
Angular
Getting Started with Typescript
A series of videos from codingforentrepreneurs.com on getting started with TypeScript.
- Welcome
- Install Node.js
- Configure TypeScript
- Classes - Part 1
- Classes - Part 2
- Getting Started with Typescript - Declaring Variables - let vs var
- Getting Started with Typescript - Run & Compile with Webpack
- Getting Started with Typescript - TypeScript - Classes - Part 3
- PackageJSON - npm init
- jQuery, Typings, & npm
- Thank you
Try Angular 4
A good series of videos from codingforentrepreneurs.com guiding through the creation of a complete application in Angular 4:
- Welcome (2:40)
- Getting Started (5:53)
- App Module & Component (8:13)
- Ng Generate New Component (5:46)
- Selectors & Components (2:08)
- ngFor and ngIf (7:57)
- Mapping Urls with RouterModule (9:17)
- Dynamic Routing of Components (7:38)
- Safely Embed a Video (8:38)
- Pipes & Custom Pipes (9:11)
- Rapid Bootstrap 3 Overview (15:14)
- Bootstrap for Angular // ngx bootstrap (11:39)
- ngx bootstrap carousel (11:56)
- Angular Click Events (14:17)
- Http Requests (17:02)
- Http & Featured (6:22)
- Two Way Data Binding (4:22)
- ngForm Basics (7:55)
- Search Detail (12:09)
- Passing Data to Components (12:08)
- Video Service (16:47)
- Search Video List (8:01)
- Video Item Model (7:19)
- Router Link & Improved Navigation (4:16)
- Improve Styling (11:06)
- ngClass (6:49)
- ngBuild and Deploy to Heroku (22:16)
- Thank You and Next Steps (1:43)
These instructions should get this up and running on Ubuntu:
git clone https://github.com/codingforentrepreneurs/Try-Angular-v4.git
cd Try-Angular-v4
npm install
ng serve
Et Cetera
Upload file to S3 Bucket with the AWS CLI
The simplest form of using the AWS CLI to upload a file to an S3 bucket is:
aws s3 cp test.txt s3://bucket-name
A neat trick is that you can pipe the output of a shell command to a file on S3, for example:
find . | aws s3 cp - s3://bucket-name/test.txt
IAM
To be able to upload files, you need an IAM role that has at least the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowUploadFileToS3Bucket",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::bucket-name/*"
]
}
]
}
Upload file to S3 Bucket using Boto3
How to upload files to S3 using Boto3, either with the high-level s3 resource or the low-level s3 client.