Enough is plenty. Good enough will do.
1638 words

Dictionary Comprehension

I have have had a much harder time of wrangling dictionary comprehensions than necessary. Code block. Like writers block perhaps? Feeling a bit slow with being stuck for a while on a project stage.

A touch of cognitive overload. Some interesting ideas about this at Cognitive Load and Coding. Worth a read with some good references at the end to follow up. A progammers cognitve load was especially helpful. I have increased the font size in my IDE and enabled auto folding. Basic stuff I could have done ages ago if I'd have been curious enough.

Back pain. Change in routines blah blah blah... It's all transient so long as I don't give up. Take some respite and come back to the learning.

Made some progress yesterday. A new approach. Narrowed my focus. Completed some PyBites. Encouraged by solving a few of these I completed one on dictionary comprehensions. Pybites is handy to have on my list of go to places for learning Python.

I am hoping to help embed what I'm spending time learning by writing something about it here. First time trying. Hopefully I've understood it and I've written nothing here to misinform. Corrections are welcome. Here goes:

bites = {6: 'PyBites Die Hard',
         7: 'Parsing dates from logs',
         9: 'Palindromes',
         10: 'Practice exceptions',
         11: 'Enrich a class with dunder methods',
         12: 'Write a user validation function',
         13: 'Convert dict in namedtuple/json',
         14: 'Generate a table of n sequences',
         15: 'Enumerate 2 sequences',
         16: 'Special PyBites date generator',
         17: 'Form teams from a group of friends',
         18: 'Find the most common word',
         19: 'Write a simple property',
         20: 'Write a context manager',
         21: 'Query a nested data structure'}
exclude_bites = {6, 10, 16, 18, 21}


def filter_bites(bites=bites, bites_done=exclude_bites):
    """return the bites dict with the exclude_bites filtered out"""
    return {key: value for (key, value) in bites.items() if key not in bites_done}


print(filter_bites(bites, exclude_bites))

So what that does is to take a dictionary bites and a set exclude_bites. From them we return a new dictionary from the entries of the existing dictionary excluding entries whose key matches an element in the set.

return {key: value for (key, value) in bites.items() if key not in bites_done}

Which returns dictionary items -

{
7: 'Parsing dates from logs', 
9: 'Palindromes', 
11: 'Enrich a class with dunder methods', 
12: 'Write a user validation function', 
13: 'Convert dict in namedtuple/json', 
14: 'Generate a table of n sequences', 
15: 'Enumerate 2 sequences', 
17: 'Form teams from a group of friends', 
19: 'Write a simple property', 
20: 'Write a context manager'
}

Notice that dictionary items with a key that matches an element in the set {6, 10, 16, 18, 21}have been excluded.

Key can be generated from an immutable type int, float, decimal, complex, bool, string, tuple, range, frozenset, bytes. With this example the int is used (iterated) from the bites dictionary. The keys must also be hashable. For example a tuple with lists will not work as lists are mutable and therefore not hashable. A tuple of strings would be fine as strings are immutable.

Python dictionaries leverage hash tables. When we use a key that contains an unhashable type, i.e. a list, the underlying hash map cannot guarantee the key will map to the same bucket every single time. If we can't hash our key, we can't use it in our dictionary. The thing to remember is that Python dictionaries require hashable dict keys. Immutable keys is not enough. (nods*)

The value may be assigned to any iterable bites_items() in this case. It does not need to be immutable. It could also be assigned the same value for all keys. The condition to filter/sort simply follows the if statement. Here exclude_bites is called to check and iterate through .

Well I think that worked. Feel like I have furthered by understanding a bit. Yeah I know... practice more and do projects!

Run your own cloud with NextCloudPi.

I've gone down the route of self hosted cloud. Last year I decided to have a go with NextCloudPi. It took a few goes to get things right. From time to time it has gone a bit cranky and needed a bit of maintenance though no data has been lost and backups have worked as hoped for when needed. It's a working alternative to giving my data to someone else to look after and manage. A satisfying endeavour.

Needed a router that could configure Port Forwarding and NAT loopback. A Raspberry pi. I went with the 3+ with power supply. A couple of external hard drives (Seagate 1TB). A USB power hub. A USB stick (16G). I had a screen and keyboard for the RaspberryPi. It's handy though not entirely necessary.

