Skip to content

Instantly share code, notes, and snippets.

View devhero's full-sized avatar
😁

Andrea Parisi devhero

😁
  • devhero
  • Milan
View GitHub Profile
@devhero
devhero / recursive_op_key.py
Created October 24, 2018 09:23
recursive operation on key
def lower(obj):
return obj.lower()
def lower_dict(obj):
return _recursive_key_op(obj, lower)
def _recursive_key_op(obj, op=None):
if isinstance(obj, dict):
return {op(k): _recursive_key_op(v, op) for k, v in obj.items()}
elif isinstance(obj, (list, set, tuple)):
@devhero
devhero / flask_tips
Last active August 16, 2021 09:50
flask tips
# from http://flask.pocoo.org/docs/1.0/cli/
# Setting Command Options
# Click is configured to load default values for command options from environment variables. The variables use the pattern FLASK_COMMAND_OPTION. For example, to set the port for the run command, instead of flask run --port 8000:
export FLASK_RUN_PORT=8000
flask run
* Running on http://127.0.0.1:8000/
@devhero
devhero / jest_webpack_babel
Last active June 15, 2018 08:49
jest webpack babel
// https://redux.js.org/recipes/writing-tests
// https://facebook.github.io/jest/docs/en/webpack.html
npm i -D jest babel-jest transform-es2015-modules-commonjs
// package.json
{
...
"jest": {
@devhero
devhero / babel_unexpected_token
Created May 22, 2018 16:52
ERROR in ./index.js Module build failed: SyntaxError: Unexpected token
// https://stackoverflow.com/questions/34614812/error-in-index-js-module-build-failed-syntaxerror-unexpected-token#34619867
// .babelrc
{
"presets": [
"react",
"env"
],
"plugins": [
@devhero
devhero / image_conversion_svg_png
Created May 11, 2018 10:50
image conversion svg to png
rsvg-convert img.svg > img.png
rsvg-convert -h 256 img.svg > img.png
@devhero
devhero / django_client_request_testing
Created April 30, 2018 07:19
django client request testing
from django.test.client import Client
client = Client()
response = client.get(some_url)
request = response.wsgi_request
@devhero
devhero / setuptools_git.py
Created April 23, 2018 09:26
setuptools git library
# https://stackoverflow.com/questions/49847800/how-can-setuptools-dependency-links-be-used-with-the-latest-master-branch-of
setup(
...
install_requires=[
'krakenex;python_version<3',
'krakenex3;python_version>=3',
],
dependency_links = [
"git+https://github.com/veox/python2-krakenex.git#egg=krakenex;python_version<'3.0'",
@devhero
devhero / setuptools_git_ssl.ssh
Created April 23, 2018 09:23
setuptools git ssl
# https://stackoverflow.com/questions/11621768/how-can-i-make-git-accept-a-self-signed-certificate#11622001
# copy public key from remote git host into pub file:
~/.ssh/id_rsa_custom1.pub
# edit global git config
~/.gitconfig
@devhero
devhero / py_mock_patch
Created April 20, 2018 12:37
python mock patch
from unittest.mock import patch
class settings:
FIRST_PATCH = 1
SECOND_PATCH = 2
with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'):
assert settings.FIRST_PATCH == 'one'
assert settings.SECOND_PATCH == 'two'
@devhero
devhero / major_version.py
Last active March 1, 2018 10:25
python get major version between files
import os, glob
from distutils.version import StrictVersion
def get_version(filename):
return os.path.splitext(filename)[0].split('-')[-1]
def _get_major_version(get_version_func):
def major_version(file_names=[]):
major_version_file = file_names[0]