iOS shortcut to convert the contents of a tweet to Markdown

I often find myself wanting to grab the contents of a tweet in Markdown format to post on my blog, so I’ve created an iOS shortcut that takes the URL to a tweet, grabs the contents via the public Twitter API, expands t.co URLs, and copies the content to the clipboard.

Here’s an example tweet:

And here’s what the output of the Shortcut looks like:

Storing and retrieving passwords in bash scripts from the macOS keychain

It's often convenient to store a password in the macOS system keychain and retrieve it inside a shell script.

Here's the bash command for setting a password:

security add-generic-password -s "Keychain item name here" -a "username here" -p

Then enter your password when prompted.

After you run this once, you can retrieve the password in a script like this:

PASSWORD=`security find-generic-password -s "Keychain item name here" -a "username here" -w`

You can then use $PASSWORD whenever you need the password in your script.

Backing up OneNote notebooks

By default, OneNote stores notebooks on OneDrive in a “Documents/“ folder. But the notebooks are not downloaded locally by the OneDrive sync client — the sync client simply downloads “.url” link files that take you to the notebook on onenote.com.

However, there is an easy way to grab a backup. Use the “Download” option on onedrive.com to download a .zip file of the entire “Documents/“ folder. This .zip will have all your notebooks in the open, documented OneNote file format.


Update (November 7, 2019): Thanks to David Mytton for pointing out that this only works for personal Office365 accounts. If you have a business account, OneDrive will store your OneNote notebooks in a "Notebooks/" folder rather than a "Documents/" folder, and it will not let you download this folder. This is a known issue and Microsoft is working to resolve it.

Using Pipenv with R Markdown and reticulate

R Markdown is very nice way to write literate R code. Recently, reticulate became available, which bridges R and Python in R Markdown documents.

If you use Pipenv for Python dependency management, here's how you get reticulate to use the proper Python executable:

library('reticulate')
venv <- system("pipenv --venv", inter = TRUE)
use_virtualenv(venv, required = TRUE)
py_config()

The py_config() command should print out the path to the Python executable in the virtualenv created by Pipenv.

Ruby: Using Bundler Without a Gemfile

A very handy tip from Victor Afanasev:

Did you know that you can use Bundler inside single Ruby script (without Gemfile) and automatically install required dependencies for it?

# example.rb

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'rest-client'
  gem 'nokogiri'
end

###

body = RestClient.get("https://www.reddit.com/r/ruby/").body

puts "Posts from r/ruby front page:"
Nokogiri::HTML(body).xpath("//div[contains(@class, 'scrollerItem')]//h2").each do |h2|
  puts h2.text.strip
end