The built-in Abbrev
module can calculate a set of unambiguous abbreviations for a set of strings, and then you can look for the shortest result for each string.
author_name
in the list of tags on a Flickr photo? When you call the flickr.photos.getInfo
API, each tag is attributed to an author. The author_name
is their username, not their realname.
The flickr.profile.getProfile
API returns somebody’s email address, but only if you’re allowed to see it.
Using a repeating-linear-gradient
as the border
gets you something that looks a bit like hazard tape.
hyperlink.parse
? Mostly you get hyperlink.URLParseError
, but you can occasionally get a ValueError
as well.
There’s a lot of whitespace in HTML which looks irrelevant at first glance, but may be significant and cause the document to render differently.
ispublic
, isfriend
and isfamily
flags work in the Flickr API? std::io::IsTerminal
to detect if you’re running in the terminal in Rust This allows me to suppress ANSI escape codes if the output is going somewhere other than the terminal.
$_
to get the last argument to the previous bash command This allows you to write commands like mkdir myfolder && cd $_
or git init myrepo && cd $_
.
current_user == None
, not current_user is None
current_user
is a proxy object that happens to be wrapping None
, but isn’t actually None
.
Open the file with mode r+
to be able to seek around the file and write to it.
Use the command eyeD3 [MP3_FILE] --write-images [FOLDER]
.
A combination of --get
and --data
/--data-urlencode
allows you to write curl commands which are readable and expressive.
Using -trim
will remove the black portions and leave you the unletterboxed image.
Using an NWPathMonitor
and inspecting the value of NWPath.status
, NWPath.isExpensive
and NWPath.isConstrained
can tell you what sort of connection you’re running on.
Adding a couple of options to the console
lexer (console?lang=python&prompt=>>>
) gets you syntax highlighting for a Python console session.
[Errno 54] Connection reset by peer
when using pytest You can run a TCP server in the background using a fixture, and using the SO_LINGER
socket option can reset the connection.
Disabling JavaScript when you open the webarchive file will prevent you from redirecting you to twitter.com.
Adding .withoutOverwriting
to your write()
call will prevent you from overwriting a file that already exists.
The inside of a .webarchive
file is a binary property list with the complete responses and some request metadata.
Wrapping a Palette:Srgb
in a struct and implementing FromStr
for the struct allows you to take hexadecimal colours as command-line inputs.
You can do some fun stuff with the --write-out
flag and variables.
The song Seasons of Love from Rent starts with the line “Five hundred twenty-five thousand, six hundred minutes”.
Using a nested query allows me to perform a two-level aggregation of the values in a column – how many values appear once, how many twice, and so on.
Use the CDX Server API to get a list of captures for a particular URL.
Using Playwright to take screenshots and adding some custom styles gets a screenshot of a page without the Wayback Machine overlay.
Using the During
filter gives me a count of how many messages were being sent.
To see exactly what HTTP requests were being made, I modified the library so that betamax would record requests.
Modern browsers allow you to embed the SVG almost as-is, with just a couple of characters that need escaping – no base64 required!
If you want an array in random order, you can use the sample
filter to get a random sample of the same size as the original array.
When you make an HTTP request, you can use the If-Modified-Since
header to get a 304 Not Modified if nothing has changed since your last request.
open
command can ask questions If you pass an argument that can’t be easily identified as a file or a URL, open
will ask you what to do next. This may be a surprise if you were trying to use it in a script.
Images can have orientation specified in their EXIF metadata, which isn’t preserved when you open and save an image with Pillow.
Escaping the pipe like [[filename\|display text]]
allows you to customise the of a link in a table.
Why I use Sessions in boto3, and the Python function I use to create them.
The flags and arguments I find useful when I’m using youtube-dl.
-n
/-i
flags to avoid overwriting files with cp
and mv
errexit
and arithmetic expressions in bash tmutil addexclusion
resp.close()
to close the file opened by send_file()
-v
flag to see what rm
is deleting You can use app.error_handler
to add custom responses for HTTP status codes, so the errors match the look and feel of the rest of the site.
{% raw %}
tag to describe Liquid in Liquid If you’re trying to write about using Liquid tags in a Liquid-based site, wrapping your tags in the {% raw %}
tag will prevent them being rendered.
test -n
with command expansion MaxMind offer databases you can do to look up IP addresses without sending the address off to a remote service.
{% capture %}
tag to assign complex strings to variables If you want to get a string that’s semi-complicated to construct, you can put a “mini-template” in the {% capture %}
tag to build it over multiple lines.
appendChild()
<details>
element differently depending on whether it’s open or closed cp
or mv
a file to it "do JavaScript"
<img>
that points to another file By reading the code for the pytest-random-order
plugin, I was able to write a new plugin that runs a random subset of tests.
You can use sqlite-utils on the command line to create a SQLite database from a CSV file.
The sqlite3.connect(…)
context manager will hold connections open, so you need to remember to close it manually or write your own context manager.
Calling browser.set_ca_data(cafile=certifi.where())
will tell where mechanize can find some local SSL certificates.
The XML-to-JSON conversion leads to some inconsistent behaviour, especially in corner cases of the API.
Following the logged-out 302 Redirect takes you to the original post.
You can use Srgb::from_str()
to parse a hexadecimal string as a colour in the palette crate.
git check-ignore
to debug your .gitignore
Running git check-ignore --verbose <PATH>
will tell you which rule applies to a given path, and where that rule is defined.
They were deliberately non-sequential as an anti-spam technique. It’s no longer required, but it’s in the codebase now and hasn’t been changed since it was written.
gem install
--force-with-lease
is safer than with --force
It checks the remote state of the origin hasn’t changed since you last fetched, so you don’t risk overwriting anybody else’s commits.
Calling json.dumps(…, separators=(',', ':'))
will reduce the amount of whitespace in the final string.
If you add /podcast
to a Tumblr site, you get a podcast-like RSS feed for all the external audio posts on that site.