Blog

Asking for Help as a Developer

I think the Coding Blocks guys were the ones who reminded me of Scott Hanselman’s brilliant advice of not wasting keystrokes - don’t share advice with one person when many could benefit from it so I figured I’d post some advice I just shared with a friend. None of these are my original ideas, I’ve had to learn these same lessons from others over time.

Read More

Calling Applescript from Python and passing in Variables

For work I had to automate a piece of software - which was seemingly best done with Applescript - but I wanted to be able to call on the script from Python and also pass in some variables. py-applescript seemed to be the best package to interface with Applescript and has examples of how to either a) call an external Applescript or b) pass in arguments. The documentation was a little less clear on how to do both at the same time. I eventually got everything working with code similar to what is below. You send the path of the external script to the AppleScript class (?) as a keyword argument ("path=path_to_file.scpt") and the arguments to the run method (?).

Read More

VSCode Custom Keybindings

I was having trouble syncing my VSCode settings across different installations and it was caused, at least partially, by the fact that I forgot to add a comma between the first and second entries below. I thought I would share these, both to help others and to help future me. The first allows me to execute an open Python script by typing cmd and b. The next two allow me to uppercase or lowercase highlighted text by typing cmd, shift and u or l, depending on what I want to do. You can edit it within VSCode by clicking cmd, shift, p and searching for Shortcuts (JSON). The JSON is important because the other Keyboard Shortcuts is just a list of every keyboard shortcut built into VSCode. This code is stored in a file named keybindings.json in ~/Library/Application Support/Code/User on my Mac so you could probably edit it directly there, too.

Read More

Cron Test Script

I recently upgraded my MacOS version and my cron jobs stopped running. It ended up being a file access permission issue but in the process I realized I didn’t have a good method to test whether cron was running. All of my cron jobs are background processes so, in addition to having to change the times that they run, I’d also have to dig into my system to see if they ran successfully. I figured that someone else would’ve written a short script to test whether cron is running but a quick Google search came up empty. So here’s the basic Python script I came up with that I’m sharing in the hopes of saving others a few minutes time. This will create a directory in whichever folder you set in DESTINATION_FOLDER named with the current date and time as such - !cron_test_17-05-2021_12-48-41.

Read More

Virtual Environment Scripting in Bash

I'm riding a bit of an endorphin high - you know the one where you get some code to work and you're reminded of the power of what we're doing here, even if it's just some simple automation. I have [Brian Okken]("http://www.twitter.com/BrianOkken") to thank for tangentially opening my eyes to the world of bash scripting. He had made a comment a while back on the [Python Bytes]("https://pythonbytes.fm/") podcast about how he automated Python to upgrade PIP every time he created a new virtual environment. After my ~20th time doing it manually I figured I'd reach out to him on Twitter to see if he'd share and he generously did on [Twitter]("https://twitter.com/brianokken/status/1375237707312427015") and via a [GitHub gist]("https://gist.github.com/okken/d166d194e1cb024d88540e8f75ac4b98").
Read More

Install Python Packages from within an iPython Session

TIL that you can install python packages from within an iPython session by appending an ! to the front of your normal command. Say you’re 20 commands deep into a tutorial and the instructor neglected to mention that you’d need numpy, seaborn and matplotlib. Just enter….

Read More

Can't read /var/mail/tweetutilities

Just had a complete brain fart and am hoping I can save someone else from suffering the same. I’m following an O-Reilly tutorial about using the Twitter API and I’m running a simple from tweetutilities import print_tweet in the terminal. But the output - from: can't read /var/mail/tweetutilities is making absolutely no sense to me. Googling doesn’t turn anything meaningful up. I’ve never dealt with /var/mail before and while someone else wrote the tweetutilities.py file, neither a search in VSCode nor my own perusing of the file showed anything that would’ve called /var/mail.

Read More

Four Tidbits

Twitter can be a huge timesuck and is generally a negative place but I stick around for gems like these.

Read More

Publishing Corvid to GitHub Pages

My sister just went out on her own as a therapist in Eugene, Oregon and so I had to get a website set up for her - JenBeckLMFT.com. I was pleased to find out about Corvid, a static-site generator written in Python that was really stripped down and perfect for being able to turn a few markdown files into a basic ‘brochure’ website. Getting it to publish to GitHub Pages smoothly was a bit of a hurdle so hopefully this documentation will help someone else with getting a site set up with a bit more ease.

Read More

Screen Recording with FFMPEG

I’ve been toying with recording some coding sessions - like Advent of Code problems - and so needed to figure out a way to record my screen. I’ve been using ffmpeg for two other recent projects and suspected it was capable because it seems to be able to do everything. Getting it going was somewhat straightforward although getting it to output timestamped filenames (to avoid overwriting) took me a few hours to iron out. What I suspect will work for most people is the following.

Read More

Crontab Secret

I found myself wrestling with crontab again trying to get a python script to run unsuccessfully when the most basic concept hit me. It wasn’t working and I thought I was mis-configuring the numbers and asterisks, alternately setting it to run in a minute and then checking the log a minute later only to see that nothing had happened. I finally just ran the command directly in the terminal. That’s when I found out that the script wouldn’t run because a bunch of packages were missing. I had recently switched from running it on the default (Raspberry Pi) system python which was python 2 and I needed to install all those packages again on the python 3 installation I was now calling via crontab. BTW, this was the crontab command that finally worked (and would have been working the whole time if I had the packages installed). Also new to me, the >> /home/pi/pi-timelapse/log.txt portion of the commmand writes the normal terminal output - which is suppressed when running via crontab - to a log file. Bottom line, try running your full command (minus the *s and numbers [and logging]) from the terminal before getting mired by the crontab timing minutiae.

