Learning Flask with Corey Schafer

My Summer project is to finish an initial version of my Practice Math site for our kids. I’ve hit a bit of a snag with fractions, but the functionality for whole numbers is almost ready.

The next step is to create a web site for the project so our kids can use the app through their browsers, rather than using the command line (somehow, I don’t think a CLI interface will grab our kids).

My plan was to learn Django, and use that to create a front-end for my Python back-end. I decided to follow along with Brad Traversy to help me learn how to create a basic Django app. It was a little trickier than I expected, and I hit a snag with my database configuration.

I then thought I’d take a look at Flask, and see if that would be a little easier for me to grok. I noticed that Corey Schafer has a Flask tutorial series where you build a basic blog with Python and Flask, so I decided to work through Schafer’s tutorial videos.

This has proven to be a terrific idea. Schafer’s tutorials are detailed, and really clear. There are times when he speeds up a little but, for the most part, I can follow along pretty comfortably, and understand what he’s doing.

Even though the goal of Schafer’s series is to build a blog, it covers a range of topics that I can incorporate into Practice Math down the line. It’s really an awesome introduction to building web sites with Flask, and well worth the time.

Not only does Schafer take you through the process, step-by-step, but he also provides links to snapshots of his code at each step of the process, along with useful code snippets in his GitHub repos.

You probably need about an hour for each episode. I binged for most of today (I’m on vacation this week), and worked through about four or five videos.

If you’re interested in Corey Schafer, listen to this TalkPython interview with him:

On a related, side note, working through this tutorial series just reinforces how glad I am that I returned to Python to start learning it (again). I still have a long way to go, but it feels like I’m picking up bits of it easier than I did with JavaScript.

I’ll return to JavaScript, for sure (you can’t really ignore JavaScript these days). For now, though, I love all the things I’m learning to do with Python.

Featured image by Sharon McCutcheon

Practice Math – the Python Edition

One of my projects this Summer is to create a working version of my Practice Math project. The goal of this project is to create a site that my kids can use to practice their math.

The idea was to create a simple site that would randomly generate math equations that kids could use to practice addition, subtraction, multiplication, and division. To do this, the site would need to have the following functions, at least in the first phase of my project:

  1. Randomly generate two numbers, and a math operator to create an equation;
  2. Evaluate the solution to the equation;
  3. Prompt the child to offer an answer to the equation;
  4. Compare the child’s answer with the actual solution, and give feedback;
  5. Make sure that equations don’t produce negative solutions (our kids haven’t really learned how to work with numbers less than zero); and
  6. Round answers to two decimal places (it can be more than this, I just picked two decimal places for now).

Version 1 – the Javascript Edition

My initial version of the project was based on Javascript. You can find that one here, on GitHub. I wasn’t able to make much progress beyond randomly generating the numbers and math operators that would be used in equations.

I hadn’t worked out how to evaluate the randomly generated numbers, more move much beyond point two in my list of features. I’m certain it’s possible, I just hadn’t worked it out yet.

Version 2 – the Python Edition

I recently decided to return to learning Python. I last attempted to learn Python about a year and a half ago. At the time, I was learning Python 2.7.x. I didn’t move beyond loops at the time.

This time, I decided to start with Python 3.x, which is the current version. I’ve been learning when I have time, and I really like the language. I decided to revisit my Practice Math project and create a Python version to help me learn the language.

I finally sat down this morning, and worked on a script that does all six of the things I want it to do. I’ve published my code on GitHub, here. Here it is in action:

I can’t take credit for what you see there, not entirely. I borrowed pretty heavily from a few sources to produce the version you see there:

Cory Kramer’s solution (the third one in this list) was particularly helpful because it helped me split my code into disparate functions. This makes the script a lot easier to read, and tweak.

My current code still has some test stuff in it. For example, the script current prints the two generated numbers, the operator, and the solution so I can check that it’s all working properly:


print("\nThis is for troubleshooting purposes only:")
print(num1) # For testing
print(num2) # For testing
print(op) # For testing
print("\nWhat is {} {} {}? > ".format(num1, op, num2))
solution = round(eval(f"{num1} {op} {num2}"), 2)
print(solution) # For testing

Next steps

The next step is to create a web interface for this. A command line version is fine to play around with, but for this to be useful, it needs to be a web site. I haven’t worked out how to add a Javascript front-end to this (I believe it’s possible, I have no idea how to do it, though).

