Skip to content

Instantly share code, notes, and snippets.

View richban's full-sized avatar
:octocat:

richban richban

:octocat:
View GitHub Profile
@richban
richban / profile.py
Created July 11, 2023 10:59
LineProfiler decorator
from functools import wraps
from line_profiler import LineProfiler
def profile(follow=[]):
def decorator(func):
@wraps(func)
def profiled_func(*args, **kwargs):
try:
@richban
richban / get_or_create_token.sh
Created May 18, 2023 09:21
Get authtoken from a Django App running inside a docker container
#!/bin/bash
# Get the container ID
container_id=$(docker ps -aqf "name=geo-django-1")
# If container is not running
if [ -z "$container_id" ]; then
echo "Container is not running."
exit 1
fi
@richban
richban / Dockerfile
Created August 26, 2022 13:15
Dockerfiles
FROM rocker/r-ver:4.1.0
RUN apt-get update \
&& apt-get install -y --no-install-recommends apt-utils \
default-jre \
zlib1g-dev \
libgit2-dev \
libstdc++6 \
libpng-dev \
libxml2-dev \
@richban
richban / performance.sql
Last active August 17, 2022 11:11
Postgres SQL queries
SELECT
calls,
rows,
ROUND((total_time::numeric / 1000 / 60), 4) AS total_min,
-- newer versions of PostgreSQL have mean_exec_time field, don't need to calculate
--ROUND((total_exec_time / 1000 / calls)::numeric, 4) AS average_secs,
ROUND(mean_time::numeric / 1000 / 60, 4) AS average_min,
ROUND(min_time::numeric / 1000 / 60, 4) AS min_min,
ROUND(max_time::numeric / 1000 / 60, 4) AS max_min,
ROUND(stddev_time::numeric / 1000 / 60, 4) AS stddev_min,
@richban
richban / flake.nix
Last active September 23, 2022 10:52
Nix flakes for Python projects and development
{
description = "Flake to manage python environment";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
mach-nix.url = "mach-nix/3.5.0";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs@ { self, nixpkgs, mach-nix, flake-utils, ... }: