Skip to content

Instantly share code, notes, and snippets.

f = open(...)
try:
json.loads(f.read())
except ValueError:
print "Invalid JSON"
raise
finally:
f.close()
#!/usr/bin/env python2
import json
import os
import re
import scrapy
from scrapy.crawler import CrawlerProcess
RELEASE_MAP = {

Features of uvp-monitor:

  • Collects information about resource usage of every VM and periodically writes the information into domain0 through xenstore. The resource usage information includes the total number of CPUs. CPU usage, memory capacity, memory usage, disk capacity, disk usage, and the number of packets received or sent by a NIC.
  • Collects VM hostnames and writes them into domain0 through xenstore.
  • Notifies domain0 whether the current VM supports hot-plug of memory, CPUs, and disks.
  • Facilitates live migration of Xen VMs and triggers VMs to send gARP and ndp packets to the network at completion of live migration.
  • Facilitates self-upgrade of UVP Tools on VMs. The uvp-monitor works with xenstore to notify domain0 of the UVP Tools version installed on VMs. If the UVP Tools version on a VM is different from the UVP Tools version on the host, the UVP Tools on the VM is then automatically upgraded to the version installed on the host.
class MyTestCase(unittest.TestCase):
def setUp(self):
self.foo_patcher = patch('__main__.Class', spec=True)
self.foo_patcher.start()
def tearDown(self):
self.foo_patcher.stop()
class TestThingie(MyTestCase):
class Foo(object):
def __init__(self):
self._endpoint = None
@property
def endpoint(self):
if self._endpoint is None:
self._endpoint = self._find_endpoint()
return self._endpoint
@OddBloke
OddBloke / README.md
Last active January 6, 2017 13:26 — forked from smoser/README.md
publishing image to azure

Publishing an image on Azure

Installation of azure cli tools

The azure cli tool is used to do this publication. To install it follow below. For further questions see Azure CLI Install

# add ~/bin and add it to path
mkdir -p ~/bin/
[ "${PATH#*$HOME/bin}" = "$PATH" ] || PATH=$HOME/bin:$PATH

install npm

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
$ cut -d: -f1 < out | cut -d/ -f1-3 | sort | uniq -c | sort -r -n
355 third_party/2and3/boto
229 third_party/2and3/jinja2
99 third_party/2and3/Crypto
81 third_party/2and3/pynamodb
43 third_party/2and3/requests
33 third_party/2and3/yaml
21 third_party/2and3/click
10 third_party/3/itsdangerous.pyi
10 stdlib/2and3/formatter.pyi
@OddBloke
OddBloke / README.md
Last active August 22, 2017 09:41
eq_plugin.py: mypy plugin to check that types are only compared to themselves

How to Use

  1. Put eq_plugin.py somewhere in your project
  2. Add plugins=path/to/eq_plugin.py to the mypy section of your mypy.ini (see example in this gist)
  3. Run mypy

Example

@OddBloke
OddBloke / Output When Run Against example.py.txt
Created August 30, 2017 09:31
A simple typed_ast script to find nested classes
--- nested.py ---
Foo -> Bar
Foo -> Bar -> Baz
Foo -> Lolz
*InMethod -> InInMethod
Foo -> Eggs
*InFunc -> InInFunc
Second -> InSecond
InIf -> InInIf
InElse -> InInElse