What I’ll rather do, though, is use a Python web framework like Django to create a front end for the site. I’m really keen to learn how to do that, partly because I want to port my Modiin Bus project over to Python too at some point (I discovered that the transit data that I’d like to use is available through Python APIs).

At the same time, I also intend figuring out how to represent fractions in the web interface. I know that’s it’s possible to use Javascript to represent fractions on a web page using options such as math.js and MathJax. I’ll look for equivalent options for Python/Django.

There are also a couple niggling issues about the current version that I’d like to resolve too. These likely exist because I’m still very much a Python newbie.

I’m sure there are other improvements I could make to how the script accepts, and processes input from users. I’ll figure that stuff out as I go. For now, I’m pretty please that this core script seems to be working.

Raising brave, imperfect daughters, and teaching them to code

Last week I came across a tweet sharing Reshma Saujani’s TED talk, titled “Teach girls bravery, not perfection“. I immediately bookmarked it to watch with my daughter (and tweeted my plan to do that).

Saujani replied to my tweet, and asked me to let her know what my daughter thought of the talk.

So, I watched the talk on Saturday morning with my 7 year old (along with my son). Afterwards, I asked her what she thought about what Saujani said about how important it is to be brave, rather than being perfect, and how the quest for perfection is so self-defeating.

My daughter said she liked the video. I asked her to elaborate, and she commented on this talk has inspired her to try to learn to code again. She said that she stopped trying the first time around because she kept making mistakes.

I noticed this when I introduced her to coding on Code.org last year. She started off really excited to see what she could create after watching me learn front-end web development for most of last year. But she soon gave up when the exercises became trickier and she found herself making mistakes.

Since watching the talk, she’s been asking me when she can get back to learning to code. It also helps that my son has also returned to learning to code after seeing me return to Python (I’ve started at the beginning with Python 3).

Now all I need to do is pick a learning platform for her to learn with. So far, Code.org and Scratch look like good options for her.

Photo by Jelleke Vanooteghem on Unsplash

Why you should learn to program

I just watched Christian Genco‘s 2012 talk at TEDxSMU titled “You Should Learn to Program“. It’s a fun 10 minute talk that highlights why it’s so awesome to learn to code.

You should watch this video, regardless of whether you can code or not. As an aside, Genco is a pretty interesting person to follow too.

42

Today is my birthday. I’m 42.

I’ve never been a “well, a birthday is just another number” person. To me, each birthday is a special day, an event to celebrate.

I usually celebrate my birthdays with a “Me Day” if the day falls mid-week. Last year I took the day off, watched one of my favourite movies, and went for a photowalk around my city.

Living in interesting times

This year has been an interesting one, to say the least. I’ve been thinking about what to write about it for a couple months and, as I sit here writing this, I’m not entirely sure what to make of it.

I left my job at InboundJunction in March (it didn’t work out for a couple reasons and my contract was terminated), and I’ve been looking for a job since then. I started doing some freelance marketing work around the same time but my main focus has been on my search for a fulltime position.

As I write this, I’ve applied for 148 positions (I have 67 current applications). Many of the companies I’ve approached and interviewed at, are remarkable companies. One thing that has struck me during my job search is just how many amazing opportunities there are here in Israel.

Granted, not all of those companies are my dream employers but those companies are in the distinct minority. Whatever may be going on in the rest of the world, Israel is buzzing.

Code, the Universe and Everything

One of the benefits of the Israeli social net is about 7 months of unemployment benefits to help get you back on your feet. You can’t retire on the monthly payments but they give you some breathing room.

Rather than spending my time watching Netflix in between job applications, interviews, and occasional freelance work, I started learning to code in earnest. I started with HTML (I knew some HTML but my knowledge was patchy), moved on to CSS, and just kept going.

Although I’ve wanted to learn to code for decades (literally), I never really got around to it (aside from developing a proficiency in MultiMarkdown, and picking up a little Python 2.7.x last year). Being unemployed with time on my hands gave me the perfect opportunity.

A couple factors pushed me off my procrastination ledge. One was seeing our son learning basic JavaScript on Code.org earlier this year. Another was watching a friend of ours spend a few minutes showing us a few simple (yet awesome) command line “tricks”. Then, there is this terrific video from Code.org:

