Skip to content

Instantly share code, notes, and snippets.

@arifsuhan
arifsuhan / colab_host_webserver.md
Last active June 18, 2024 02:35
A general way to run Web Applications on Google Colab

Run Web Application on Google Colab

Port Selection

Port Command
Unused Port import portpicker
port = portpicker.pick_unused_port()
Or
Custom Port port = 8000
Custom Port port = 8000 port = 8000
@rcoup
rcoup / conftest.py
Created June 27, 2019 15:02
Click CliRunner with PDB working better under pytest
import contextlib
import io
import warnings
import pytest
from click.testing import CliRunner
"""
In your tests:
@mgaitan
mgaitan / flat_alembic_versions.py
Last active May 7, 2020 16:48
Flat alembic multi-branches in one linear branch
# -*- coding: utf-8 -*-
"""
Flat alembic versions
A______
| | |
B B1 ...
| |
C C1
|
@junaid1460
junaid1460 / jupyter_html_table.py
Last active January 7, 2023 20:57
Jupyter HTML Table class, Pythonic way of creating Table for jupyter
from IPython.display import HTML, display
class Tag:
def __init__(self, name, value):
self.name = name
self.value = value
def __repr__(self):
return "<%s>%s</%s>"%(self.name, str(self.value), self.name)
class Linear:
def __init__(self, data):
@omaraboumrad
omaraboumrad / splitlogs.py
Created October 6, 2017 14:18
View docker-compose services logs in split tmux panes
# Requires pyyaml
import os
import yaml
run = os.system
new_window = lambda cmd: run('tmux new-window -n "logs" "{}"'.format(cmd))
split_vertical = lambda cmd: run('tmux split-window "{}"'.format(cmd))
split_horizontal = lambda cmd: run('tmux split-window -h "{}"'.format(cmd))
even_vertical = lambda: run('tmux select-layout even-vertical')
@ask
ask / async_cached_property.py
Last active February 28, 2018 11:57
async_cached_property
import asyncio
from typing import Any, Awaitable, Callable, Optional, Type
# eh, like the @cached_property idiom, but async and you do `await x.y`
class async_cached_property:
name: str
def __init__(self, getter: Callable[[], Awaitable]) -> None:
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dschep
dschep / py-comp-to-js.md
Last active May 21, 2024 12:58
Python Comprehensions to JS

Python list & dict comprehensions translated to JavasScript

Comprehensions are a really useful feature of Python that aren't available in JavaScript (or many languages). These concepts of course can be tranlsated into using map instead. But especially the dictionaries are a bit trickier.

Lists / Arrays

>>> foobar = range(5)
>>> [x + 1 for x in foobar]
[1, 2, 3, 4, 5]
@h4
h4 / env.py
Last active June 20, 2024 13:00
Setup alembic to work properly with PostgreSQL schemas
from __future__ import with_statement
from alembic import context
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from models import Base
config = context.config
fileConfig(config.config_file_name)
@mgaitan
mgaitan / post-checkout.py
Created March 3, 2016 12:42 — forked from inklesspen/post-checkout.py
Post-checkout hook to detect alembic issues when switching branches.
#!/usr/bin/env python
"""
Provide useful alembic information after switching branches.
"""
import argparse
import subprocess
import os
import os.path
import py.path