Read More

Removing Hidden Blog Post Links from Next Previous

I have a few posts on my (Jekyll) blog that aren’t related to tech that I have hidden from the main blog page (although they’re available by search or direct URL). There are several blog posts showing you how to accomplish that functionality so I won’t get into it. What I didn’t realize until recently was that they were still showing up in the Next / Previous links at the bottom of other posts. The blog posts that should be excluded have exclude: true within their front matter (header) so from there it was a matter of extending the same usage of unless from the main blog page to the code that linked to the Next / Previous posts.

Read More

Scraping Text between Two Tags with Beautiful Soup

Putting this here in case I need it in the future and because there wasn’t much information online about how to grab the text between two tags with BeautifulSoup and Python. I think it’s difficult to find a solution because most of the people who are searching for something similar can benefit from semantic/ nested HTML and just back up one layer and get children or next_sibling, etc.

Read More

Text Encoding TLDR

Here’s my probably wrong and definitely incomplete takeaway on text encoding. Instead of copy pasting decode / encode snippets from Stack Overflow I promise to get to the bottom of the encoding of the next text I scrape or import into Python.

Read More

Exit Python REPL (on Mac) with Control-D

Quick tip that I just learned (from a Pluralsight video) is that you can exit the Python REPL in Mac’s Terminal by pressing Control and D instead of having to type exit() and hit enter, which is a bit clumsier. Control and C halts any process that might be taking a while so I’m hoping it’ll be easy to remember Control + D for exiting the REPL.

Read More

Pyenv and Venv / Virtualenv wrapper settings

I’ve had a hell of a time wrapping my head around managing Python versions on my machine with pyenv, and individual project dependencies with venv (/ virtualenv) and an even harder time getting them to work on my (Mac) machine. The issue I had with pyenv was finally resolved when I just moved the declaration in my .bash_profile from the beginning of the file to the end. My favored way of editing it (with Nano) is done by invoking nano ~/.bash_profile in terminal, although I also discovered I could edit it directly in VSCode when I found the .bash_profile in my home (Scott in my case) folder (I think you have to unhide hidden files, which hides all system/ dotfiles by default). I don’t exactly understand what is happening in the code below but the reason it needs to be toward the end of .bash_profile is that pyenv apparently intercepts and redirects PATH listings you may have earlier in the file.

Read More

Storing JSON 'File' in Heroku Config Vars

It seems like a problem ripe for <vomet>disruption</vomet> but for a junior dev who still doesn’t know best practices around storing private API keys I think I came up with a clever workaround for this particular thorny situation. The problem is that I was trying to deploy to Heroku a (Flask / Python site) that writes to a Google Sheet and therefore needs OAuth authentication. Heroku has “Config Vars” in which you can store a private key as a string that won’t be accessible to the public and you can keep out of your Git/ GitHub/ source control. The problem in this case is that OAuth gives you a JSON file of about 8 values, at least two of which are needed for authentication, if not more. The solution seemed obvious - to store that JSON as text in a Config Var but implementation proved anything but easy for me. After more than a day of fiddling, I think I finally have it working.

Read More

Nuxt - Google Lighthouse - noopener Breaking Links

I ran Google Lighthouse on a Nuxt site that I built and implemented their performance tuning and accessibility hints and was actually able to get 100% scores across the board (Woohoo!). It wasn’t until the next day that I realized that I had crippled all of the external links that I had on the site opening in a new tab (with target="_blank"). Lighthouse recommends always adding rel="noopener" or rel="noreferrer" to prevent the new website from manipulating the redirect elsewhere. I dutifully searched through all my site files (thanks VSCode) for target="_blank" and replaced it with target="_blank" rel="noopener". It turns out that was the problem and when I went back and did the same operation replacing all the rel="noopener" with rel="noreferrer", everything seems to be working again.

Read More

Jekyll CSS Not Rendering

I had a problem with this here Jekyll install/ blog in that I couldn’t get the CSS to render and nearly abandoned Jekyll because it was the third major issue I’d encountered in the few short weeks of trying to get it going. Thankfully a guy named Gungor on the Jekyll Gitter forum pointed out to me that my css was being served at http while my site was at https (It’s possible that I have those reversed). I spent the next three hours trying to figure out what I needed to change and, after trying every iteration of http/s in the url and baseurl variables in my _config.yml file, I finally commented them both out and it suddenly worked. I wish I could explain why but if you’re running Jekyll on GitHub Pages with a custom domain see if that doesn’t fix your problem.

Read More

Linking to a PDF (CV / Resume) from your Jekyll Header / Nav

This seems like the most basic task but I finally had to resort to writing every link structure combination I could conceive of (~10, in all) and copy my Resume.pdf file into multiple folders to figure out how to do this. In the end I put my Resume.pdf file in a folder titled static in my home folder. From there I added a link to the header.html file amongst the list of other navigation links as follows. The key part is that it have a leading forward slash after the baseurl - ”{{ site.baseurl }}/static/Resume.pdf”

Read More

index.md not building into index.html on a Jekyll Site

I had an issue setting up this Jekyll site/ blog where I wanted to replace the default blog page that was at index.html with the about page and have the listing of abreviated blog entries on a separate page that you have to click through to from the home page. I swapped the default Jekyll about.md and index.html files for index.md and blog.html, respectively. The problem was that the index.md wouldn’t build into an index.html as it should. I’m not sure of the exact problem but it was all in the header markdown that you see at the top of every markdown page. I think it was that I didn’t change the titles of the pages to reflect the changes in the filenames and there was a naming conflict. Anyway, after revisiting them index.html is being properly built from index.md.

Read More