Skip to content

Instantly share code, notes, and snippets.

View svschannak's full-sized avatar

Sven Schannak svschannak

View GitHub Profile
@svschannak
svschannak / snmp_calls.py
Last active January 3, 2016 21:09
Create a valid mac-address from an string
def create_valid_mac_address(mac_address):
mac_address = mac_address.replace("-", "")
if len(mac_address) != 12:
raise InvalidMacAddressStringException("The String of the MAC-Address does not contain enough characters")
if not all(c in string.hexdigits for c in mac_address):
wrong_chars = ""
for c in mac_address:
if c not in string.hexdigits:
wrong_chars += "#%s#" % c
else:
@svschannak
svschannak / write_list_to_file.py
Created January 20, 2014 12:49
Write and read list to/from file
snmpwalk_mac_file = open("ndms/snmp-results/snmpwalk_mac_adresses.txt", "w")
snmpwalk_mac_file.close()
snmpwalk_mac_file = open("ndms/snmp-results/snmpwalk_mac_adresses.txt", "w")
pickle.dump(mac_objects, snmpwalk_mac_file)
#snmpwalk_mac_file = open("ndms/snmp-results/snmpwalk_mac_adresses.txt", "r")
#snmp_mac_list = pickle.load(snmpwalk_mac_file)
@svschannak
svschannak / api.py
Last active January 4, 2016 02:39 — forked from marteinn/api.py
from tastypie.exceptions import NotFound
from tastypie.resources import ModelResource
from tastypie.authentication import BasicAuthentication, ApiKeyAuthentication
from tastypie.models import ApiKey
from django.contrib.auth.models import User
__author__ = 'martinsandstrom'
class ApiTokenResource(ModelResource):
from tastypie import fields
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from tastypie.bundle import Bundle
from tastypie.exceptions import NotFound
from tastypie.resources import Resource
# a dummy class representing a row of data
class Row(object):
@svschannak
svschannak / add_days.py
Created January 24, 2014 10:32
add days to datetime-object
self.datetime + datetime.timedelta(days=3)
{{ reservation.datetime|date:'Y-m-d\TH:i:s' }}
def product_list(self):
products = self.products.all()
product_list = []
for product in products:
for product_store in product.stores_for_product.all():
product_list.append(product_store)
for cat in self.child_categories.all():
for product in cat.product_list():
product_list.append(product)
@svschannak
svschannak / create_password_for_nginx_auth.sh
Created January 27, 2014 10:35
create password for nginx_auth
printf "username:$(openssl passwd -crypt password)\n" >> htpasswd
@svschannak
svschannak / rgb-cmyk-rgb-conversion
Created February 4, 2014 10:10
convert rgb to cmyk to rgb
def rgb_to_cmyk(r,g,b):
cmyk_scale = 100
if (r == 0) and (g == 0) and (b == 0):
# black
return 0, 0, 0, cmyk_scale
# rgb [0,255] -> cmy [0,1]
c = 1 - r / 255.
from tastypie import fields
from tastypie.authentication import Authentication
from tastypie.authorization import Authorization
from tastypie.bundle import Bundle
from tastypie.exceptions import NotFound
from tastypie.resources import Resource
# a dummy class representing a row of data
class Row(object):