Skip to content

Instantly share code, notes, and snippets.

View alanjds's full-sized avatar

Alan Justino da Silva alanjds

  • Santo André, São Paulo/SP - Brazil
View GitHub Profile
@alanjds
alanjds / decorators.py
Created August 3, 2020 18:59 — forked from garrypolley/decorators.py
Django decorate 3rd party app's views
# -*- 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 August 22, 2019 20:45
What CPython modules are Pure and what ones are C-based?
_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
@alanjds
alanjds / awslambda.bootstrap.py
Created April 16, 2018 22:18 — forked from lucasrcosta/awslambda.bootstrap.py
AWS Lambda Python Runtime
# -*- 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 August 10, 2015 14:03
Error on pycryptodome recipe (p4a)
#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'
@alanjds
alanjds / logs
Last active August 29, 2015 14:06
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 August 29, 2015 14:06 — forked from tito/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 August 29, 2015 14:06 — forked from tito/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 August 29, 2015 14:06 — forked from tito/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
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 December 20, 2015 07:09
Solves: "LookupError: unknown encoding: hex"
# 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 *