Skip to content

Instantly share code, notes, and snippets.

View sloanlance's full-sized avatar
Certified GitHub Pro

Mr. Lance E Sloan sloanlance

Certified GitHub Pro
View GitHub Profile
@sloanlance
sloanlance / Python utilities.md
Created June 28, 2017 15:30
Python: A document of ready to use utilities included in Python's standard modules

Python's Built-in Utilities

List of command line accessible tools built into the Python standard library.

Encoding and decoding

Base64 en/decoding:

python -m base64 -d [file]

python -m base64 -e [file]

@sloanlance
sloanlance / quopri.sh
Created June 28, 2017 14:57
Python: quopri - Wrapper script for quopri module to encode or decode MIME quoted-printable data
#!/bin/sh --
# This script is easier to use when in a file named "quopri" without the extension.
# The ".sh" extension is helpful for syntax highlighting in GitHub and editors.
# For use, it's recommended to either remove the ".sh" from the filename or make a
# symbolic link to it named "quopri".
# For more information about quopri, see: https://docs.python.org/library/quopri.html
python -mquopri "${@}"
@sloanlance
sloanlance / pythonanywhere gists.md
Last active February 15, 2023 11:20 — forked from pythonanywhere/extra_functions.py
PythonAnywhere Gist DemoBot
@sloanlance
sloanlance / heredoc_json.bash
Created May 2, 2017 16:29 — forked from kdabir/heredoc_json.bash
json in heredoc in bash script alongwith variable substitution
_BUCKET_NAME="foo.example.com"
_POLICY=$(cat <<EOT
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadForGetBucketObjects",
"Effect":"Allow",
"Principal": "*",
"Action":["s3:GetObject"],
@sloanlance
sloanlance / guzzle.md
Created March 2, 2017 18:13
PHP: Guzzle as replacement for direct use of Curl or PECL HTTP modules.

Copied from: https://github.com/IMSGlobal/caliper-php/issues/126#issuecomment-226624750

I've recently learned that Guzzle is a popular HTTP client library for PHP: http://guzzlephp.org/

This package has a lot of nice features, including:

  • Simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data, etc...
  • Can send both synchronous and asynchronous requests using the same interface.
  • Uses PSR-7 interfaces for requests, responses, and streams. This allows you
@sloanlance
sloanlance / thedeletionist_com.js
Last active February 21, 2017 18:52
JavaScript | Formatted source of The Deletionist bookmarklet from: http://thedeletionist.com/ | See examples of the output at: https://twitter.com/TheDeletionist
/*
* Formatted source of The Deletionist bookmarklet from: http://thedeletionist.com/
* See examples of the output at: https://twitter.com/TheDeletionist
*/
// javascript:
(function () {
console.log('*****************');
console.log('The Deletionist, by Amaranth Borsuk, Jesper Juul, and Nick Montfort. 2013-07-09. http://thedeletionist.com');
var Rule = function (name, regex, target) {
@sloanlance
sloanlance / nc-netcat_web_request_monitor.md
Last active May 17, 2021 16:46
BASH: Simple web request monitor using `nc` (AKA `netcat`)

While working on a project that produces JSON and sends it to a server using an HTTP POST request, I found it sometimes inconvenient to start the server every time I needed it. Most of the time, unless I was working on the server code itself, I just wanted to see the raw request data. I learned that the nc utility (AKA netcat) could do just that.

However, using nc the way others explained it didn't work well for my purposes. It turns out that it shouldn't be run in the background, as was suggested, and it should give a proper HTTP response to satisfy the client. I came up with this solution:

while [[ 1 ]]; do printf 'HTTP/1.1 200 OK\n\n' | nc -l 127.0.0.1 8000; printf '\n\n= = = = = %s = = = = =\n\n' "$(date)"; done

It's helpful to run this in a shell in a separate window. As new requests are received, they will be seen scrolling up the display.

@sloanlance
sloanlance / Pythonista_OpenOtherApp.md
Last active June 25, 2021 14:47
Pythonista: Opening other apps from the application extension (iOS sharing mechanism)

In older versions of iOS, a Pythonista program run from the application extension (iOS sharing mechanism) could open other applications using code like:

import webbrowser
webbrowser.open('googlechrome://example.com/')

Where googlechrome (and googlechromes for secure connections) is a special URL scheme registered by the Google Chrome application. Some other applications have their own schemes.

However, that doesn't work in more recent versions of iOS (at least version 9.3.5 and newer; older versions may be affected, too). That code will open Google Chrome if the program is run from the Pythonista UI, but not if it's run from a sharing request.

@sloanlance
sloanlance / Clear terminal and scrollback.md
Created February 8, 2017 16:08
Clear terminal and scrollback

I'd recently expected the clear-like command from a commandline PHP program to clear the screen and scrollback buffer, like Command-K does in iTerm. It didn't clear the scrollback, though. So I tried the ANSI or DEC vt100 escape sequence Esc[2J. That didn't help either. The clearing wasn't important, though, searching for it was taking too much time, so I gave up on it. (Looking back, I probably could have found some iTerm documentation on the codes.)

I recently came across a solution for something else entirely, and it used the sequence Esc[3J. It cleared the scrollback, too. I wanted to know which other parameters could be used in the Esc[ₓJ sequence (which is called "erase in display" or "ED"), so I found these resources:

A

@sloanlance
sloanlance / macOS Time Machine progress.md
Created February 8, 2017 15:24
macOS Time Machine progress