Hi folks,
Here’s a brand new short song I recorded while practicing on the piano. It’s titled Equanimity and is in the key of D♭. Enjoy.
IT and anything that fascinates me
Hi folks,
Here’s a brand new short song I recorded while practicing on the piano. It’s titled Equanimity and is in the key of D♭. Enjoy.
In this post I go over how to automatically document Django applications. By this I refer to a way to run a tool that automatically reads your projects and docstrings and generates beautiful documentation. Sphinx is an excellent tool for the job. Sphinx makes it easy to create beautiful intelligent documentation for projects. It uses reStructuredText as its markup language. Here’s how to go about it.
First install Sphinx using the command:
pip install sphinx
Initialise Sphinx
sphinx-quickstart
You will be asked several questions which will be used to generate a configuration file, a few folders and possibly a Makefile. You will want to make sure you enable autodoc to allow generating documentation from docstrings as well as the generation of Makefile so that you can run the make command in the future to update documentation. Below is an example of the what the screen looks like for these
Welcome to the Sphinx 1.6.1 quickstart utility. Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets). Enter the root path for documentation. > Root path for the documentation [.]: ./docs You have two options for placing the build directory for Sphinx output. Either, you use a directory "_build" within the root path, or you separate "source" and "build" directories within the root path. > Separate source and build directories (y/n) [n]: n Inside the root directory, two more directories will be created; "_templates" for custom HTML templates and "_static" for custom stylesheets and other static files. You can enter another prefix (such as ".") to replace the underscore. > Name prefix for templates and static dir [_]: The project name will occur in several places in the built documentation. > Project name: Your Project Name > Author name(s): Some Author Name Sphinx has the notion of a "version" and a "release" for the software. Each version can have multiple releases. For example, for Python the version is something like 2.5 or 3.0, while the release is something like 2.5.1 or 3.0a1. If you don't need this dual structure, just set both to the same value. > Project version []: 0.1 > Project release [0.1]: If the documents are to be written in a language other than English, you can select a language here by its language code. Sphinx will then translate text that it generates into that language. For a list of supported codes, see http://sphinx-doc.org/config.html#confval-language. > Project language [en]: The file name suffix for source files. Commonly, this is either ".txt" or ".rst". Only files with this suffix are considered documents. > Source file suffix [.rst]: One document is special in that it is considered the top node of the "contents tree", that is, it is the root of the hierarchical structure of the documents. Normally, this is "index", but if your "index" document is a custom template, you can also set this to another filename. > Name of your master document (without suffix) [index]: Sphinx can also add configuration for epub output: > Do you want to use the epub builder (y/n) [n]: Please indicate if you want to use one of the following Sphinx extensions: > autodoc: automatically insert docstrings from modules (y/n) [n]: y > doctest: automatically test code snippets in doctest blocks (y/n) [n]: y > intersphinx: link between Sphinx documentation of different projects (y/n) [n]: y > todo: write "todo" entries that can be shown or hidden on build (y/n) [n]: y > coverage: checks for documentation coverage (y/n) [n]: y > imgmath: include math, rendered as PNG or SVG images (y/n) [n]: y > mathjax: include math, rendered in the browser by MathJax (y/n) [n]: > ifconfig: conditional inclusion of content based on config values (y/n) [n]: > viewcode: include links to the source code of documented Python objects (y/n) [n]: > githubpages: create .nojekyll file to publish the document on GitHub pages (y/n) [n]: A Makefile and a Windows command file can be generated for you so that you only have to run e.g. `make html' instead of invoking sphinx-build directly. > Create Makefile? (y/n) [y]: > Create Windows command file? (y/n) [y]: n Creating file ./docs/conf.py. Creating file ./docs/index.rst. Creating file ./docs/Makefile. Finished: An initial directory structure has been created. You should now populate your master file ./docs/index.rst and create other documentation source files. Use the Makefile to build the docs, like so: make builder where "builder" is one of the supported builders, e.g. html, latex or linkcheck.
Upon completion, a docs file should appear in your project.
You can then generate documentation in HTML format by changing to the docs folder and running the following command:
make html
You should see something like:
Running Sphinx v1.6.1 making output directory... loading pickled environment... not yet created loading intersphinx inventory from https://docs.python.org/objects.inv... intersphinx inventory has moved: https://docs.python.org/objects.inv -> https://docs.python.org/2/objects.inv building [mo]: targets for 0 po files that are out of date building [html]: targets for 1 source files that are out of date updating environment: 1 added, 0 changed, 0 removed reading sources... [100%] index looking for now-outdated files... none found pickling environment... done checking consistency... done preparing documents... done writing output... [100%] index generating indices... genindex writing additional pages... search copying static files... done copying extra files... done dumping search index in English (code: en) ... done dumping object inventory... done build succeeded. Build finished. The HTML pages are in _build/html.
Now we will tell Sphinx to document the modules of one of our applications.
Open docs/conf.py
After the first block of comments, add the following code so that Sphinx can read docstrings from project files:
import os import sys import django sys.path.insert(0, os.path.abspath('..')) os.environ['DJANGO_SETTINGS_MODULE'] = 'yourprojectname.settings' django.setup()
Next, create a modules folder within docs. We will use these to hold our documentation. E.g. To document models, create a file at modules/models.rst.
Edit models.rst and add the following content:
Models ====== .. automodule:: yourappname.models :members:
Save and close the file.
Next, make this link available in the documentation index by editing docs/index.rst.
Find the section starting with .. toctree:: and add a line modules/models under it so that it looks like this:
.. toctree:: :maxdepth: 2 :caption: Contents: modules/models
Save and close the file.
Now is the time to regenerate the documentation.
Run the following command from inside the docs folder.
make html
You can access the documentation by opening docs/_build/html/index.html in a browser. You should see ‘Models’ under ‘Content’.
That’s it!
If you want to be able to access your documentation from the Django application itself, e.g. using a link like /docs/, you can do this using the awesome django-docs package.
Enjoy.
Reference
1. Documenting your Django application with sphinx. https://madradavid.com/documenting-your-django-application-sphinx/.
Hi folks,
In this post I’ll share a really small but handy tip I discovered while using Git.
Let’s say you make some commits on your local repository which you later find undesirable. You can of course use git reset –hard to put the repository in previous state that doesn’t have those commits.
Let’s assume that later (perhaps after adding a few fresh commits) you try to push this to the remote repository, git will refuse by default because the remote repository has more commits.
To force git to accept the push you need to add the -f flag.
git push -f
Note: you should only force a push if you are the only one with access to the repository or you are sure that other users haven’t cloned the existing state of the remote repository, otherwise forcing a push could lead to problems of diverging history for other users.
Hi folks,
I just recorded a new gospel song – Thank You Lord using strings voice. This song has just the instrumentals, so it’s a good one to sing along to. Below is the recording.
Enjoy.
Hi folks,
Today I’m going to talk about a cool way to end worship songs when the last chord is a 1 chord. The idea is that instead of just playing the 1 chord and stopping, we play a short progression.
First, play 5 and 1 notes simultaneously on the right hand while you play the 7 note on the left hand.
Then play the 4 and 1 notes simultaneously on the right hand while you play the 6 tone on the right hand. Essentially you’re moving your first left and right fingers down one whole step.
Play the 2 and 1 notes on the right hand while you play the ♭6 note on the left hand.
Finally, play the 3 and 1 notes on the right hand while you play the 5 and 1 notes on the left hand.
In the key of D♭major, here are the steps:
Play A♭ and D♭ on the right hand and C on the left.
Play G♭ and D♭ on the right hand and B♭ on the left hand.
Play E♭ and D♭ on the right hand and A on the left hand.
Play F and D♭ on the right hand and A♭ and D♭ on the left hand.
Below is a recording of the progression.
And below is a recording of the end of the song ‘Thank You Lord’ using this progression.
Hi folks,
In this article I will discuss how to fix a problem with unmounting file systems in Ubuntu. Suppose you want to unmount a file system /some/endpoint for example in Ubuntu but run into an error like
umount: /some/endpoint: target is busy (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1).) Mount is denied because the NTFS volume is already exclusively opened. The volume may be already mounted, or another software may use it which could be identified for example by the help of the 'fuser' command.
An easy way to find out what exactly is using that endpoint is to run the following command:
lsof | grep /some/endpoint
Once you see what process is using the filesystem, you can then go ahead to kill or end it.
Hi folks,
In this post I will briefly talk about a concept that’s very important to know in order to easily play songs in all 12 keys. It’s called the Number System.
Before learning the Number System, I used to find it quite challenging to transpose songs since I thought of each key as its own distinct set of notes. But by thinking of the tones of a scale as numbers, you create a common language to describe what you need to play regardless of scale. This made it significantly easier for me to play in all 12 keys. Here’s a quick example. Suppose you want to play the melody of the first line of Mary has a Little Lamb in the key of C, one can describe this as
E D C D E E E
In the key of G, it will be:
B A G A B B B
Now, instead of thinking of the tones distinctly when trying to play the song, we can use the Number System to abstract this to
3 2 1 2 3 3 3
To make this system effective, one will need to know for each key what tone corresponds to what number. E.g. C is the first tone of C, D is the second tone of C, etc. Once you master the Number System, you can apply it to chord progressions to quickly understand common patterns in music, e.g. the 2-5-1 or 7-3-6 chord progressions.
Here I go over a cool progression for beginning worship songs. It is as follows:
1 7 4major(third inversion)/6 1 5major(third inversion)/7 5
E.g. In the key of D♭, suppose your song starts with the 1 chord D♭major(add 9), you can preceed it with the progression by playing
D♭ C G♭major(third inversion)/B♭ D♭ A♭major(third inversion)/C A♭ D♭major(add 9)
Below is a recording.
Recently I was watching a tutorial on how to transition from first to second tone chords (or 1-2 couples). The instructor said one could go from the 1 chord to a ♭2 diminished chord and then the 2 chord. This got me thinking. If diminished chords could be used in transitioning from the 1 chord to a 2 chord, is there anything else it could be used for? Curious, I decided to do a bit of research on the subject and ran into an excellent Youtube video that threw more light on it. Here I will discuss briefly what I have learnt about diminished chords: how they are formed and when to use them.
Diminished chord is one of four basic chords, the others being Major, Minor and Augmented. To form a diminished C chord for example, you start with the C note, then place the next finger on the note one minor third away, i.e. E♭, and the last finger on the note one minor third further, i.e. G♭. So, C E♭ G♭ are the notes in the C dim chord. If you want to extend it, then you can go a further minor third away to A and you have C dim7. So, generally, tones of diminished chords are minor third intervals apart.
Something interesting to note about diminished chords is that the diminished 7 chord of each tone in a given diminished 7 chord shares the same notes as all the other tones in the chord. For example. Consider Cdim7 comprising C E♭ G♭ A. Considering the second inversion of the chord E♭ G♭ A C, we have E♭dim7 chord. Taking the third inversion G♭ A C E♭, we have G♭dim7 and the fourth inversion A C E♭ G♭ is simply the same as Adim7. A consequence of this is that for all twelve tones of a scale, there only three types of dim7 chords to learn in terms of tone composition .
Now to the fun part. How can we use diminished chords to spice up our music? One way is by playing a diminished chord one semitone before the key of the chord you want to play, then playing the desired chord. E.g. if you want to play a Cmajor chord, you can preceed it with a B♭dim7 chord. This works for both major and minor chords.
Another way to use it is to first play a diminished 7 chord of the same chord tone you want to play, then play the desired chord tone. E.g. if you want the Cmajor chord, you can precede it with a Cdim7 chord.
A third way to use it is to first play a diminished 7 chord one semitone after the your desired tone, then play the desired chord. E.g. if you want to play an Aminor chord, you can precede it with a B♭dim7 chord. This method is good especially for minor chords.
Here is an excellent Youtube tutorial that explains all these in great detail.
By making use of diminished chords, one can fill some of the empty space between chord progressions and also introduce a more interesting sound to one’s playing. That’s all for now.
Today I came across a cool keyword in a Sass file. It’s called ‘!default’. There was a variable declaration and then !default after it e.g.
$foo: 20px !default;
So, I decided to fine out what exactly it means. !default means the variable will be set if it has not already been set. This way, you can declare project specific values of a variable first and then add the defaults after it.
Sources