Skip to content

Instantly share code, notes, and snippets.

View sigmavirus24's full-sized avatar
🌴
Taking a break from F/OSS indefinitely

Ian Stapleton Cordasco sigmavirus24

🌴
Taking a break from F/OSS indefinitely
View GitHub Profile
@sigmavirus24
sigmavirus24 / cli.py
Created June 22, 2015 13:32
Getting gitenberg's repositories
>>> i = g.repositories_by('gitenberg')
>>> count = 0
>>> import time
>>> for repo in i:
... count += 1
... if count % 10000:
... time.sleep(0.5)
@sigmavirus24
sigmavirus24 / results
Last active August 29, 2015 14:23
Uploading with requests-toolbelt
>>> r.json()
{u'files': {u'file': u'import requests\n\nfrom requests_toolbelt.multipart import MultipartEncoder, MultipartEncoderMonitor\n\n\ndef encoder_callback(mon):\n pass\n\nkey = \'file\'\nfilename = \'test.py\'\nuser_agent = \'user-agent/1.0\'\nurl = \'https://httpbin.org/post\'\n\npayload = {key: (filename, open(filename, \'rb\'), "application/octet-stream")}\n\nencoder = MultipartEncoder(fields=payload, encoding=\'ascii\')\n\nmonitor = MultipartEncoderMonitor(encoder, encoder_callback)\n\nheaders = {\'content-type\': monitor.content_type, \'user-agent\': user_agent}\n\nr = requests.post(url, data=monitor, headers=headers)\n'}, u'origin': u'...', u'form': {}, u'url': u'https://httpbin.org/post', u'args': {}, u'headers': {u'Content-Length': u'752', u'Accept-Encoding': u'gzip, deflate', u'Accept': u'*/*', u'User-Agent': u'user-agent/1.0', u'Host': u'httpbin.org', u'Content-Type': u'multipart/form-data; boundary=017244edd7a74af792e8e33db55cc92b'}, u'json': None, u'data': u''}
>>> r.json()['files']
{u'
@sigmavirus24
sigmavirus24 / console.py
Created April 4, 2015 21:14
Debug logging for Hyper
>>> conn = hyper.HTTP20Connection('http2bin.org:443')
>>> first = conn.request('POST', '/post', body=body)
Sending frame SettingsFrame on stream 0
Received frame SettingsFrame on stream 0
Sending frame SettingsFrame on stream 0
HPACK encoding [(':method', 'POST'), (':scheme', 'https'), (':authority', 'http2bin.org'), (':path', '/post')]
Adding (b':method', b'POST') to the header table
Encoding 3 with 7 bits
Adding (b':scheme', b'https') to the header table
Encoding 7 with 7 bits
@sigmavirus24
sigmavirus24 / csr.py
Last active August 29, 2015 14:17
Code Search Result File Data
# Assuming csr is the CodeSearchResult
file_contents = csr.repository.file_contents(csr.path, csr.sha)
# file_contents is a Contents object so we have the decoded attribute
contents = file_contents.decoded
if not contents:
contents = file_contents.contents
# do analysis
@sigmavirus24
sigmavirus24 / logs.txt
Created March 24, 2015 16:26
ubuntu 12.04 simplejson
root@pip-wheel-ian-12:~# curl -O https://bootstrap.pypa.io/get-pip.py ; python get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1571k 100 1571k 0 0 12.4M 0 --:--:-- --:--:-- --:--:-- 13.5M
Collecting pip
Downloading pip-6.0.8-py2.py3-none-any.whl (1.3MB)
100% |################################| 1.3MB 371kB/s
Collecting setuptools
Downloading setuptools-14.3.1-py2.py3-none-any.whl (501kB)
100% |################################| 503kB 946kB/s
@sigmavirus24
sigmavirus24 / logs.txt
Created March 24, 2015 16:13
simplejson on ubuntu 14.04
root@pip-wheel-ian:~# apt-get update; apt-get install -y fail2ban python-dev
[ snip ]
root@pip-wheel-ian:~# curl -O https://bootstrap.pypa.io/get-pip.py ; python get-pip.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1571k 100 1571k 0 0 2291k 0 --:--:-- --:--:-- --:--:-- 2290k
Collecting pip
Downloading pip-6.0.8-py2.py3-none-any.whl (1.3MB)
100% |################################| 1.3MB 376kB/s
Collecting setuptools
>>> import rfc3986
>>> u = rfc3986.uri_reference('https://example.com/foo/bar;fiz=baz?boop=bop')
>>> u
URIReference(scheme=u'https', authority=u'example.com', path=u'/foo/bar;fiz=baz', query=u'boop=bop', fragment=None)
>>> u.normalize().unsplit()
u'https://example.com/foo/bar;fiz=baz?boop=bop'
@sigmavirus24
sigmavirus24 / example.hy
Created February 11, 2015 21:46
new_hyer
(defn func-gen [a b]
(fn [c]
([a b c])))
(setv one-and-two (func-gen 1 2))
(setv one-two-and-three (one-and-two 3))
@sigmavirus24
sigmavirus24 / ex.py
Created January 30, 2015 17:20
fun with packaging
>>> packaging.version.Version('1.2.10a10')
<Version('1.2.10a10')>
>>> v0 = packaging.version.Version('1.2.10a10')
>>> v1 = packaging.version.Version('1.2.10a10+openstack.1')
>>> v0 == v1
False
>>> v0 < v1
True
@sigmavirus24
sigmavirus24 / semver.rst
Last active September 21, 2022 07:52
SemVer examples
Version String 64 bit storage version
0.2.1 0000000000000000000000000000000000001000000000000000000011100000
2.10.5 0000000000000000010000000000000000101000000000000000001011100000
1.0.1a 0000000000000000001000000000000000000000000000000000000010000000
1.0.1a | 0000000000000000001000000000000000000000000000000000000010000000 |