Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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 / README.md
Last active July 20, 2016 16:20 — forked from lsloan/urltidy.py
Python experiments in removing contiguous slashes from URLs. The `urlparse` module should do this.

This is the README file.

@lsloan
lsloan / stringContainsCharacters.py
Created July 26, 2016 20:22
Python: A couple of methods to check whether a string contains any or all of the characters from a second string.
def stringContainsAnyCharacters(string, characters):
"""
Check whether 'string' contains any characters from string 'characters'.
:param string: String to check for wanted characters
:type string: str
:param characters: String of characters to be found
:type characters: str
:return: True if any characters are found, False otherwise
:rtype: bool
@pudquick
pudquick / pip-mini.py
Last active October 23, 2016 03:44
Minimal version of pip in a standalone form for handling pure python situations (Pythonista, etc.)
# Standalone mini version of pip
# Geared towards Pythonista, but easily adaptable to other pure python installs
import argparse, copy, gzip, os, os.path, re, requests, shutil, site, sys, tarfile, time, xmlrpclib
# Where packages will end up installed
site_packages = site.USER_SITE
# Root of Pythonista saveable document location
pythonista_base = os.path.split(site_packages)[0]
# Temporary directory for work
@sloanlance
sloanlance / json_tool.py
Created November 2, 2016 18:19
Python: The json.tool included with Python. I copied it to note some changes I'd like to make. From: https://github.com/python/cpython/blob/master/Lib/json/tool.py
r"""Command-line tool to validate and pretty-print JSON
Usage::
$ echo '{"json":"obj"}' | python -m json.tool
{
"json": "obj"
}
$ echo '{ 1.2:3.4}' | python -m json.tool
Expecting property name enclosed in double quotes: line 1 column 3 (char 2)
@sloanlance
sloanlance / linux_set_time_ntp.md
Created November 10, 2016 20:50
Linux: Set the system time from an NTP server

If ntpdate is installed:

sudo ntpdate pool.ntp.org

To install ntpdate:

sudo apt-get install ntpdate # for Ubuntu-like
@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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# From http://nedbatchelder.com/blog/200712/human_sorting.html
import re
def tryint(s):
try:
return int(s)

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 my_name+extra_info@gmail.com 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 my_name+extra_info@gmail.com address is valid and the receiving mail server will deliver messages for that address to the user with the address
@sloanlance
sloanlance / Auto Text Expander preferences ℹ️👍😃
Last active January 11, 2017 15:54
Emoji: Emoji and other things that I like Auto Text Expander to fill in for me.
Preferences for Auto Text Expander ℹ️👍😃
@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 "${@}"