Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Justino da Silva alanjds

  • Santo André, São Paulo/SP - Brazil
View GitHub Profile
@alanjds
alanjds / decorators.py
Created Aug 3, 2020 — forked from garrypolley/decorators.py
Django decorate 3rd party app's views
View decorators.py
# -*- coding: utf-8 -*-
from django.conf.urls import include
def decorated_include(urls, decorator)
"""Used to decorate all urls in a 3rd party app with a specific decorator"""
urls_to_decorate = include(urls)
for url_pattern in urls_to_decorate
url_pattern._callback = decorator(url_pattern._callback)
@alanjds
alanjds / pure.py
Last active Aug 22, 2019
What CPython modules are Pure and what ones are C-based?
View pure.py
_original_import = __import__
def store_loader(name, module, storage):
try:
spec = module.__spec__
loader = spec.loader if type(spec.loader) == type else spec.loader.__class__
except Exception as err:
loader = type(err)
module = err
View awslambda.bootstrap.py
# -*- coding: utf-8 -*-
# /var/runtime/awslambda/bootstrap.py
"""
aws_lambda.bootstrap.py
Amazon Lambda
Copyright (c) 2013 Amazon. All rights reserved.
Lambda runtime implemention
"""
@alanjds
alanjds / __init__.py
Created Aug 10, 2015
Error on pycryptodome recipe (p4a)
View __init__.py
#coding: utf-8
from pythonforandroid.toolchain import CompiledComponentsPythonRecipe, PythonRecipe
class PyCryptodomeRecipe(PythonRecipe):
version = '3.1'
url = 'https://pypi.python.org/packages/source/p/pycryptodome/pycryptodome-{version}.zip'
site_packages_name= 'pycrypto'
View logs
09-26 00:18:56.167: I/python(10572): PATH: ['/data/app/org.test.minimalcalc-1.apk/assets', '/data/app/org.test.minimalcalc-1.apk/assets/lib/python2.7/', '/data/app/org.test.minimalcalc-1.apk/assets/lib/python2.7/site-packages/']
09-26 00:18:56.168: I/python(10572): PWD: /
09-26 00:18:56.168: I/python(10572): PWD: /
09-26 00:18:56.170: I/python(10572): Traceback (most recent call last):
09-26 00:18:56.170: I/python(10572): File "/data/data/org.test.minimalcalc/files/_bootstrap.py", line 127, in <module>
09-26 00:18:56.170: I/python(10572): runpy._run_module_as_main(main_module, False)
09-26 00:18:56.170: I/python(10572): File "/Users/alanjds/src/git/python-for-android/dist/default/private/lib/python2.7/runpy.py", line 162, in _run_module_as_main
09-26 00:18:56.171: I/python(10572): File "/Users/alanjds/src/git/python-for-android/dist/default/private/lib/python2.7/runpy.py", line 72, in _run_code
09-26 00:18:56.171: I/python(10572): File "/Users/alanjds/src/git/p4a-minimal-shell/main.py", line 44, i
@alanjds
alanjds / README
Last active Aug 29, 2015 — forked from tito/README
View README
P4A_pyjnius_DIR=~/code/pyjnius ./distribute.sh -b minimal -m 'pyjnius python' -u pyjnius
cd .; ./build.py --package org.minimal.test --name _MINIMAL --version 1 --private ~/code/testmininal --asset debug installd
adb logcat *:S python:D
@alanjds
alanjds / README
Last active Aug 29, 2015 — forked from tito/README
View README
P4A_pyjnius_DIR=~/code/pyjnius ./distribute.sh -b minimal -m 'pyjnius python' -u pyjnius
cd .; ./build.py --package org.minimal.test --name _MINIMAL --version 1 --private ~/code/testmininal --asset debug installd
adb logcat *:S python:D
@alanjds
alanjds / README
Last active Aug 29, 2015 — forked from tito/README
View README
P4A_pyjnius_DIR=~/code/pyjnius ./distribute.sh -b minimal -m 'pyjnius python' -u pyjnius
cd .; ./build.py --package org.minimal.test --name _MINIMAL --version 1 --private ~/code/testmininal --asset debug installd
adb logcat *:S python:D
View c_version.diff
diff --git a/bootstrap/minimal/jni/main.c b/bootstrap/minimal/jni/main.c
index ca1a7de..252059e 100644
--- a/bootstrap/minimal/jni/main.c
+++ b/bootstrap/minimal/jni/main.c
@@ -1,5 +1,7 @@
#include <jni.h>
#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include <android/log.h>
@alanjds
alanjds / binascii.py
Last active Dec 20, 2015
Solves: "LookupError: unknown encoding: hex"
View binascii.py
# Adapted from: https://bitbucket.org/pypy/pypy/src/f2bf94943a41/lib_pypy/binascii.py
"""A pure Python implementation of binascii.
Rather slow and buggy in corner cases.
PyPy provides an RPython version too.
"""
try:
from _binascii import *