Restarting Python SimpleHTTPServer on file system changes
I have a little static site generator that I made for my own uses. When I'm ready with my changes, I run a test command that uses Python's SimpleHTTPServer to serve the built, public folder so I can make sure it all looks good before I rsync it to my remote server.
I wanted to run some custom build code every time one of the files changed, and I wanted that hidden behind a single command. Using watchdog seemed like an easy enough solution, but running the server was an issue, since the SimpleHTTPServer included with python will block the main thread as soon as you start it. Thankfully, you can just toss it in its own process and go about your day. I ended up with something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
def dev_command(): from watchdog.observers import Observer from watchdog.events import FileSystemEventHandler from multiprocessing import Process from http.server import HTTPServer, SimpleHTTPRequestHandler def create_server(): httpd = HTTPServer(('', 8000), SimpleHTTPRequestHandler) httpd.serve_forever() class Rebuilder(FileSystemEventHandler): p = None def stop_server(self): if self.p: print("Stopping server") self.p.terminate() def rebuild(self): # run all your rebuild commands def start_server(self): if self.p: self.stop_server() print("Starting Server") self.p = Process(target=create_server) self.p.start() def on_modified(self, event): if self.should_rebuild(event): print("Rebuilding") self.rebuild() def should_rebuild(self, event): """Include code to make sure you only rebuild on events you care about. Or you could implement watchdog's RegexMatchingEventHandler""" return True rebuilder = Rebuilder() rebuilder.start_server() observer = Observer() observer.schedule(rebuilder, "/path/to/watch/", recursive=True) observer.start() try: while True: time.sleep(1) except KeyboardInterrupt: observer.stop() observer.join()
Thinkpad X1 Gen 7 with Ubuntu, Windows Dual Boot and Disk Encryption
I recently set up a Thinkpad X1 Gen 7. I wanted disk encryption and to retain the Windows installation in case I ever needed it in the future. I was a bit nervous because there are some stories of people needing to fight with their settings and configuration and unfortunately the Ubuntu installer gives you pathways for either dual booting or encryption, but not both. Luckily I found a fairly good write up and things went smoothly. Since the write up focuses on a Dell machine, I thought I could allay some fears with a few notes on how things went for me. For the most part, I just followed the instructions and everything worked out.
Mike's tutorial shows a few BIOS settings to be made. I didn't make any changes to my bios. The settings were either alread correct, or I couldn't find one that applied. Mike mentions that he disabled Secure Boot, but that it may be optional. I did not disable this.
The only difference here is that my device was not
/dev/nvme0n1. One thing to be careful with is that you need to replace all the occurences in this tutorial careful. In some places, he mentions partitions not devices. In these cases you will have a corresponding numbered partition. For example one line in the configuation is
mkfs.fat -F 32 /dev/sda1, in this case I needed to enter
mkfs.fat -F 32 /dev/nvme0n1p1.
Two small tips. When you eneable bitlocker, actually save the key to a location off the computer. This seems obvious, but I'm not familiar with Windows and in a first attempt I just stored it on the Window's hardrive thinking I would get it later. But no, I needed it later and I didn't have access to it.
After the Windows install I was not able to access my BIOS with F12. To fix thisyou need to go into your Settings > Recovery > Advanced Startup "Restart now". When the computer restarts, select Troubleshoot > Advanced options > UEFI Firmware Settings > Restart. Check out this laptopmag.com article for screenshots.
This part was pretty straightforward. During the install process I did not select to install the third-party packages because this forces you to make a decision about using secure boot and I figured it was better to not introduce that variable.
Make sure you're very careful translating the commands in the tutorial to refer to your disk / partition layout.
Everything went smoothly. Don't become discouraged if you select windows from the Grub boot menu and get failure message. You need to boot Windows from your BIOS's boot menu. I will re-iterate Mike's note here:
"By default, your computer will boot into grub, which can boot Ubuntu. Although Windows is listed in grub, booting Windows from grub with BitLocker enabled won’t work because the system’s TPM will detect a change in the boot sequence. To avoid this problem, you should boot Windows directly from your computer’s BIOS boot menu - usually accessible by pressing F12 on startup."
I missed this the first time around and ended up installing everything again.
Amazingly, everything I have tried in Ubuntu has worked perfectly:
- Bluetooth ✓
- Wifi ✓
- Sound ✓
- Webcam ✓
- Trackpoint ✓
- Trackpad ✓
- Function Keys ✓
- Webcam ✓
- Fingerprint scanner ✓
- Microphone ✓
- Sleep / Wake ✓
I have the UHD option and the screen looks great and there are plenty of options for scaling.
Maintaining a Reading List with Vim and Open Library
I tend to accrue about 10-30 book recommendations a year, mostly from articles or comments I read online. I paste them in a plain markdown file within a vimwiki that I sync to github. Generally I'll either have a title and author, or a url to the publisher's website, Amazon, Goodreads or some other site.
When I have a list of urls, its often hard to pick out the title. And when I'm scrolling through looking for a book to read sometimes I want to know how many pages it is so I know what I'm getting into. Using vim filters, a python script and open library I can easily replace these pasted in entries with these extra details.
As shown above, the flow is: Use visual mode to select some books I've pasted in and use a vim filter command (!bookup) with a script that opens those urls, extracts some data and uses open library to fill in the rest. After a short wait, it overwrites them, formatted as markdown table rows.
If I find new domains, I can add a new "extractor" in a few minutes. If the script encounters something it can't find, it moves it to the bottom and outputs it in its original form.
If I don't have vim handy when I find a new recommendation, I can drop it directly into github using the github editor, or into a note app on my phone that works like a queue to get things into more permanant places. Then I can use this tool to convert them next time I'm editing in vim.
How to Write and Update Email and Why
At some point in your career you'll find yourself in charge of something. It might be a team or a project or a problem, but it will be something that other people care about. As soon as you find yourself in this position the best thing you can do is start writing a recurring update email. By this I mean an email about this thing—a team, a project, a problem—that gets sent at some predictable frequency to people who care. It should let them know what has changed, what challenges have arisen, what you've accomplished and what is coming next.
Nothing you do will have so many rewards with so little work.
Why to Write
Sponsor Your Colleagues
A few years ago someone asked me to look at a buggy system that had been bad enough issues that it was getting attention from the CTO. They paired me with one of the best, and most under-leveled, engineers I've ever worked with. He started methodically working through the problem, making much more progress than I was. People wanted to be kept up to date with the issue, which meant I had a good reason to email the CTO every week. The emails I wrote turned into an ode to the works of this under-leveled engineer. Each week I wrote about the amazing work he had done in solving the issue. It ended up being one of the most fulfilling things I've done in my career.
Build An Audience
If you write a great update email, something funny happens: people read it. And then more people start reading it. They'll actually ask you to add them to it. Soon, you have a way of reaching a wide variety of people and controlling a message. With almost no extra work, you have achieved influence.
A Repeating A Message
If you say something once, you haven't said it at all. Communication requires repetition. The medium of a weekly email is one that allows you to build themes and repeat the same thing over and over in different ways until people get it. You can't do that in a one off message.
People Will Want to Appear In It
Your weekly email should be highlighting all the things you team is doing. They know people are reading it. Their managers are probably reading it. They know its going to go out this week and they'll actually start to understand that their work is visible and therefore meaningful. They'll want to do more and more.
Regular Communication Makes Communicating Changes Easy
If you tell someone you're going to do something within six weeks and then on day forty-one you tell them its not going to be done, you've probably surprised them (in a bad way).
If you tell someone you're gong to do something within six weeks and each week you let them know where you are, they won't care at all when you end up needing eight or nine. They adjusted for that weeks ago.
It Forces You to Be Up to Date
Every week you know you have to write this email. Thea means you have to keep up things. This doesn't mean micro-managing and snooping, but it means building up some habits that let you figure this out from the ambient information.
At times you'll find yourself thinking, I have no idea what Judy is working on. And you'll realize you haven't been following along or paying enough attention. And because you want to sponsor her and provide good information, you'll fix that.
You Can Delegate It
If you are going on vacation you can find a teammate to take over. This gives them an opportunity to shift into a new role, one where they'll have to pay attention to things they may have been ignoring. They also get a chance to put their own spin on things and push their own side of the story. It can be a good opportunity for someone looking for new skills.
Keep People From Meddling
A weekly email removes anxiety from Stakeholders. They won't get nervous that things aren't getting done because they haven't heard anything. They'll know that things are moving along and they'll be reluctant to disrupt that.
How to Write
To write a great update email, there are a few things to keep in mind.
Use a Consistent Subject Line so People Can Filter Them
Something like "[Team Update] 2020-02-01" will do. You can add summary to the subject if you wish, just make sure there is something in the subject that people can build a mail filter rule out of.
Use Basic Typography
Don't go nuts on colors and layout, but definitely rely on basic typographical elements to help scan-ability. Headers, bold, italics, lists, paragraph text. That should be all you need. Build a language by using them consistently. Try to draw attention to people with emphasized text so they can scan.
All The Rules of Writing on the Web Apply
- Almost Everything
- A List
Keep things as short as possible. Link out for any details. Use lists as much as possible. People don't read long paragraphs.
Use Emoji Sparingly
Emojis are great to draw attention to things. Try to stick to a library of around 3-5 and use them consistently. For instance, if something launches, you always use a :tada:. If something is at risk and you need help, maybe an exclamation point emoji. People will learn that language and it will help them scan for information.
In this context, gifs are the opposite of communication. Your recipients will look at the GIF and nothing else. They'll say to themselves, ugh, this gif is so stupid.
Also there's nothing sadder than someone looking for the perfect gif on a Friday afternoon.
Give yourself some window in which to write your update every week and make sure you always do it. People are bewitched by uninterrupted consistency and they will attribute you with abilities far greater than you actually possess just because you never skip one. If you need to, delegate it out.
Introduce New Topics
When a new project or theme pops up, use a little extra space to introduce it properly without forcing someone to click away. The next week continue to do some exposition on it. Then as people are familiar with it, start to simply refer to it and link to documentation or past emails. This will keep the email short bit give people a way to get background if they need it.
Don't Turn it Into a Form
I know you're already thinking this, and you should just stop: Don't ask people on your team to email you updates or fill out a form with their updates for the week. That misses the point: you're not really paying attention to things if you need that and you're taking valuable time away from people. Instead, make sure you're staying on top of things. That might mean reading Slack, running
git log, making notes in meetings and 1-on-1's, checking your issue tracker or (sparingly) asking someone for an update directly. It sounds hard, but with a little practice you'll be able to figure out how to do this without bothering anyone.
There is a correlary to this: let your teammates know they can always push things to you if they think you'll miss them. You'll never know everything that's going on and people can feel forgotten if you miss something they thought was important.
Here's a quick script I've been using when I want to take on a task, but I don't want to lose track of time.
./timeb 10 figure out why this error happens sometimes
In the above example, the UI OS will show a notification in 10 minutes.
It works with Ubuntu and Mac.
It also logs out the tasks and time stamps to my home folder. I feel like that might be interesting to have, but I haven't done anything with it yet.