This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import fdopen | |
from json import dumps | |
from tempfile import mkstemp | |
payload = {'one': 1} | |
osfd, tmpfile = mkstemp() | |
with fdopen(osfd, 'w') as pf: | |
pf.write(dumps(payload)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from six import add_metaclass | |
def print_decorator(func): | |
def replacement(*args, **kwargs): | |
result = func(*args, **kwargs) | |
print('The result of the function is: {}'.format(result)) | |
return result | |
return replacement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_modules(name): | |
""" | |
Get a list of all submodules given a module root name. | |
""" | |
from pkgutil import walk_packages | |
module = __import__(name) | |
# Handle modules installed in top-level | |
if not hasattr(module, '__path__'): | |
return [(name, False)] | |
submodules = [(name, True)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.utils.crypto import get_random_string | |
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' | |
if __name__ == '__main__': | |
print(get_random_string(50, chars)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add_digits_optimized(num): | |
""" | |
Recursively sum al digits of a number until result is one digit. | |
Optimized version using simple integer logic. | |
:param int num: Number to sum all it's digits. | |
:rtype: int | |
:return: The recusive sum of all digits. | |
""" | |
result = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding:utf-8 -*- | |
# | |
# Copyright (C) 2015 Carlos Jenkins <[email protected]> | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, either version 3 of the License, or | |
# (at your option) any later version. | |
# | |
# This program is distributed in the hope that it will be useful, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
// | |
// Define a thing to store in sections | |
// | |
struct mything { | |
const char* name; | |
int num; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of a memory mapped register structure: | |
// | |
// gcc register.c -o register | |
// ./register | |
// | |
// This assumes register size is 8bits. | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> |