Skip to content

Instantly share code, notes, and snippets.

View Compro-Prasad's full-sized avatar
🔨
Building stuff. Mostly software.

Compro Prasad Compro-Prasad

🔨
Building stuff. Mostly software.
View GitHub Profile
@Compro-Prasad
Compro-Prasad / base.py
Last active December 10, 2023 13:43
Sqlalchemy base template for FastAPI projects
import os
from typing import Any, AsyncGenerator, Generator
from datetime import datetime
from alembic_utils.pg_trigger import PGTrigger
from alembic_utils.pg_function import PGFunction
from sqlalchemy import create_engine
from sqlalchemy import func
from sqlalchemy.orm import Mapped as T
from sqlalchemy.orm import mapped_column as column
@Compro-Prasad
Compro-Prasad / nginx.conf
Created December 10, 2023 11:16
Nginx proxy config for fastapi
location /prefix-path {
rewrite ^/prefix-path/(.*)$ /$1 break;
# Important to prevent CORS
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
# Unexplored options
#proxy_set_header X-Original-URI $request_uri; # Set the modified URI in X-Original-URI header
#proxy_set_header X-Script-Name /prefix-path;
@Compro-Prasad
Compro-Prasad / alembic-trigger-migration.py
Created March 5, 2023 11:56
Alembic migration to set updated_on field to now() on update in postgresql
"""Create User table
Revision ID: xyz
Revises:
Create Date: 2023-03-05 08:54:17.867180
References:
1. alembic_utils API reference to create trigger: https://olirice.github.io/alembic_utils/api/
2. alembic_utils usage in a migration: https://olirice.github.io/alembic_utils/examples/
@Compro-Prasad
Compro-Prasad / most_recent_values.sql
Created October 9, 2022 11:57
Get most recent non null values from a table
CREATE TABLE table1 (
id BIGSERIAL,
main_id int not null,
created TIMESTAMP DEFAULT NOW(),
value1 VARCHAR,
value2 VARCHAR,
value3 VARCHAR,
);
INSERT INTO table1(main_id, value1) VALUES(1, 'a');
@Compro-Prasad
Compro-Prasad / two-three-consecutive_nonduplicate-split_string.py
Last active July 24, 2022 09:04
Split a given string into 2 and/or 3 letter characters such that no two consecutive strings are duplicates of each other
"""
We can define 2 special types of strings (both consisting of lowercase English letters):
- two_string: string of length 2 (example: "ab","zz")
- three_string: string of length 3 (example: "abc","ghw")
You can create new strings by placing one or several two_strings and three_strings
side by side in a line and without placing two same strings next to one another.
From the example above you can create for example “abzz”, “ababc”, “zzabcghwab” etc.
import random
from collections import defaultdict
from pprint import pprint
from timeit import timeit
def get_configs(n=1000):
a2z = "abcdefghijklmnopqrstuvwxyz"
configs = defaultdict(set)
conds = set()
for _ in range(n):
@Compro-Prasad
Compro-Prasad / stitch.py
Last active January 19, 2020 12:13 — forked from jweir/stitch.py
stitch images in python
"""
First make sure you have the Python Image libraries installed
sudo pip install pillow
Down below you will need to define the absolute path to the images see "dir=..."
Run this by entering
python stitch.py
[Trace - 06:22:39 PM] Sending request 'textDocument/documentSymbol - (64)'.
Params: {
"textDocument": {
"uri": "file:///home/compro/Downloads/github.com/Compro-Prasad/lisp-from-scratch/src/basic_structure.rs"
}
}
[Trace - 06:22:39 PM] Received response 'textDocument/documentSymbol - (64)' in 20ms.
Result: [
use std::collections::HashMap;
type Defun = fn(LispType) -> LispType;
#[derive(Debug, Clone, PartialEq)]
pub enum LispType {
Symbol(String),
Str(String),
RealNumber(f64),
LispDefun(Defun),
@Compro-Prasad
Compro-Prasad / click-text.el
Created June 22, 2019 05:15
How to make clickable text in Emacs?
(defun compro/print-message (event)
"This function runs when you click the text."
(interactive "e")
(message "Hello World"))
(let* ((str "Click Me") ;; The text that will be produced
(str-beg 0) ;; Start position of string
(str-end (string-width str)) ;; End position of string
(map (make-sparse-keymap))) ;; Click event will be registered here
(define-key map [mouse-1] 'compro/print-message) ;; Register click event