Skip to content

Instantly share code, notes, and snippets.

View falkben's full-sized avatar
🚲

Ben Falk falkben

🚲
View GitHub Profile
@falkben
falkben / run.py
Created December 8, 2022 22:56
run.py command for running terraform commands in different environments and modules
#!/usr/bin/env python3
"""Script to execute terraform commands in the correct environment per module
Examples:
# init backend for lambdas module inside sandbox environment
./run.py sb lambdas init
# deploy platform module for dev environment
@falkben
falkben / sync_async_deco.py
Created August 1, 2020 04:07 — forked from anatoly-kussul/sync_async_deco.py
Python sync-async decorator factory
class SyncAsyncDecoratorFactory:
"""
Factory creates decorator which can wrap either a coroutine or function.
To return something from wrapper use self._return
If you need to modify args or kwargs, you can yield them from wrapper
"""
def __new__(cls, *args, **kwargs):
instance = super().__new__(cls)
# This is for using decorator without parameters
if len(args) == 1 and not kwargs and (inspect.iscoroutinefunction(args[0]) or inspect.isfunction(args[0])):
@falkben
falkben / fastapi_streaming_responses.py
Last active July 20, 2020 14:24
shows that a StreamingResponse can be cancelled. We can detect whether it has been cancelled by inspecting the generator (if not async) or through exceptions.
import asyncio
import time
import uvicorn
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
app = FastAPI()
@falkben
falkben / test_ports_open.py
Created July 1, 2020 21:51
simple http server for testing open ports
import argparse
from http.server import BaseHTTPRequestHandler, HTTPServer
from socketserver import ThreadingMixIn
from threading import Thread
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
@falkben
falkben / import_todoist.py
Created June 16, 2020 04:34
convert an asana project exported to json into a todoist task list
# %%
import json
import todoist
# %%
projects = [
("backend", "backend"),
("blog", "Blog"),
("deployment", "deployment"),
@falkben
falkben / import_trello.py
Created June 15, 2020 05:10
convert an asana project exported to json into a trello board
# To add a new cell, type '# %%'
# To add a new markdown cell, type '# %% [markdown]'
# %%
import json
import requests
import time
# %%
projects = [
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@falkben
falkben / mesh.py
Last active June 6, 2018 16:54
This script generates a mesh from neuroglancer python scripts
from pathlib import Path
import argparse
import numpy as np
import tifffile as tiff
import neuroglancer
parser = argparse.ArgumentParser(description='create meshes')
parser.add_argument('img_path_str', type=str, help='path to images')
@falkben
falkben / url_scrape.py
Last active November 4, 2017 03:23
scrapes a website for all the URLs below it
''' scrapes a website for urls '''
import requests
from bs4 import BeautifulSoup
class URLTest():
def __init__(self, link, status_code, current_depth, head):
self.link = link
self.status_code = status_code