Skip to content

Instantly share code, notes, and snippets.

# python3 test_grequests.py
2019-04-14 23:30:41,697 START
2019-04-14 23:30:41,721 Starting new HTTPS connection (1): localhost:8082
2019-04-14 23:30:41,722 Starting new HTTPS connection (1): localhost:8082
2019-04-14 23:30:41,723 Starting new HTTPS connection (1): localhost:8082
2019-04-14 23:30:41,724 Starting new HTTPS connection (1): localhost:8082
2019-04-14 23:30:41,725 Starting new HTTPS connection (1): localhost:8082
2019-04-14 23:30:41,726 Starting new HTTPS connection (1): localhost:8082
2019-04-14 23:30:41,727 Starting new HTTPS connection (1): localhost:8082
#!/usr/bin/env python
from __future__ import print_function
import gevent_openssl
gevent_openssl.monkey_patch()
import grequests
import logging
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
#!/bin/bash
cn='example.com'
host="0.0.0.0"
port=8082
openssl genrsa -out /tmp/$cn.key 2048
openssl req -new -x509 -sha256 -key /tmp/$cn.key -out /tmp/$cn.crt -days 3650 \
-subj "/CN=$cn\/emailAddress=admin@$cn/C=US/ST=Ohio/L=Columbus/O=Widgets Inc/OU=Some Unit"
docker run --rm -e HTTPS_CERT_FILE='/tmp/example.com.crt' -e HTTPS_KEY_FILE='/tmp/example.com.key' -e PORT=$port -p $port:$port -v /tmp:/tmp mccutchen/go-httpbin:v2.1.1
from __future__ import print_function
import requests
url = "https://google.com"
url_count = 10
for i in range(url_count):
print(requests.get(url, params={'page': i}))
from __future__ import print_function
import grequests
url = "https://google.com"
url_count = 10
pending_requests = []
for i in range(url_count):
pending_requests.append(grequests.get(url, params={'page': i}))
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@saurabh-hirani
saurabh-hirani / flatten_nested.py
Last active January 16, 2019 09:21
Flatten a nested array
def flatten(arr):
"""
Flatten a nested array
>>> flatten([1, 2, 3])
[1, 2, 3]
>>> flatten([1,2,3,[1,2,3]])
[1, 2, 3, 1, 2, 3]
@saurabh-hirani
saurabh-hirani / understand-percentile-final.txt
Last active December 1, 2018 05:36
rough-notes-for-explaining-percentile
1.
- if 10 students took a test and scored the following:
10 20 30 40 50 60 70 80 90 100
and the cutoff percentage for a college admission is 90% - how many students got in?
- average does not help - avg = (n * (n + 1)) / 2 = 55
@saurabh-hirani
saurabh-hirani / get_es_index_type_count.py
Last active August 5, 2018 06:38
For an ES host - call the _mappings API and get the type count for each index
import sys
import json
import requests
# The following find function is a minor edit of the function posted here
# https://stackoverflow.com/questions/9807634/find-all-occurrences-of-a-key-in-nested-python-dictionaries-and-lists
def find(key, value):
for k, v in value.iteritems():
if k == key and not isinstance(v, dict) and not isinstance(v, list):
yield v