Learning to code has helped me realise that code creates possibilities. Like Karlie Kloss said, “understanding coding is … like a superpower”. It takes from a place where you wish “someone” made that thing you want, to be able to make it yourself.

My journey that started with <!doctype html> has taken me through a fantastic world where, using a text editor and an Internet connection, you can build amazing things. Here are a few of the languages I’ve learned (in varying degrees):

  • HTML;
  • CSS;
  • JavaScript (including Node.js, React and Ember);
  • WordPress-oriented PHP;
  • Shell scripting (I’ve learned to love the command line);
  • Build tools like gulp, npm scripting, and even a little Webpack and grunt; and
  • Git.

I feel like I’m just getting started. There is far more that I don’t know (and want to learn). And yet each time I write code that does something, it’s thrilling!

Along the way I’ve created projects that use what I’ve learned. They include little ones like this birthday site I created for our son when he turned 10, and bigger ones like Modiin Bus (currently being overhauled as I learn).

My coding journey has consumed me. There is always something to learn, code to improve, and projects to build. My personal writing and photography have taken a back seat (as you may have noticed). At the same time, I’ve gained so much in the process.

For one thing, learning to code opens the door to a whole new line of work for me. Rather than being limited to content marketing, I can explore web development roles too[1], and everything in between.

Mostly Househusband

One of the huge perks of my protracted job search is being home for most of the year. It’s almost given my wife and I an opportunity switch traditional roles.

She goes to work (as an awesome account manager at mySupermarket) and I take the kids to school, handle much of the housework[2], manage play-dates and after-school activities.

Being unemployed also made the annual school summer vacation (2 months!) so much easier to handle, logistically, because I was around to take and fetch from holiday camps, and be with the kids when they were just on vacation.

Although the challenges of my job search haven’t always been conducive to recognising the gifts of my current status, the experience of working from home all this time has highlighted what is most important to me.

Rather than never being around due to the demands of an intensive career that keeps me away from home, I’ve been around to watch our kids grow up over the last year.

It’s been a busy period, for sure. I am definitely not the type of person who’ll toss in a load of laundry and veg out till the kids come home. I’m constantly learning more code in between my freelance work, job search, and being here for our kids.

In the meantime, Gina’s career is blooming. She moved into a new account management role a few months ago and is awesome at it. I’m proud of her and of what she’s accomplished. If me being home has given her a little more space to do that, then this is yet another benefit.

So long, and thanks for all the .zsh

Of course, it didn’t escape me that there is something special about this birthday.

While I don’t have all the answers (not even remotely), perhaps being 42 brings a few answers to the questions that I haven’t been able to answer so far.

At the very least, I feel like I have a better grasp on what’s really important, and what isn’t. Regardless of where I may find myself working (hopefully soon), I am grateful for the opportunities I’ve had this year to learn, grow (a little), and be more present (mostly).

Ultimately, living in Israel (and in most of the world) generally means that both of us need to earn an income. So, my search continues. I love coding[3], I’ve had opportunities to interview at some of today’s most exciting companies, and there is still so much more to do.

I don’t know what lies ahead in 2018 but, as I keep reminding myself when I find myself slipping into Regretsville, we only really have the present moment. Sometimes, the moment we are in can be source of boundless opportunities.

It might even hold the answers we seek.


  1. Roughly half of my current job applications are for coding positions.  ↩
  2. Gina still does most of the cooking.  ↩
  3. Even when it frustrates me, when I suddenly can’t remember how to string a function together, or both.  ↩

Celebrating Women in Tech with the awesome #WITBragDay meme

Three women in technology collaborating with laptops

My favourite meme at the moment is the awesome #WITBragDay meme on Twitter that celebrates women in tech. It seems to have been started by Alice Goldfuss with her tweet:

The result is tweet after tweet of pure inspiration from women in the technology industry. I spent some time reading tweets this morning when I woke up and I found myself smiling because these stories are just awesome.

These women, and others like them, are the perfect response to the odious Damore memo. These stories are also the stories I want both our kids to know, especially our daughter. Heck, these stories inspire me as I learn to code. Here is a selection of some of my favourites:

I’ve created a Twitter Moment for the tweets I love the most. You can find that here too (it may be more complete and up to date):

Image credit: The #WOCinTech collection on Flickr, licensed CC BY 4.0

You can read more about the #WOCinTech project here too: “#WOCinTechChat – Promoting diversity in tech through stock photos