Skip to content

Instantly share code, notes, and snippets.

@secemp9
secemp9 / vogel_approximation.py
Last active January 19, 2024 09:26
Vogel algorithm for transportation problem
import math
supply = [50, 60, 50, 50]
demand = [30, 20, 70, 30, 60]
costs = [
[16, 16, 13, 22, 17],
[14, 14, 13, 19, 15],
[19, 19, 20, 23, 50],
[50, 12, 50, 15, 11]
@secemp9
secemp9 / colab_empty_gpu_memory.py
Created January 7, 2024 09:09
colab trick to empty gpu memory
# Run this block to make sure you have the full GPU memory.
# See https://medium.com/@oribarel/getting-the-most-out-of-your-google-colab-2b0585f82403.
# memory footprint support libraries/code
!ln -sf /opt/bin/nvidia-smi /usr/bin/nvidia-smi
!pip install gputil
!pip install psutil
!pip install humanize
import psutil
import humanize
@secemp9
secemp9 / colab
Last active December 27, 2023 17:43
colab trick
#@title <-- Tap this if you play on Mobile { display-mode: "form" }
%%html
<b>Press play on the music player to keep the tab alive, then start code below</b><br/>
<audio src="https://raw.githubusercontent.com/KoboldAI/KoboldAI-Client/main/colab/silence.m4a" controls>
@secemp9
secemp9 / tkinter_tabs_editor4.py
Created December 26, 2023 08:03
tkinter tabs editor
import tkinter as tk
from tkinter import simpledialog
class TabBar(tk.Canvas):
def __init__(self, master):
super().__init__(master, height=20, bg='grey', xscrollincrement=20)
self.configure(highlightthickness=0)
self.tabs_frame = tk.Frame(self, bg='grey')
self.tabs_window = self.create_window((0, 0), window=self.tabs_frame, anchor="nw")
@secemp9
secemp9 / tkinter_tabs_editor3.py
Created December 25, 2023 19:08
tkinter tabs editor
import tkinter as tk
from tkinter import ttk
from tkinter import NE, LEFT, RIGHT
class ScrollableNotebook(ttk.Frame):
def __init__(self, parent, *args, **kwargs):
ttk.Frame.__init__(self, parent, *args)
self.xLocation = 0
self.notebookContent = ttk.Notebook(self, **kwargs)
self.notebookContent.pack(fill="both", expand=True)
@secemp9
secemp9 / tkinter_tabs_editor2.py
Created December 25, 2023 17:13
another tkinter editor with tabs
import tkinter as tk
from tkinter import ttk
from tkinter import NE, LEFT, RIGHT
class ScrollableNotebook(ttk.Frame):
def __init__(self, parent, *args, **kwargs):
ttk.Frame.__init__(self, parent, *args)
self.xLocation = 0
self.notebookContent = ttk.Notebook(self, **kwargs)
self.notebookContent.pack(fill="both", expand=True)
@secemp9
secemp9 / tkinter_tabs_editor.py
Created December 25, 2023 16:41
tkinter text editor with tabs
import tkinter as tk
from tkinter import ttk
tab_count = 1
def create_tab():
global tab_count # Access the global tab_count variable
tab = ttk.Frame(notebook)
notebook.add(tab, text=f"<Untitled> {tab_count}") # Use tab_count in the tab text
text_widget = tk.Text(tab)
@secemp9
secemp9 / bench_numpy_panda.py
Created December 20, 2023 19:11
Timing some functions from Python, pandas and numpy
import pandas as pd
import numpy as np
import timeit
import platform
# Printing versions of python, numpy, etc
python_version = platform.python_version()
numpy_version = np.__version__
pandas_version = pd.__version__
@secemp9
secemp9 / numpy_serialize.py
Created December 19, 2023 14:03
numpy instance serialize
import sys
import json
import numpy as np
def improved_default(data):
"""
Improved function to handle numpy data types for JSON serialization.
Converts numpy integer and float types to their native Python counterparts.
"""
if isinstance(data, np.integer):
@secemp9
secemp9 / geotest.py
Last active December 6, 2023 15:46
Pulling map data with osmnx
import osmnx as ox
location = "Manhattan, New York City, New York, USA"
# Mode can be 'drive', 'bike', 'walk', etc.
G = ox.graph_from_place(location, network_type='drive')
nodes, edges = ox.graph_to_gdfs(G)
print(nodes.head())
print(edges.head())