Advertisement

Advertisement

How to Build Python from Source

Installing Python is easy using the pre-built installers and packages from your operating system. However, if you want to build the cutting-edge version directly from GitHub master branch, you will have to build your own version from source. You may also want to do it just to reinforce your understanding of Python.

This guide will walk through the steps needed to build Python 3 from source and then create a virtual environment that you can use for projects.

Using Stripe.js Elements with Angular

This will cover a simple example of how to get a credit card payment source token from Stripe that you can use to associate a Stripe customer with a payment source. This is good for subscription services where you need to store the payment source to later add subscriptions to.

We will look at the process for using Stripe.js Elements to create a credit card form that will obtain the token we need.

How to serve Angular locally over HTTPS

Angular has a convenient launcher to serve your app during development (ng serve). It watches for file changes and automatically reloads saving time. By default it serves over HTTP but to avoid issues with mixing HTTP and HTTPS content, you might want to run the local development server using SSL to serve over HTTPS. This will cover how to use ng serve and npm run start to include SSL certificates to use HTTPS.

AJAX HTTP Requests with Vanilla JavaScript

JavaScript in the browser allows you to make asynchronous HTTP requests using AJAX (asynchronous JavaScript and XML). The benefit of making an AJAX call is that it does not require the page to reload, creating an interface that feels smoother and more responsive.

Some frameworks like jQuery make this even easier, but it is important to understand how to do it without a framework.

Let's look at an example of how to do this.

Angular Create Multiple Environment Files

With Angular 7, when you create an app with the default app generator, it creates two basic environment files: development and production.

When you run ng serve it serves with the development environment settings. To build production you run ng build --prod.

My problem was that I wanted more environments, particularly, a local, development, and production environment. So I wanted to add a new settings file for local work and have ng serve use the local settings.

This will look at how to create additional environment settings files, how to use ng build with your custom environment, and how to use ng serve with the custom environments too.

The serve command first calls build, so we will first look at how to update the build step and then the serve action.

Arduino CLI Tutorial

There is an official Arduino CLI application that allows you to compile and upload sketches from the command-line without IDE.

This guide will walk through the process of installing and configuring the CLI tool as well as compiling and uploading sketches. It will also cover third-party boards and libraries like the ESP8266, Adafruit PyPortal, and Seed Studio boards like Seeeduino Nano.

PyPortal CircuitPy Tutorial (AdaBox 011)

The PyPortal is an awesome little IoT device that is programmable with CircuitPython. It's got wi-fi, a color touch screen, a speaker and speaker connector, microSD card slot, 8MB flash memory, a light sensor, a temperature sensor, a NeoPixel LED, a few JST connectors, and more!

You can buy a PyPortal at https://www.adafruit.com/product/4116. This tutorial covers the PyPortal that came in AdaBox011. I don't believe there are any differences between the AdaBox version and the one you can buy separately from the shop.

In this tutorial we will take a look at the various components and how to use them in CircuitPython with code examples for each. After following the tutorial you should have a solid grasp on the PyPortal.

Since the hardware and software is open source, you can find the sources online:

Ruby ActiveRecord (without Rails) Tutorial

The Ruby ActiveRecord gem provides easy-to-use abstractions for working with databases and allows you to easily swap out the database backend. For example to switch from SQLite3 to MySQL without changing code. It has built-in support for database abstractions to SQLite3, MySQL, and PostgreSQL. One of the primary aspects of ActiveRecord is that there is very little to no configuration needed. It follow convention over configuration.

ActiveRecord is commonly used with the Ruby-on-Rails framework but you can use it with Sinatra or without any web framework if desired.This tutorial will focus on using it independently, outside of any other framework.

See my SQLite3 Tutorial and Ruby SQLite3 Tutorial for more background on using SQLite3 directly. It is good to have a solid foundation with SQL before trying to work with ActiveRecord.

NeoTrellis M4 CircuitPy Tutorial (AdaBox 010)

