An introduction to curl
using GitHub's API.
Makes a basic GET request to the specifed URI
curl https://api.github.com/users/caspyin
""" | |
If your sock drawer has 6 black socks, 4 brown socks, 8 white socks, and 2 tan socks, how many socks would you have to pull out in the dark to be sure you had a matching pair? | |
""" | |
# Data | |
collection = { | |
'black': 6, | |
'brown': 4, | |
'white': 8, |
An introduction to curl
using GitHub's API.
Makes a basic GET request to the specifed URI
curl https://api.github.com/users/caspyin
{ | |
"name": "base-policy", | |
"version": 1.0, | |
"type": "dummy", | |
"compatible": [4.0, 4.1, 4.2, 4.3], | |
"customer": "XYZ - Client", | |
"data": [ | |
{ | |
"name": "test-name-1", | |
"value": "test-val-1" |
import httplib | |
import base64 | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
config = {"username": "your-sauce-username", | |
"access-key": "your-sauce-api-key"} |
# import config. | |
# You can change the default config with `make cnf="config_special.env" build` | |
cnf ?= config.env | |
include $(cnf) | |
export $(shell sed 's/=.*//' $(cnf)) | |
# import deploy config | |
# You can change the default deploy config with `make cnf="deploy_special.env" release` | |
dpl ?= deploy.env | |
include $(dpl) |
import requests | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
URL = "https://www.somesitewithbadssl.com" | |
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0","Connection":"close","Accept-Language":"en-US,en;q=0.5","Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Upgrade-Insecure-Requests":"1"} | |
response = session.get(URL, headers=headers, timeout=15, verify=False) | |
result = response.text | |
print (result) |
import asyncio | |
loop = asyncio.get_event_loop() | |
async def hello(): | |
await asyncio.sleep(3) | |
print('Hello!') | |
if __name__ == '__main__': | |
loop.run_until_complete(hello()) | |
import time | |
from functools import wraps | |
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logger=None): | |
"""Retry calling the decorated function using an exponential backoff. | |
http://www.saltycrane.com/blog/2009/11/trying-out-retry-decorator-python/ | |
original from: http://wiki.python.org/moin/PythonDecoratorLibrary#Retry |