Skip to content

Instantly share code, notes, and snippets.

View thehappycheese's full-sized avatar

thehappycheese

  • Western Australia
View GitHub Profile
@thehappycheese
thehappycheese / git_wrapper.py
Last active May 8, 2024 03:22
A simple python wrapper for git that helps build synthetic repos based on snapshots of some folder
from __future__ import annotations
import subprocess
from pathlib import Path
from typing import Optional
import os
from dataclasses import dataclass
from deprecated import deprecated
from pandas import Timestamp
# This works... but cant read the output array in the final step! :(
# Experimental!
UserLib ← &ffi ⊂□"User32.dll"
GdiLib ← &ffi ⊂□"Gdi32.dll"
KernelLib ← &ffi ⊂□"Kernel32.dll"
MessageBoxA ← UserLib {"int" "MessageBoxA" "long" "const char*" "const char*" "unsigned int"}
# MessageBoxA {0 "Yes Please" "About to Take A Screenshot" 0}
GetSystemMetrics ← UserLib {"int" "GetSystemMetrics" "int"}
GetDeviceContext ← UserLib {"long long" "GetDC" "long"}
@thehappycheese
thehappycheese / pandas_aoihttp.py
Created February 19, 2024 03:50
pandas_aoihttp
import pandas as pd
import asyncio
from aiohttp import ClientSession, TCPConnector
@pd.api.extensions.register_series_accessor("aiohttp")
class AiohttpAccessor:
def __init__(self, pandas_obj):
self._obj = pandas_obj
async def _fetch_text(self, url: str, session):
@thehappycheese
thehappycheese / Mendelbressenuiuabrott.ua
Created December 26, 2023 19:02
Mendelbressenuiuabrott
# pairwise coefficient of interpolation
Interp ← ÷:⊃(-≡⊢|≡/-)◫2
MarchingSquares ← (
:
⊃(
≡(◫2)Interp
| ◫2⍜⍉Interp
| ≡≡(°⋯♭)◫2_2> # types
| ≡°⍉⍉⊞⊟∩(⇡-1)⊃(⊢⇌|⊢)△
@thehappycheese
thehappycheese / split_dataframe_by_weighted_sequence.py
Created November 17, 2023 03:29
Split DataFrame by Weighted Sequence
import pandas as pd
def split_dataframe_by_weighted_sequence(
df:pd.DataFrame,
split_column:str,
weight_column:str,
skew:float=0.5
):
"""
Split a dataframe into two parts by a sequence of values and a sequence of weights.
from pathlib import Path
import keyring
import pandas as pd
import os
import sys
# You need access to the compiled .NET AdomdClient .dll
# You can get it using nuget
# ```powershell
# nuget.exe install Microsoft.AnalysisServices.AdomdClient.retail.amd64
# nuget.exe install Microsoft.AnalysisServices.Tabular
@thehappycheese
thehappycheese / prompt.ps1
Created October 23, 2023 10:21
Shorten powershell prompt for tutorials
function prompt {
$currentPath = (Get-Location).Path
$driveLetter = $currentPath.Substring(0,1)
$folderName = Split-Path $currentPath -Leaf
"$driveLetter:/.../$folderName> "
}
@thehappycheese
thehappycheese / serve_once.py
Created October 10, 2023 05:51
Starts a thread and serves the given data just once before closing the thread. Use with Selenium.
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
def serve_once(data:str, port=8000, host="127.0.0.1"):
"""
Serves the given data on the given port and host, then returns after
responding to one request.
This is a helpful way to send HTML to a browser being controled using Selenium.
"""
@thehappycheese
thehappycheese / get_arcgis_layer_as_geopandas.py
Created March 30, 2023 03:05
Fetch arcgis rest open data as geopandas dataframe
#pip install pandas geopandas arcgis arcgis2geojson
import json
import geopandas as gpd
from geopandas import GeoDataFrame
from arcgis.features import FeatureLayer
from arcgis2geojson import arcgis2geojson
def get_arcgis_layer_as_geopandas(url:str) -> GeoDataFrame:
layer = FeatureLayer(url)
@thehappycheese
thehappycheese / calculate_nickmapbi_offset.py
Created March 28, 2023 05:04
Function to calculate approximate lane offset from carriageway and xsp
def calculate_nickmapbi_offset(carriageway, xsp):
return {
"L":{
f"L{num+1}": +3.5/2 - 3.5*num for num in range(0,7)
},
"R":{
f"R{num+1}": -3.5/2 + 3.5*num for num in range(0,7)
},
"S":{
f"L{num+1}": -3.5/2 - 3.5*num for num in range(0,7)