Skip to content

Instantly share code, notes, and snippets.

@ndricca
ndricca / fastapi_error_example.py
Last active October 4, 2022 09:12
[SOLVED] Stack Overflow question on FastAPI
from typing import Optional, List, Union
from typing_extensions import Literal
import uvicorn
from pydantic import BaseModel, Field
from fastapi import FastAPI, Body
class Payload(BaseModel):
start: int
@ndricca
ndricca / find_notebook_by_mem_usage.md
Last active July 5, 2022 09:35
Find which jupyter notebook is using more memory on server

How to find out which jupyter notebook is using most of memory on a server

UPDATE 2022-07: see python script attached

  1. find PIDs responsibles of most memory usage: ps aux --sort=-%mem | head

  2. look at the name of the JSON used inside the jupyter launcher command, usually is kernel-${kernel_id}.json and get `${kernel_id}

  3. go at the jupyter server endpoint /api/sessions

MULTIPLES_DICT = {
3: 'Fizz',
5: 'Buzz',
7: 'Wolf',
}
def _is_by_num(num: int, multiple: int) -> bool:
return num % multiple == 0
@ndricca
ndricca / css-parallax-w3s-sample.markdown
Created June 11, 2020 12:53
CSS-Parallax-W3S-Sample
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>covid_effect_pollution_milan</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
@ndricca
ndricca / join_coalesce.R
Created August 1, 2018 10:22
how to make this join for multiple columns?
library(tidyverse)
(a <- data_frame(ID = 1:20,
D1 = sample(0:1,size = 20,replace = T,prob = c(0.8,0.2)),
D2 = sample(0:1,size = 20,replace = T,prob = c(0.7,0.3)))
)
(b <- data_frame(ID = 1:20,
D1 = sample(0:1,size = 20,replace = T,prob = c(0.9,0.1)),
D2 = sample(0:1,size = 20,replace = T,prob = c(0.9,0.1)))
)
@ndricca
ndricca / gist:95dca0530e4a1be6ab5be52b7753e8a5
Created June 27, 2018 08:29
dplyr conteggio e proporzione in riga per grouppi
rm(list = ls())
library(dplyr)
df <- data_frame(y = rnorm(10,2),
x1 = as.factor(rbinom(10,1,0.5)),
x2 = as.factor(rep(letters[1:2],5)))
df
df %>%
add_count() %>%