Skip to content

Instantly share code, notes, and snippets.

View emma-k-alexandra's full-sized avatar
⌨️
Starting more projects than I can finish

Emma K Alexandra emma-k-alexandra

⌨️
Starting more projects than I can finish
View GitHub Profile
@emma-k-alexandra
emma-k-alexandra / zip-the-worst-way.js
Created January 17, 2024 03:27
Fun with Object.groupBy and Map.groupBy
/**
* This is a fun attempt to implement a `zip` function using the new Object.groupBy and Map.groupBy functions because I hate index math.
*/
/**
* A silly implementation of zip using [Object.groupBy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy).
*
* It's zip! Great explanation here of the Python implementation (which is better than this one)
* @see https://docs.python.org/3.3/library/functions.html#zip
*
@emma-k-alexandra
emma-k-alexandra / Request
Created October 12, 2022 22:21
Trains to New Carrollton return `null` `DestinationCode` from GetPredictions JSON endpoint in WMATA API
GET https://api.wmata.com/StationPrediction.svc/json/GetPrediction/K06 HTTP/1.1
Host: api.wmata.com
api_key: API_KEY_HERE
@emma-k-alexandra
emma-k-alexandra / forward-to-trailing-slash-plugin.js
Last active September 26, 2023 12:33
Vite multi-page app trailing slash dev server workaround for https://github.com/vitejs/vite/issues/6596
/**
* Forwards routes in the given list to a route with a trailing slash in the dev server
* Useful for multi page vite apps where all rollup inputs are known.
*
* Vite fix is upcoming, which will make this plugin unnecessary
* https://github.com/vitejs/vite/issues/6596
*/
export default routes => ({
name: 'forward-to-trailing-slash',
configureServer(server) {
@emma-k-alexandra
emma-k-alexandra / View+Size.swift
Created January 17, 2022 21:11
Assign the size of a SwiftUI View to a Binding - Based on Federico Zanetello's `readSize`
import SwiftUI
/*
Example
struct MyView: View {
@State private var childSize = CGSize.zero
var body: some View {
ChildView()
@emma-k-alexandra
emma-k-alexandra / scrollama-web-components.html
Created March 17, 2021 02:49
Scrollama + Web Components
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scrollama + Web Components</title>
</head>
<body>
<!-- The web component -->
@emma-k-alexandra
emma-k-alexandra / cscsw_cva.csv
Last active April 24, 2022 16:56
UPDATE: Please check this folder for more IDs (4/24/22): https://github.com/emma-k-alexandra/Laundry-IDs/tree/main/output All CSC Service Works CVAs available (as of February 15th, 2021) to revalue card via https://www.sdirevalue.com/JustPurchaseCode.aspx Place value in column "cva" into the "CVA ID" field
address name cva
9700 Sumac Road Des Plaines IL 60016 Glen Oaks Apts 1
9700 Sumac Road Des Plaines IL 60016 Glen Oaks Apts 2
9700 Sumac Road Des Plaines IL 60016 Glen Oaks Apts 3
9700 Sumac Road Des Plaines IL 60016 Glen Oaks Apts 4
9700 Sumac Road Des Plaines IL 60016 Glen Oaks Apts 5
9700 Sumac Road Des Plaines IL 60016 Glen Oaks Apts 6
9700 Sumac Road Des Plaines IL 60016 Glen Oaks Apts 7
733 Bode Circle Hoffman Estates IL 60169 Autumn Chase Apts 10
755 Bode Circle Hoffman Estates IL 60169 Autumn Chase Apts 11
import SwiftUI
// View to split up a string into Text views, split by spaces.
struct ContentText: View {
private var splitText: [String]
let count: Int
init(_ text: String) {
self.splitText = text.split(separator: " ").map { "\($0) " }
if text.hasPrefix(" ") {
// Determine the alignment of every view in the ZStack
func zStackViews(_ geometry: GeometryProxy) -> some View {
// These are used to track the current horizontal and vertical position
// in the ZStack. As a new text or link is added, horizontal is decreased.
// When a new line is required, vertical is decreased & horizontal is reset to 0.
var horizontal: CGFloat = 0
var vertical: CGFloat = 0
// Determine the alignment for the view at the given index
func forEachView(_ index: Int) -> some View {
let numberOfViewsInContent: Int
let view: AnyView
// Determine the number of views in the Content at the given index
switch content[index] {
case .text(let text):
numberOfViewsInContent = text.count
view = AnyView(text)
case .link(let link):
numberOfViewsInContent = 1
...
var body: some View {
VStack {
GeometryReader { geometry in
// Needs to be .topLeading so we can modify alignments on top and leading
ZStack(alignment: .topLeading) {
self.zStackViews(geometry)
}
.background(calculateHeight($height))
}