Skip to content

Instantly share code, notes, and snippets.

View polyrand's full-sized avatar

Ricardo Ander-Egg polyrand

View GitHub Profile
@polyrand
polyrand / LICENSE.md
Last active January 22, 2021 13:03
Excalidraw.art License

DISCLAIMER

This License is currently being reviewed and may be updated any time. The changes made to this License have immediate effect after its update.

TL;DR

You can use the Drawings for whatever you want except redistributing or reselling them in any of their forms, separated or packaged.

You can use them for unlimited End Products, either paid or free, for unlimited End Clients, as long as the End Product is not directly related or in competition with the Drawings and/or excalidraw.art.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@polyrand
polyrand / README-setup-tunnel-as-systemd-service.md
Created November 26, 2020 18:28 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/[email protected]. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@polyrand
polyrand / app.py
Created November 3, 2020 16:22
Example structure of putting a whole app in a single file.
import asyncio
import smtplib
import ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from socket import gaierror
import base64
import datetime as dt
import imghdr
import json
@polyrand
polyrand / latency.txt
Created September 1, 2020 23:52 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@polyrand
polyrand / parse_sql_return.py
Last active September 21, 2024 10:34
Decorator to parse the results of a raw sqlalchemy query to a Pydantic model.
import inspect
from functools import partial, wraps
from typing import Union
from app import schemas
from app.db import database
from pydantic.main import ModelMetaclass
from shortuuid import uuid
# The following 2 functions parse raw results from the SQL queries
@polyrand
polyrand / docdec.py
Created July 27, 2020 20:48
Write python docstrings in a separate text file.
# docd.py
def doc(f):
with open("docs.txt") as d:
docfile = d.read()
# save old docstring
if f.__doc__:
prev_doc = f.__doc__
f.__doc__ = prev_doc + "\n\n# docdoc\n" + docfile
-- walkthrough of: https://mystery.knightlab.com
--
/* A crime has taken place and the detective needs
* your help. The detective gave you the crime
* scene report, but you somehow lost it. You
* vaguely remember that the crime was a murder
* that occurred sometime on Jan.15, 2018 and that
* it took place in SQL City. Start by retrieving
* the corresponding crime scene report from the
* police department’s database. */
@polyrand
polyrand / reorder_data.py
Last active May 25, 2020 07:57
TFG snippet
new_cols_nodrug = [c for c in df.columns.to_list() if c not in all_drug_cols]
new_cols = new_cols_nodrug.copy()
for i in range(len(drugs)):
new_cols.append(f"drug_{i}")
new_cols.append(f"pasi_inicial_{i}")
new_cols.append(f"tiempo_{i}")
new_cols.append(f"motivo_{i}")