Skip to content

Instantly share code, notes, and snippets.

View VITIMan's full-sized avatar

VITI VITIMan

  • ¡Murcia!
View GitHub Profile
@VITIMan
VITIMan / argparse_unique_elems.py
Created August 23, 2017 08:08
Snippets using argparse
import argparse
# https://stackoverflow.com/a/9377686
class UniqueAppendAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
unique_values = set(values)
setattr(namespace, self.dest, unique_values)
servers = ["ApaServer", "BananServer", "GulServer", "SolServer",
"RymdServer", "SkeppServer", "HavsServer", "SovServer" ]
@VITIMan
VITIMan / cli_curl.md
Last active September 19, 2017 14:52
command line
@VITIMan
VITIMan / import_dynamic.py
Created August 30, 2017 14:16
Some dynamic imports snippets
"""
# From: https://stackoverflow.com/a/30941292
# Standard import
import importlib
# Load "module.submodule.MyClass"
MyClass = getattr(importlib.import_module("module.submodule"), "MyClass")
# Instantiate the class (pass arguments to the constructor, if needed)
instance = MyClass()
"""
@VITIMan
VITIMan / json_array_requests.py
Created September 4, 2017 07:39
Requests library snippets
import requests
import json
# from https://stackoverflow.com/a/35534695
payload = [{"json": "array"}, {"another": "element"}]
headers = {'Content-Type': 'application/json', 'Accept':'application/json'}
requests.post(url,data=json.dumps(payload), headers=headers)
# In newer versions of requests
# from https://stackoverflow.com/a/35535240
@VITIMan
VITIMan / docker-compose.md
Created September 5, 2017 07:40
Docker snippets

Debugging

If you are using the following within your code to debug:

import ipdb; ipdb.set_trace()

Then you may need to run the following for it to work as desired:

$ docker-compose -f file.yml run --service-ports image:tag
@VITIMan
VITIMan / activitypub_resources.md
Created September 10, 2017 17:07
ActivityPub, JSON-LD, ActivityStreams resources