Skip to content

Instantly share code, notes, and snippets.

@viatoriche
viatoriche / common.plantuml
Created February 1, 2024 11:28
common.plantuml
!define PrimaryNavyBlue 00204d
!define SecondaryBlue 73acdd
!define SecondaryLightBlue d4e5f7
!define DeepGrey 737373
!define SecondaryGrey 969696
!define SecondaryLightGrey cdcdcd
skinparam ParticipantBackgroundColor<<Internal>> #PrimaryNavyBlue
skinparam ParticipantBackgroundColor<<3rdParty>> #DeepGrey
skinparam ActorBackgroundColor<<Internal>> #PrimaryNavyBlue
@viatoriche
viatoriche / about.txt
Created August 14, 2017 09:08 — forked from jessejlt/about.txt
nginx, flask, and file downloads
Okay so here's the setup:
[-] The primary server API is exposed via Flask (Python) and all static files, including all html, css, js is served by nginx.
[-] Python is exposing an API at url http://domain.com/api/download/<file_id>, where file_id is a database id for the file that we're interested in downloading.
1. User wants to download a file, so we spawn a new window with the url '/api/download/<file_id>'
2. Nginx intercepts the request, sees that it starts with /api/, and then forwards the request to Flask, which is being served on port 5000.
3. Flask routes the request to its download method, retrieves the pertinent data from the file_id, and constructs additional header settings to make nginx happy and to force the browser to see the file stream as a download request instead of the browser just trying to open the file in a new window. Flask then returns the modified header stream to nginx
4. Nginx is finally ready to do some work. While parsing the headers for the incoming request, it encounters "X
@viatoriche
viatoriche / dict_update.py
Last active March 31, 2016 13:17
dict_update
import collections
def dict_update(d, u):
"""Recursive dict update
:param d: goal dict
:param u: updates for d
:return: new dict
"""
for k, v in u.iteritems():
@viatoriche
viatoriche / geventreactor.py
Last active September 15, 2015 14:54 — forked from yann2192/geventreactor.py
Twisted reactor running on gevent (libevent+greenlet)
## Copyright (C) 2011 by Jiang Yio <http://inportb.com/>
## Please find instructions at <http://wiki.inportb.com/python:geventreactor>
## The latest code is available at <https://gist.github.com/848058>
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
@viatoriche
viatoriche / fields.py
Last active August 29, 2015 14:26 — forked from nagyv/fields.py
Google Protobuffer field for Django
''' A model field to store and retrieve Google Protocol Buffer objects easily.
Uses the BlobField available on GAE for storage.
Usage:
myfield = ProtobufField(protoclass=MyProtocolClass)
where MyProtocolClass is a protocol descriptor class generated from a .proto file.
The field is supposed to store only the given kind of protocol messages.