Skip to content

Instantly share code, notes, and snippets.

@fhk
fhk / gemini_geograph.py
Created August 20, 2024 01:03
gemini_geograph.py
import momepy
import geopandas as gpd
def create_graph(linestrings):
gdf = gpd.GeoDataFrame(geometry=linestrings)
graph = momepy.gdf_to_nx(gdf, approach="primal")
return graph
from shapely.geometry import LineString, Point
from shapely.ops import unary_union
from geopy.distance import geodesic
def snap_to_nearest_node(point, nodes, tolerance):
for node in nodes:
if geodesic((point.y, point.x), (node.y, node.x)).meters <= tolerance:
return node
return point
@fhk
fhk / Broadband.md
Created May 23, 2024 17:16
Broadband Plan

First Steps for a Citywide Fiber Network

Here's a breakdown of the initial steps you'd take to initiate a citywide fiber project, incorporating elements from the provided feasibility studies and focusing on funding, ISP evaluation, and infrastructure considerations:

Phase 1: Strategy & Policy Development

  1. Establish a Broadband Policy: Define the city's vision for broadband. This should cover:
  • Goals: Ubiquity, affordability, competition, open access, desired speeds, and financial sustainability.
  • Roles: The city's role as owner, facilitator, or partner.
  • Community Engagement: Processes for gathering public input and ongoing communication.
# Some quick snippets for points to lines
address_df = pd.DataFrame([[0, Point([c for c in h3.cell_to_latlng(h3_8)[::-1]])]], columns=['id', 'geometry'])
address_gdf = gpd.GeoDataFrame(address_df, geometry="geometry", crs="epsg:4326")
gdf = gpd.read_file(
"./data/all_the_data.fgb",
engine="pyogrio", bbox=location_box)
gdf = gdf.to_crs('epsg:3310') # https://epsg.io/3310
@fhk
fhk / trello_2csv.py
Created March 8, 2023 19:16
Yay JSON export isn't premium but csv is. Lets just move some data...
import sys
import json
import csv
def main():
input_json = sys.argv[1]
output_csv_data = [['name', 'lastdate', 'desc', 'shorturl']]
with open(input_json, mode='r') as ijson:
data = json.load(ijson)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fhk
fhk / IncreasingCostMST_Generator.py
Created April 22, 2022 16:57 — forked from niroyb/IncreasingCostMST_Generator.py
Searches a graph and yields all the minimum spanning trees in order of increasing cost. This could be used to solve minimum spanning trees with constraints by yielding trees until we reach the first one which satisfies a constraint. For example it could solve the degree constrained minimum spanning tree DCMST
#!/Usr/bin/env python
# -*- coding: utf-8 -*-
'''
Searches a graph and yields all the minimum spanning trees in order of increasing cost.
This could be used to solve minimum spanning trees with constraints by yielding trees until
we reach the first one which satisfies a constraint.
For example it could solve the degree constrained minimum spanning tree DCMST
'''
wget https://golang.org/dl/go1.16.7.linux-amd64.tar.gz;
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.7.linux-amd64.tar.gz;
export PATH=$PATH:/usr/local/go/bin;
export GOPATH=$HOME/go;
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin;
go get github.com/fraugster/parquet-go/cmd/csv2parquet;
@fhk
fhk / lp_solver_wasm.md
Last active May 16, 2024 18:28
Compiling a linked linear programming solver library

Linear Programming Solver running in the browser?

So I wanted to see if I could get a solver running in the browser.

Why you might ask? Well its pretty typical to need to deploy a back end for a webapp or even to have a specific install on your OS.

This makes things clunky if we wanted to say:

  1. Visualize solutions in realtime using some js libs on the client side
  2. Solve models on the client side of a web app
@fhk
fhk / Cali_broadband.ipynb
Created January 7, 2019 20:23
Cali_broadband
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.