This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git config --global alias.lola "log --graph --decorate --pretty=oneline --abbrev-commit --all" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import base64 | |
def int_to_b32str(x): | |
base = int(math.log2(1 + x) / 8) + 1 # How many bytes ? | |
bytestring = x.to_bytes(base, 'big') | |
b32str = base64.b32encode(bytestring).decode() | |
return b32str.rstrip('=') # remove trailing "=" | |
def b32str_to_int(b): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# !pip install clipboard | |
# !pip install Pillow | |
import clipboard | |
from PIL import ImageGrab, Image | |
import base64 | |
def clipboard_to_image(): | |
"""Reads image in the clipboard and outputs a PIL.Image""" | |
image = ImageGrab.grabclipboard() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import logging | |
# 1 - Choose a logger (where logs should come from) | |
# logger = logging.getLogger() # Root logger ; if you're in a notebook of end-user script | |
logger = logging.getLogger(__name__) # Lib-named logger ; if you're in a module | |
# logger = logging.getLogger(None if __name__=='__main__' else __name__) | |
# 2 - Choose the (minimal) log level | |
logger.setLevel(logging.DEBUG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Brutal shortcuts: | |
# Kill everything launched with "python registry.py" | |
kill -SIGTERM -$(ps aux | grep 'python registry.py' | awk '{print $2}') | |
# Same in a function | |
grepkill() { kill -SIGTERM -$(ps aux | grep $1 | awk '{print $2}'); } | |
# Restart a uvicorn server | |
git reset --hard ; kill -SIGTERM $(ps aux | grep 'uvicorn server:app' | grep -v "grep" | awk '{print $2}'); nohup uvicorn server:app --host 127.0.0.1 --port 8000 > server.log & |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymongo | |
connection = pymongo.MongoClient() | |
# get running operations | |
list(connection.admin["$cmd.sys.inprog"].find()) | |
# kill an operation by id | |
op_id = 123456 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import HTML | |
def _repr_html_(self, figsize=(17,10), **kwargs): | |
"""Displays in the notebook a folium.folium.Map object. | |
""" | |
self._build_map(**kwargs) | |
width, height = figsize | |
iframe = '<iframe src="data:text/html;base64,{html}" width="{width}" height="{height}"></iframe>'\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tornado import ioloop, gen, concurrent | |
import pandas as pd | |
import time | |
import asyncio | |
from multiprocessing import TimeoutError, Process | |
from multiprocessing.dummy import Pool as ThreadPool | |
class F(object): | |
def __init__(self): |
NewerOlder