Skip to content

Instantly share code, notes, and snippets.

View stavxyz's full-sized avatar
😿

samuel stavxyz

😿
View GitHub Profile
@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,
@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'
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 / 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)
@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 / 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 / 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: { },

san/desan using ujson

  • standard read/write
    • 1.23 ms
  • sysinfo block read/write
    • 97.7 ms

SON Manipulator

  • standard read/write
    • .75 ms
  • sysinfo block read/write
"""
Example for a colourised logging output.
This example uses "blessings" to handle console escape sequences. ``blessings``
itself is a very harmless package in that it does not have any external
dependencies. And it's code-base is very clean and small.
The example extends the core logging formatter (logging.Formatter) and
colourises the complete line. This takes advantage of any upstream updates
related to logging. When writing this against Python 2.7, the parent code
@stavxyz
stavxyz / red.py
Created December 30, 2013 16:28
redis string from connection_string
import urlparse
from redis import Redis
from waldo.common import config
conf = config.current()
dbstring = conf['connection_string']
dbstring = urlparse.urlparse(dbstring)
dbstring = "redis://" + dbstring.netloc + ":6329"