Skip to content

Instantly share code, notes, and snippets.

View stavxyz's full-sized avatar
😿

samuel stavxyz

😿
View GitHub Profile
@stavxyz
stavxyz / test.md
Last active December 31, 2015 21:19
test
{
774e43e9a3af4e1d811d9fff57cadf43: {
    netloc: "www.thalo.com",
    managed: true,
    tenant_id: "565212",
    discovery_status: "ERROR",
    trigger_id: "urn:uuid:7d790d47-25c4-4f7e-83ba-92e764c914e1",
    time: "2013-12-19 20:54:52 +0000",
    metadata: { },
@stavxyz
stavxyz / sets.md
Last active December 31, 2015 15:59
python -- unique list

Determines whether a list nested in mongodb already contains the value.
If not, write it.

def is_a_new_thing(an_id):
    doc = DB.collection.get('stuff')
    the_ids = doc['ids']
    setbefore = set(the_ids)
    setafter = set(the_ids).add(an_id)
 # adding an existing value to a set will not change the set
@stavxyz
stavxyz / mongo.md
Created December 17, 2013 17:17
mongodb concurrency
def update(self, key, data):
        """ Affects only the keys in `data` """
        write = copy.copy(data)
        current = self.get(key)
        current.update(write)
        response = self.save(key, data) if current == self.get(key) else False
        # experimental
 # user should check response is not False to ensure successful update
@stavxyz
stavxyz / plat.py
Created December 12, 2013 00:26
import platform
import platform
for thing in dir(platform):
print '---------'
print thing
try:
print getattr(platform, thing)()
except Exception:
print getattr(platform, thing)
Unrecoverable error: error(9, 'Bad file descriptor')
Traceback (most recent call last):
  File "/home/sstav/.virtualenvs/project/local/lib/python2.7/site-packages/celery/worker/__init__.py", line 212, in start
    self.blueprint.start(self)
  File "/home/sstav/.virtualenvs/project/local/lib/python2.7/site-packages/celery/bootsteps.py", line 123, in start
    step.start(parent)
  File "/home/sstav/.virtualenvs/project/local/lib/python2.7/site-packages/celery/bootsteps.py", line 373, in start
    return self.obj.start()
  File "/home/sstav/.virtualenvs/project/local/lib/python2.7/site-packages/celery/worker/consumer.py", line 271, in start
@stavxyz
stavxyz / A_dictmaster.md
Last active December 27, 2015 14:59
map (nested) values from one dict to (differently keyed, nested) values in another dict. -- from a list of keys

like this:

The source_dict contains some values you're going to want in your new or updated target_dict, and it might look like this:

source_dict = {'key1': {
                  'key2': {
                      'key3': {
                          'key4': 'value4',
                          'key5': 'value5'
@stavxyz
stavxyz / postactivate
Last active December 22, 2015 16:29
a postactivate hook for git-hg interop supported by virtualenvwrapper
#!/bin/bash
# This hook is run after this virtualenv is activated.
#####################################
## To setup a venv which
## has git-hg interopability
##
## Fetches latest script
##
## Using virtualenv, virtualenvwrapper,