Tonight I just couldn’t do another few hours of tutorials so I made up a small project that I have been thinking about for a while.
Jerry seinfeld has an often repeated story about building a practice. For him it is writing jokes, but it could be anything. He recommends to put a big calendar in a very visible place in your house and put a red X on it when you write jokes. The next day you should do the same. Eventually you will have a ‘chain’ of good days, and human nature will not want to break that chain. By making a visual indicator of your practice habits it can help motivate you to get off the couch. I found a few physical examples of this concept on medium here.
My version of this will (eventually) be an auto updating desktop image that pulls from a log of my studies. It’s written in python and leans heavily on the python image library PIL.
Here we go.
noDaysOff – build timeline
Goal: Get as much done as I can before bed. test as I go, and try to minimize feature creep.
8:10pm start coding
google “pil rectangle” because I haven’t drawn boxes in PIL before. This is the first of many many google searches for the night. I have my chrome history at the bottom of the page.
8:19pm find this PIL sample code and build a script that can make a canvas and draw a box. Our first taste of success!
version up -> v002 I’m not using git here yet, so I’m just saving periodically with incrementing file names so that I can roll back if need be, and also refer to the way things “used to be done”
8:31pm – Now I can input a width and a height and it will draw 31 boxes across the top in one row. It will scale the boxes to fit within the canvas. I have decided on a layout where every month has a row, but I may add another wrapping layout in the future.
next up – month lookup to find the number of days in a month.
8:43pm version to v003
Month lookup and leap year lookup is done! I did a leap year function this week in cs101, but it was much nicer to use the built in calendar.isleap(year) function!
next up – either weekend detection or reading in the text file. This will use a text file as an easy way to enter in the data. It will write a file on the first run, and then scan it for data on every following run.
8:58pm versioned up to v004, weekends have been found! it was easier than I thought it would be.
if datetime.datetime.weekday(datetime_object) in [0,6]: #detect weekend
It currently makes different colored boxes on the weekends. now to test.
9:06pm weekend detection looks good but is one day off. it says jan 1 2018 is a sunday, but google says monday
hmmm. maybe I’ll switch to reading in data so I can get the taste of failure out of my mouth!
9:14pm start by writing the text file. that’s pretty simple. I’m not using the csv writer. Maybe I should be, but the text writer works fine for this right now. Eventually I would like to use os to put the text file right next to the script. it’s hard-coded now.
9:20pm it is writing and reading from file, but not sure yet how to do anything with it. I’m writing to a text file and reading it back in as a csv.
10:00pm v005 I spent a bunch of time trying to track down a bug that came down to I implemented my leap year check backwards. sigh. The day counter seems to be slightly wrong as well. it doesn’t add up to 365. I should be testing my functions as I go and building tests for them specifically. I need to look into testing more.
10:21pm I think I’ve got most of the bugs ironed out for now. I still don’t have the weekend thing fixed.
10:58pm I added a “days worked” counter and got that text to appear. I also commented a bit, wrote down some to dos for tomorrow and cleaned up a few things.
Below is the visual evolution during my 3 hours of coding. I think it’s rewarding to see it looking nicer than before.
…and here is my shit ton of google searches! I’m hoping to memorize more syntax in the future, but in the meantime I feel like writing code is better than memorizing syntax. It also may help me learn it while writing it!
It was fun to bang out an almost functional prototype in one night. I have a lot of polishing to do, but it does help the ego a little after getting emotionally crushed on codewars time after time!
2 thoughts on “Coding sprint – No Days Off”