This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* When using the equal comparison operator ("==") to compare a number with a string or | |
* the comparison involves numeric strings, each string is converted to a number and the | |
* comparison performed numerically. These rules also apply to the switch statement. The | |
* type conversion does not take place when using the identical comparison operator | |
* ("===") as that involves comparing the type as well as the value. | |
* | |
* It's safer to always use strcmp() or the identical comparison operator ("===") for | |
* string comparisons. |
An example of configuring Vim to support Markdown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import requests | |
OUTPUT_FILE = 'get-pip.py' | |
URL = 'https://bootstrap.pypa.io/' + OUTPUT_FILE | |
file(OUTPUT_FILE, 'w').writelines(requests.get(URL)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
NOW=$(date -u +"%Y-%m-%dT%H:%M:%SZ") # ISO 8601 format, UTC | |
CURL_STDIN='@-' # cURL's notation for stdin | |
curl "https://endpoint.example.org/caliper" \ | |
--request POST \ | |
--header "Content-Type: application/json" \ | |
--capath /etc/pki/tls/certs/ \ | |
--data ${CURL_STDIN} << EOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -- | |
function hash_hmac { | |
digest="$1" | |
data="$2" | |
key="$3" | |
shift 3 | |
echo -n "$data" | openssl dgst "-$digest" -hmac "$key" "$@" | |
} |
When I develop with Python, I like to use its interactive interpreter to experiment with code samples quickly and in real time. It allows me to import the code I've been developing so I can test it in a controlled environment. Java doesn't include this ability outnatively, but there are a number of ways to accomplish something similar with additional software. With my preference for Python, I chose Jython to do this.
- Install Jython. See jython.org for details. It may be as simple as, for example, on OS X with Homebrew:
brew install jython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Experiments in removing contiguous slashes in URLs. | |
Why doesn't urlparse do this for us? | |
""" | |
import posixpath | |
import re | |
import urlparse | |
apiBaseURL = 'http://example.org//api/v1/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get(self, apiQueryURI, params=None, **kwargs): | |
""" | |
Append the specified query URI to the base URL, which is then sent to the REST API. | |
Results are returned as a requests.Response object. | |
:param apiQueryURI: URI for the query, to be appended to the base URL | |
:type apiQueryURI: str | |
:return: requests.Response | |
:rtype: requests.Response | |
""" |