I subscribe to Adafruit's AdaBox and I get a fun project every 3 months mailed to me. A little while back I received AdaBox 010 which came with a NeoTrellis M4 board as the centerpiece. The board comes with a microcontroller that can be programmed with Python using CircuitPython.

The NeoTrellis M4 comes with a grid of 32 NeoPixels, which double as buttons. On top of that, it has an audio processor with an 1/8" audio output jack so it can play sound files and generate noise. Furthermore, it even has an accelerometer that can detect motion in three direction so you have even more input available to control the audio and lights. It also comes with a microphone. To top it off, it can act as a MIDI device! It can use the USB port as the MIDI interface or it can use the UART connector for MIDI.

The micro-USB connector is used for power but also acts as a USB removable drive for easy access to the source code files and easily upload sound files. It can also serve as a MIDI USB interface to interact with MIDI software. The USB can also serve as a generic USB HID (Human interface device) like a mouse or keyboard to send events to a computer that it understands like a keypress or a mouse event.

In this tutorial, I try to provide an overview of all the capabilities and give you an idea of all the possibilities with this board. You will find several code examples that focus on one specific aspect of the board.

Python configuration files (INI)

A common need when writing an application is loading and saving configuration values in a human-readable text format. For example, if you need to pass in database configuration information at run-time, you might want to have a file that stores the username, password, and database name in a plain-text file that you can modify. This is where INI configuration files come in.

Python standard library has a configparser module that can read and write INI style files. We will look at how to read and write INI files as well as some alternatives for storing configuration.

Get Directory of Current .py File

When writing a Python application sometimes it can be useful to get the name of the Python file where the code is stored. To take it further, you might want to get the full absolute path of the Python file or just the directory of the Python file. This can be particularly useful if you want to reference resources relative to the Python file, wherever it may reside.

SQLite3 Tutorial

SQLite3 is an ubiquitous relational database written in C. The main thing that stands out about SQLite versus other databases is the fact that the whole database is contained in a single file with no server or configuration needed making it very easy to set up and use. It is licensed as public domain which is even more free than typical open source libraries like MIT or GPL. It uses a mostly SQL compliant language so if you are familiar with any other standard SQL engine the language should be something you are familiar with.

Ruby SQLite Tutorial

SQLite3 is an awesome cross-platform relational database. Some of the major benefits of SQLite include its simplicity and easy management. Everything is stored in a single file and there is no authentication.

One of the big drawbacks with a SQLite database is that there is a global write-lock. Only one write operation can occur at any time. This can create a bottleneck for very write-intensive applications.

SQLite is used in production in many embedded and web applications. For example, you can use SQLite in combination with the Sinatra web application framework to persist data. If you are interested in learning how to use Sinatra, check out my Sinatra Tutorial.

Ruby is an incredibly productive and useful language. Combining Ruby with SQLite3 is a natural fit that opens many possibilities. Add in a simple web framework like Sinatra and you have an incredibly powerful but simple set of tools for building a web application.

You can read more on the official SQLite3 website and on the SQLite Wikipedia article.

If you need a database-agnostic library, something that you can use with SQLite and then easily configure to start using MySQL without rewriting all of your code, you want to use an ORM. ORM stands for Object-Relational-Mapping and the most popular one for Ruby is ActiveRecord.

Ruby Sinatra Tutorial

Sinatra is a minimalist web framework for the Ruby programming language. It is known for being very simple and easy to use. If you are familiar with express.js, it was inspired by Sinatra. I have found it to be incredibly useful and fast to work with. This tutorial will cover some of the common tasks that I have used.

Deploy Ruby Rack Web Apps with uWSGI and Nginx

This tutorial demonstrates how to deploy a Ruby web app using the Sinatra framework using uWSGI and nginx as the web server. This uses the config.ru standard for creating a web app. You can use this method to work with several other Ruby web frameworks including Rails.

This was tested on Fedora 30. Slight modification might be needed for other distributions.

Advertisement

Advertisement