The installation instructions here were helpful. Notable change was to not bother with an SD card. The 3+ will boot from a USB drive so just used that. I believe a USB stick is more reliable than an SD card for this purpose.

The database is on the USB stick. The data directory (my files/music etc) is on HD1 along with scheduled snapshots to revert back to if and when needed. The data is backed up to HD2 via synced snapshots from those on HD1. The database is also on a scheduled back up to this drive along with the configuration files for the NCP install. Instructions for doing this are here.

It totally serves the purpose I wanted it for. It's FOSS. Contacts, calendar and tasks synced between devices. Files accessible anywhere and backed up to external storage. I can stream my own music. There's the ongoing satisfaction of having it work. I love it! Big thanks to Nacho Parker at ownyourbits for the hard work of putting this out there.

NextCloudPi

Learning to code. You're good enough. A worthwhile effort.

So I have been learning to code using Python. It started as a distraction over the Christmas holidays in 2019. It's now November 2020. I've coded way more days than not over that time. #100 days straight? Most likely and more than once. Not been counting.

Coding exercises, tutorials, blogs, websites, podcasts and so on. Enjoyed reading posts on dev.to where I'm learning the language and getting a feel for the culture of the development world. There's much talk about impostor syndrome. Seems it pretty endemic. Not heard it referred to as much with reference to any other endeavour. Something perhaps to do with a lot of developers being self taught and/or that learning on the job is a prerequisite and necessity to stay match fit.

Getting stuck with things right now. Final stage of a 'hard' project on Jet Brains Academy and just not getting it. Learning Python (easy); learning to program (hard). Codecamp says I'm -

codecamp

Completing exercises and small projects is no longer enough to keep making progress. Shame as I was enjoying the illusion the pace had created! Deliberate practice might be what's needed from now.

Deliberate practice is not a comfortable activity. It requires sustained effort and concentration. The people who master the art of deliberate practice are committed to being lifelong learners—always exploring and experimenting and refining.

My interest is starting to wane. I've been avoiding getting on. Finding other distractions. Not having so much fun. Asking myself if I can even be bothered with it anymore. That could be the impostor syndrome in disguise. See you're already getting the traits! Perhaps it's not that you can't be bothered it's that you don't think you're good enough. Let that shit go!

Coding skill is an attribute I would like to have. Here's to the effort deliberate practice takes!

Monday 2nd November 2020

I have been using Standard Notes for a few years now. The functionality has improved progressively over this time. The latest update to the desktop client 3.5.1 has all notes decrypted and on display very quickly.

I moved over to Standard Notes having tried a number of other different note keeping apps. It was a laborious process transferring everything I had in Evernote. Worthwhile though and I have never looked back.

Standard Notes ticks boxes for privacy, longevity, FOSS and ownership of data. The simple UI and rendering is a plus. Syncing between devices is as expected. I only use a few extensions and those I do work great. Back up and restore has been flawless. Very reassuring.

I have been aware of Listed for a while. I like the platform. The simplicity. Not been minded to use it much though. Had a go now and then out of curiosity but nothing more. I have kept a blog for years using Wordpress. Neglected a blog for years might now be more accurate to say. Times have moved on. An over-engineered solution and way more than I use. The notion of posterity has kept it going. I shall archive, shut down and move on.

The intention now is to start using Standard Notes / Listed to support my learning to program using Python. I often read how easy it is to learn how to code using Python. Depends what your reference point is I guess. I've been at it since December 2019. No prior related experience. I have got to the point of understanding that learning Python is not the same as learning to program. That realisation is perhaps a useful measure of the level I am at with it. In that regard learning Python to an intermediate level has I suppose been quick and easy. To keep moving forward from this point is the aim.

So then posts here shall be about all that and the odd bit of Linux related stuff I come across and find helpful. Desktop (Ubuntu), mobile (Pine Phone) and Raspberry Pi. Maybe a bit about cycling. Long distance audax. Perhaps the odd comment on unrelated ideas that I'd feel some benefit from thinking about, writing down and sharing. That kind of thing.