The 10-3-2-1-0 Rule

10h before sleep – no caffeine
3h before sleep – no more eating
2h before sleep – no more work
1h before sleep – no more tv / tablet
0 times snoozing the alarm clock in the morning

So when I want to get to bed at around 22:00 (10pm) my schedule would look like the following

  • 12:00 – stop drinking caffee
  • 19:00 – stop eating
  • 20:00 – stop working
  • 21:00 – stop watching Netflix/Prime/Youtube
  • Stop snoozing the alarm clock when it rings at 6:00

After one week my experience is this:

  • 12:00 – stop drinking caffee
    • good and easy to do, I drink one cup in the morning and at max 2 cups at work
    • positive effect on my skin picking issue
  • 19:00 – stop eating
    • not as easy, sometimes I’m late from work
  • 20:00 – stop working
    • no-brainer, I rarely stay at work after 19:00
  • 21:00 – stop watching Netflix/Prime/Youtube
    • hard, hard, hard, at the moment I practice guitar / piano from around 19:30 till 21:00
  • Stop snoozing the alarm clock when it rings at 6:00
    • not working I still snooze between 2 to 5 times, so I get up at 6:30 minimum

Some tweeking

I shifted my sleep time from 22:00 – 6:00 to 22:30 – 6:30

  • 12:30 – stop drinking coffee
  • 19:30 – stop eating
  • 20:30 – stop working
  • 21:30 – stop watching Netflix/Prime/YouTube
  • Stop snoozing the alarm clock when it rings at 6:30

 

 

SQL-Basics: Relations

As the Junior Data Scientist of Knight Industries we created a table to keep track of all our operatives: SQL-Basics: Create, Read, Update, Delete

Devon asks us to keep track of our operations aka missions as well. For the first implementation let us assume that a mission has one operative and an operative can participate in multiple missions. that’s what we call an 1 to many relationship.

  +------------+                 +----------+
  |            |1   active in   n|          |
  | operative  +-----------------+ missions |
  |            |                 |          |
  +------------+                 +----------+

Missions have an id, a code name like “Phantom Liberty”, an operative id and a total cost. Continue reading “SQL-Basics: Relations”

SQL-Functions

In SQL-Basics

we learned the standard SQL statements to create a table, insert data into it, retrieving data from tables and altering data. Now we want to do even

Devon is a data driven man and to evaluate our mission, he likes to know from us:

    • how many missions we finished
    • the total cost of all missions
    • the mission with the lowest cost
    • the mission with the highest cost
    • the average mission cost
    • the five most expensive missions

 

SELECT COUNT(*) FROM missions;
SELECT SUM(total_cost) FROM missions;
SELECT MIN(total_cost) FROM missions;
SELECT MAX(total_cost) FROM missions;
SELECT AVG(total_cost) FROM missions;
SELECT * FROM missions ORDER BY total_cost DESC LIMIT 5;

Distributing your own package on PyPi – Part 2

In Distributing your own package on PyPi I wrote about my first package on PyPI. Here are some refinements aka lessons learned:

Project Description on PyPI

I wondered why the project description on PyPi was empty. Solution: You need a long_description. If You already have a README.md, you can read it into a string and use this as the description.

But you have to add long_description_content_type=’text/markdown’ as well.

from setuptools import setup

# read the contents of your README file
from os import path
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
    long_description = f.read()

setup(
    name='flask_url_mapping',
    version='0.6',
    packages=['flask_url_mapping'],
    url='https://github.com/jboegeholz/flaskurls',
    download_url='https://github.com/jboegeholz/flaskurls/archive/0.2.tar.gz',
    license='MIT',
    author='Joern Boegeholz',
    author_email='boegeholz.joern@gmail.com',
    description='Django-style URL handling for Flask',
    long_description=long_description,
    long_description_content_type='text/markdown',
    install_requires=["Flask", "Flask-Login"]
)

 

Dependencies of your Package

If your package relies on the usage of other python packages you should add them to your setup.py as well via install_requires.

setup(
    name='flask_url_mapping',
    version='0.6',
    packages=['flask_url_mapping'],
    url='https://github.com/jboegeholz/flaskurls',
    download_url='https://github.com/jboegeholz/flaskurls/archive/0.2.tar.gz',
    license='MIT',
    author='Joern Boegeholz',
    author_email='boegeholz.joern@gmail.com',
    description='Django-style url handling for Flask',
    install_requires=["Flask", "Flask-Login"]
)

Introduction to matplotlib – Part 2

When you finished reading part 1 of the introduction you might have wondered how to draw more than one line or curve into on plot. I will show you now.

To make it a bit more interesting we generate two functions: sine and cosine. We generate our x-values with numpy’s linspace function

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi)

sin = np.sin(x)
cos = np.cos(x)

plt.plot(x, sin, color='b')
plt.plot(x, cos, color='r')
plt.show()

You can plot two or more curves by repeatedly calling the plot method.

That’s fine as long as the individual plots share the same axis-description and values.

Subplots

fig = plt.figure()
p1 = fig.add_subplot(2, 1, 1)
p2 = fig.add_subplot(2, 1, 2)
p1.plot(x, sin, c='b')
p2.plot(x, cos, c='r'

The add_subplot method allows us to put many plots into one “parent” plot aka figure. The arguments are (number_of_rows, number_of_columns, place in the matrix) So in this example we have 2 rows in 1 column, sine is in first, cosine in second position:

when you have a 2 by 2 matrix it is counted from columns to row

fig = plt.figure()
p1 = fig.add_subplot(221)
p2 = fig.add_subplot(222)
p3 = fig.add_subplot(223)
p4 = fig.add_subplot(224)
p1.plot(x, sin, c='b')
p2.plot(x, cos, c='r')
p3.plot(x, -sin, c='g')
p4.plot(x, -cos, c='y')

The code is available as a Jupyter Notebook on my github