Skip to content

Instantly share code, notes, and snippets.

@sankalp-khare
sankalp-khare / switch-gnupg.sh
Created July 3, 2023 11:00
Downgrade / switch gnupg version in homebrew and pin it
#!/bin/bash -e
#-------------------------------------------------------------------------------------
# Summary: Executes commands to...
# * Check/output currently installed version of gnupg
# * Change into the brew repo/install directory
# * Find the git commit-id of the specified version of gnupg
# * git branch/switch to the commit-id
# * replace the brew installed version with the specified version (and pin it)
# * clean up the branch, switch back to master, and remove cached files
# * Check/output the newly installed version of gnupg
@jvelezmagic
jvelezmagic / main.py
Created May 17, 2023 12:05
Langchain FastAPI stream with simple memory
# The goal of this file is to provide a FastAPI application for handling
# chat requests amd generation AI-powered responses using conversation chains.
# The application uses the LangChaing library, which includes a chatOpenAI model
# for natural language processing.
# The `StreamingConversationChain` class is responsible for creating and storing
# conversation memories and generating responses. It utilizes the `ChatOpenAI` model
# and a callback handler to stream responses as they're generated.
# The application defines a `ChatRequest` model for handling chat requests,
@nymous
nymous / README.md
Last active May 17, 2024 15:10
Logging setup for FastAPI, Uvicorn and Structlog (with Datadog integration)

Logging setup for FastAPI

This logging setup configures Structlog to output pretty logs in development, and JSON log lines in production.

Then, you can use Structlog loggers or standard logging loggers, and they both will be processed by the Structlog pipeline (see the hello() endpoint for reference). That way any log generated by your dependencies will also be processed and enriched, even if they know nothing about Structlog!

Requests are assigned a correlation ID with the asgi-correlation-id middleware (either captured from incoming request or generated on the fly). All logs are linked to the correlation ID, and to the Datadog trace/span if instrumented. This data "global to the request" is stored in context vars, and automatically added to all logs produced during the request thanks to Structlog. You can add to these "global local variables" at any point in an endpoint with `structlog.contextvars.bind_contextvars(custom

// Please find the full, tested version in
// https://github.com/influxdata/influxdb_iox/blob/fe155e15fb2ad166aee66b0458e63c24a8128dd4/query/src/exec/task.rs#L101-L118
pub struct DedicatedExecutor {
state: Arc<Mutex<State>>,
}
/// Runs futures (and any `tasks` that are `tokio::task::spawned` by
/// them) on a separate Tokio Executor
struct State {
@minad
minad / polyp.md
Last active February 9, 2024 10:51
Polyp: Small child of the Hydra

Polyp: Small child of the Hydra

;; The undo keybindings `C-x u` and `C-_` enter the polyp.
(defpolyp polyp-undo
  "_u_ndo  _r_edo"
  ("u" undo-fu-only-undo "C-x u" "C-_")
  ("r" undo-fu-only-redo))
@mikroskeem
mikroskeem / gccemacs_osx.md
Last active May 12, 2024 15:07
gccemacs on OSX

gccemacs on OS X

Read this first: http://akrl.sdf.org/gccemacs.html

Prerequisites

1) GCC with libgccjit enabled

For that you need to compile gcc (duh). I edited Homebrew's gcc formula:

@karlicoss
karlicoss / init.el
Created September 29, 2019 10:28
Snipped for org-mode agenda to show presence of notes
(with-eval-after-load 'org-agenda
(defun my/org-has-children ()
(if (save-excursion (org-goto-first-child)) "▶" " ")
)
(add-to-list 'org-agenda-prefix-format '(
agenda . "%i%-3:(my/org-has-children) %-12:c%?-12t% s "
))
)
; Result:
@sparkydogX
sparkydogX / occupy-memory.py
Last active March 27, 2024 05:55
Pytorch trick : occupy all GPU memory in advance
import os
import torch
from tqdm import tqdm
import time
# declare which gpu device to use
cuda_device = '0'
def check_mem(cuda_device):
devices_info = os.popen('"/usr/bin/nvidia-smi" --query-gpu=memory.total,memory.used --format=csv,nounits,noheader').read().strip().split("\n")
@xiaolai
xiaolai / jupyter-as-a-desktop-app.md
Last active September 15, 2023 08:37
Run Jupterlab as an desktop app

How to run Jupyterlab as a desktop app on Mac OSX

In Sep, 2021, Jupyterlab Desktop App (electron) was released by Mehmet Bektas (github repo).

brew install --cask jupyterlab

jupyterlab-app-first-opened

@kostaz
kostaz / install-ripgrep-on-ubuntu.sh
Created September 21, 2018 20:33
Install ripgrep on Ubuntu
#!/bin/bash
[[ $UID == 0 ]] || { echo "run as sudo to install"; exit 1; }
REPO="https://github.com/BurntSushi/ripgrep/releases/download/"
RG_LATEST=$(curl -sSL "https://api.github.com/repos/BurntSushi/ripgrep/releases/latest" | jq --raw-output .tag_name)
RELEASE="${RG_LATEST}/ripgrep-${RG_LATEST}-x86_64-unknown-linux-musl.tar.gz"
TMPDIR=$(mktemp -d)
cd $TMPDIR
wget -O - ${REPO}${RELEASE} | tar zxf - --strip-component=1