Skip to content

Instantly share code, notes, and snippets.

View AlexandreProenca's full-sized avatar
:octocat:
Focusing

Alexandre Proença AlexandreProenca

:octocat:
Focusing
View GitHub Profile
@AlexandreProenca
AlexandreProenca / fastapi_websocket_redis_pubsub.py
Created December 17, 2021 13:54 — forked from timhughes/fastapi_websocket_redis_pubsub.py
FastAPI Websocket Bidirectional Redis PubSub
"""
Usage:
Make sure that redis is running on localhost (or adjust the url)
Install uvicorn or some other asgi server https://asgi.readthedocs.io/en/latest/implementations.html
pip install -u uvicorn
Install dependencies
class SearchTree:
def __init__(self, cargos: List[dict], trucks: List[dict]):
self.cargo_nodes, self.truck_nodes = self.build_nodes(cargos, trucks, Node)
self.tree = KdTree(self.truck_nodes)
self.delivery_distance = {
item['product']: geodesic(
(item['origin_lat'], item['origin_lng']),
(item['destination_lat'], item['destination_lng'])
) for item in cargos
}
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<title>G1 > Loterias</title>
<link>http://g1.globo.com/loterias/index.html</link>
<description>
Veja no G1 Loterias os resultados dos últimos concursos da Mega-Sena, Dupla Sena, Loteria Federal, Loteca, Lotofacil, Lotogol, Lotomania, Quina e Timemania.
</description>
<language>pt-BR</language>
<copyright>© Copyright Globo Comunicação e Participações S.A.</copyright>
<atom:link href="http://pox.globo.com/rss/g1/loterias/" rel="self" type="application/rss+xml"/>
@AlexandreProenca
AlexandreProenca / Postgres tips
Created February 8, 2019 11:32
Quando é necessario que uma tabela seja alterada em uma transação atomica
migrations.RunSQL("""
ALTER TABLE "campaigns_groupmember"
ADD CONSTRAINT "campaigns_groupmember_parent_order_uniq"
UNIQUE USING INDEX "campaigns_groupmember_parent_order_uniq"
DEFERRABLE
INITIALLY IMMEDIATE
"""),
seq_page_cost (floating point)
Sets the planner's estimate of the cost of a disk page fetch that is part of a series of sequential fetches. The default is 1.0. This value can be overridden for tables and indexes in a particular tablespace by setting the tablespace parameter of the same name (see ALTER TABLESPACE).
random_page_cost (floating point)
Sets the planner's estimate of the cost of a non-sequentially-fetched disk page. The default is 4.0. This value can be overridden for tables and indexes in a particular tablespace by setting the tablespace parameter of the same name (see ALTER TABLESPACE).
Reducing this value relative to seq_page_cost will cause the system to prefer index scans; raising it will make index scans look relatively more expensive. You can raise or lower both values together to change the importance of disk I/O costs relative to CPU costs, which are described by the following parameters.
Random access to mechanical disk storage is normally much more expensive than four times sequential
@AlexandreProenca
AlexandreProenca / DHT.py
Created August 15, 2018 02:16 — forked from eyllanesc/DHT.py
Raspberry Pi Course Code
import Adafruit_DHT
import time
isRunning = True
while isRunning:
try:
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, 4)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity))
else:

Checkout a new working branch

 git checkout -b <branchname>

Make Changes

 git add
 git commit -m "description of changes"

Sync with remote

[].forEach.call($$("*"),function(a){
var color = (~~(Math.random()*(1<<24))).toString(16)
a.style.outline="1px solid #"+color;
var dom = document.createElement("div");
dom.setAttribute("style", "font-size: 10px; margin:5px; background: #"+color);
dom.innerText = a.localName;
a.appendChild(dom);
})
@AlexandreProenca
AlexandreProenca / README.md
Created January 31, 2017 13:15 — forked from addyosmani/README.md
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version

@AlexandreProenca
AlexandreProenca / bottle-cors.py
Created June 30, 2016 17:27 — forked from richard-flosi/bottle-cors.py
Bottle with Cross-origin resource sharing (CORS)
"""
Example of setting up CORS with Bottle.py.
"""
from bottle import Bottle, request, response, run
app = Bottle()
@app.hook('after_request')
def enable_cors():
"""