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
@pierrejoubert73
pierrejoubert73 / markdown-details-collapsible.md
Last active May 29, 2025 16:34
How to add a collapsible section in markdown.

How to add a collapsible section in markdown

1. Example

Click me

Heading

  1. Foo
  2. Bar
    • Baz
  • Qux
@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 / 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 / disable_macOS_parental_controls.sh
Last active September 7, 2021 16:00
Disable Parental Controls and other services in macOS Sierra (OS X)
#!/bin/bash
# This is a draft but it works
# FIRST (I don't even know if it works but we'll assume yes)
# sudo launchctl list
# sudo launchctl disable system/netbiosd
# sudo launchctl disable system/parsecd
# sudo launchctl disable system/parentalcontrols.check
# sudo launchctl disable system/airportd
Gist title: XSLT for JSON
Summary: In response to a Stack Overflow question about an XSLT equivalent for processing JSON,
I posted an answer (http://stackoverflow.com/a/34910682/543738) suggesting DefiantJS. Also, a
JSFiddle version (https://jsfiddle.net/lsloan/8dt9egjf/).

Valid Email Addresses

Many websites attempt to validate email addresses based on formatting rules alone. Often, they use regular expressions which may turn out to be wrong, which is difficult to notice due to their complexity. Attempting to do very much validation of email addresses is usually a mistake and should be avoided.

The most common problem I've seen personally, from the perspective of a website user, is that email addresses containing a plus-sign (+) are considered invalid. For example, an email address like [email protected] is often rejected as invalid. However, that conclusion is incorrect.

  • According to RFC 3696 from the IETF, + is a valid character for the "local part" (the part before the @ sign).
  • According to RFC 5233, the [email protected] address is valid and the receiving mail server will deliver messages for that address to the user with the address
@sloanlance
sloanlance / BASH: ISO 8601 Timestamp with Milliseconds
Last active May 6, 2024 14:40
How to get an ISO 8601 timestamp with milliseconds in BASH
Gist title: "BASH: ISO 8601 Timestamp with Milliseconds"
Summary: How to get an ISO 8601 timestamp with milliseconds in BASH
#!/usr/bin/python
# -*- coding: utf-8 -*-
# From http://nedbatchelder.com/blog/200712/human_sorting.html
import re
def tryint(s):
try:
return int(s)
@sloanlance
sloanlance / Example of GitHub's geoJSON support
Last active December 5, 2016 16:43
geoJSON: An example of a geoJSON file which outlines and labels many countries. It will be rendered with a map viewer in GitHub. Other features, such as cities and regions within countries, may be added by the map viewer. For more info, see: https://help.github.com/articles/mapping-geojson-files-on-github/
Example of GitHub's geoJSON support