A Hundred Days of Code, Day 026 - Refactoring

Worked only an hour today. Trying to change the little lookup program, I made the other day, into something a little better. Not quite a good day. Calling it quits early.

August 3, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 025 - Comprehension Exercises

Working on Comprehension exercises today. Reflections and Experience I really need feedback, when it comes to programming. I cannot face a blank page. I always seem to start with printing something out to screen and then my brain kind of kicks into gear. Everything after that is just type, print, is this what I expected, if not then fix, type, print … Exercise 3.1 and I think, I am finally getting good handle on comprehensions. from something that would take me at least 10 lines of code to just expressing it concisely in 1! I can read Python messages and take a gander at what I need to do next. I see a '_io.TextIOWrapper' object and know I can iterate over it. I see AttributeError: '_io.TextIOWrapper' object has no attribute 'strip' and realise that it cannot be stripped into parts. I need another way to skin that cat. And then I took it too far (just like this sentence), and nested a comprehension in another one, in where, I had to learn how to put in a conditional in the form of a ternary operator, in Exercise 3.2 (the commented for loop is much simpler!), but that was very good practice. Really stretched me! I caught myself getting distracted a lot. I needed to set a 30 min timer and I spent about 15, looking for where the timer app in my Mint Desktop was, instead of just setting the darned timer on the phone. Took an hour to figure out the comprehension for 3.2 and about 20 minutes to do it for Exercise 3.3. Practice helps! Watching the solutions, and I realise, I got them right in principle, but that I need to be more aware of what happens to an object in memory, so that I can simplify code. I was able to remove one level of comprehension, which I used just to get the end of a string.

August 3, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 023, Day 24 - Tiny Utility to do comparative DNS Lookups

Problem - Compare domain lookups, against DoH Servers Take a list of domains (one per line) from a text file as input, find the IP address for the domain using the standard system level DNS, and then check against DoH answers from both cloudflare and google. and say if all answers match properly or not. Notes What do I need to do? (checklist) Get a list of popular websites, (probably Alexa) figure out a way to read them in loop through each line, and look up its ip with the local dns (use the sockets module) with Google’s DoH json endpoint (use the requests module) with Cloudflare’s DoH json endpoint (ditto like Google) Compare all the values. Print if they match or not. Experience I should commit my work often. This took me two days, because I lost all of yesterday’s progress in a computer hiccough. The program runs well. It intentionally limits itself to only the first result in the Google and Cloudflare lookups. I should learn to focus more on what is at hand and not overthink the program. I should be learning to build primitive little, handy dandy tools, not giant cathedrals. I spent two hours fiddling with a way to create another program that would process files for me. (and abandoned it) I need to read the documentation across sites very carefully. They are written with experienced programmers in mind, and not beginners like me. For e.g. When I was trying to look up domain names with Cloudflare, I blindly copied the example and then wondered why it was not giving me the appropriate replies. I then realised I was missing a seperate parameter, &ct=application/dns-json which was quite clearly listed above, but not in the example below. (which in truth was listed, but as part of the command at the command line and I, like a dumbass, just copied the requisite code to adapt to my Python program. Lesson: Cargo cult with extreme caution) Which leads back to the fact, that I should stick to what is assigned, because just doing that much at this stage is taking me a long time. Improvements and features can wait until I am much more fluent. I realise I am trusting autocomplete too much, and I should at least look at what I am completing. I spent 40 minutes, wondering why my comparisons were not working, when in fact, I was using the wrong variables. Lost loads of time with typos. Be more intentional. More slow. Code. Put your sitenames into a file called dumpsites.txt Run check-ip.py ...

August 1, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 022 - Getting into the Groove

Did the same time as yesterday. Only about an hour. Was much more prodcutive though. Getting the hang of how to sit and program and work through things I do not know. Gaining a bit of experience with the workflow now. I have the basics in hand. I know what I want to look up. So check problem, work a bit, look up, try, fail, repeat, gain incremental success, work some more. Love the feedback loop too. With other stuff I try, I have to wait days, weeks, months. Here, it’s immediate. ...

July 30, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 021 - Swing and a miss

Only did about an hour of distracted work and exercises today. I’ll still count it though. Tomorrow is another day :)

July 29, 2020 · Mario Jason Braganza

A Hundred Days of Code, Day 020 - Setting up an Editor for Python Development

Had given myself a day, to see if I could get a good Python development environment using Elpy and Emacs. It does work. Just not well enough for me. At the end of the day today, I was happy I learnt so much about Emacs. But that is not my focus right now. Python is. Emacs knowledge can come slowly and organically. So I have kept Emacs as my regular editor for nearly everything text. And switched to the community edition of Pycharm for all my Python projects. ...

July 28, 2020 · Mario Jason Braganza