Skip to content

Instantly share code, notes, and snippets.

View mcpar-land's full-sized avatar
🤠

John mcpar-land

🤠
View GitHub Profile
@mcpar-land
mcpar-land / running_average.go
Created August 1, 2023 17:23
go running average
package main
import (
"fmt"
"math/rand"
)
func main() {
src := []float64{}
for i := 0; i < 100; i++ {
@mcpar-land
mcpar-land / build.rs
Created June 29, 2023 05:34
add tailwind to rust build script
use std::process::Command;
fn main() {
let tailwind_cmd = "npx tailwindcss -i input.css -o assets/app.css";
if cfg!(target_os = "windows") {
Command::new("cmd").arg("/C").arg(tailwind_cmd).status()
} else {
Command::new("sh").arg("-c").arg(tailwind_cmd).status()
}
@mcpar-land
mcpar-land / uniques_by_col.py
Created March 1, 2023 19:43
Pandas Unique Values By Column
def uniques_by_col(df: pd.DataFrame, drop_columns=[]) -> pd.DataFrame:
u = {}
for col in df.columns.tolist():
if str(col) not in drop_columns:
u[col] = pd.Series([(i[0], v) for i, v in dftxt[[col]].value_counts().iteritems()], dtype="object")
df2 = pd.DataFrame.from_dict(u, orient="index").T.replace({None: np.nan})
col_order = []
for col in df2.columns.tolist():
if str(col) not in drop_columns:
df2[[(str(col), "Val"), (str(col), "Count")]] = pd.DataFrame(df2[col].tolist(), index=df2.index)
@mcpar-land
mcpar-land / main.go
Last active May 23, 2022 16:46
Golang 1.18 undo example
package main
import (
"fmt"
)
func main() {
fmt.Print("Hello, ", "playground\n")
s := AppState{}
a := ActionStack[AppState]{}
@mcpar-land
mcpar-land / main.rs
Created September 7, 2020 16:47
Bevy Ui Crash
use bevy::prelude::*;
pub struct GlobalChildRef(pub Entity);
pub struct GlobalChild;
fn setup(
mut commands: Commands,
mut materials: ResMut<Assets<ColorMaterial>>,
global_child: ResMut<GlobalChildRef>,
) {
@mcpar-land
mcpar-land / menu.tsx
Created July 14, 2020 17:45
React subcomponents with styled-components and typescript
import React from 'react'
import styled from 'styled-components'
const MenuBase = styled.div`
display: flex;
flex-direction: column;
`
const MenuItem = styled.div`
padding: 5px;
@mcpar-land
mcpar-land / ComplicatedComponent.jsx
Last active November 8, 2019 18:11
JSDoc for React functional component props
/**
* @type {React.FC<{
* propertyOne: string,
* propertyTwo: ComplicatedClass<GenericType>,
* propertyThree: any,
* propertyFour: (fxnArg: object) => string
* }>}
*/
const ComplicatedComponent = ({propertyOne, propertyTwo, propertyThree, propertyFour}) => {