Skip to content

Instantly share code, notes, and snippets.

View macro6461's full-sized avatar
🏠
WFH

Matthew Croak macro6461

🏠
WFH
View GitHub Profile
@macro6461
macro6461 / HouseContainer.tsx
Last active April 2, 2025 17:22
This is a React Native component with child component to render a nested list of places within a place
import React, { useEffect, useState } from "react";
import { View, Text, FlatList, StyleSheet } from "react-native";
// Data Structure
interface Place {
id: string;
object_type: string;
name: string;
parent_place: string | null;
traps_count: number;
@macro6461
macro6461 / pre-commit
Created December 5, 2024 16:38
The pre-commit git hook python code for queuejs-bfs
#!/usr/bin/env python3
import sys
import json
import re
import subprocess
def get_git_version():
try:
result = subprocess.run(['git', 'describe', '--long', '--tags'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@macro6461
macro6461 / publish_to_npm.py
Created December 4, 2024 21:03
Here is the python script for publishing to NPM in my Github actions
import os
import subprocess
def publish_to_npm():
print("CHECKING NPM TOKEN!!")
npm_token = os.getenv("NPM_TOKEN")
if not npm_token:
print("NPM_TOKEN is not set. Exiting...")
exit(-1)
print(f"NPM_TOKEN: {npm_token}")
@macro6461
macro6461 / popup.js
Created January 18, 2023 20:31
JavaScript pertaining to popup blog post
const constructPopup = () => {
// propbably not the most efficient solution to hiding the popup
// but the code is here if for whatever reason you might want to use it
document.body.innerHTML += popupString;
}
const popupString = `
<div class="popup outer">
<div class="popup inner">
<button class="close">x</button>
@macro6461
macro6461 / popup.html
Created January 17, 2023 16:13
HTML pertaining to blog post about Custom Popup
<!-- reference css styles in header of your HTML file -->
<div class="popup outer">
<div class="popup inner">
<button class="close">x</button>
<!-- add custom popup content below -->
<img src="giphy.gif"/>
<h3>Here is your popop!</h3>
<p>If you liked this tool, please leave a tip or follow me on Medium!</p>
<p>Thanks for using the custom popup!</p>
<a href="https://paypal.me/mattcroak?country.x=US&amp;locale.x=en_US" target="_blank">Paypal</a>
@macro6461
macro6461 / new_changelog_item.sh
Created April 13, 2022 18:04
This is the gist for `new_changelog_item` bash script
new_changelog_item()
{
while read line; do
if [[ $line == "## [Unreleased]"* ]]; then
newvar=$(<<<"$line" sed 's/[].*[]/\\&/g')
echo $newvar
echo "LINE FOUND IN" CHANGELOG.md
sed -i "" "s/$newvar/## [Unreleased]\n\n## [$version] - $date\n### Added\n - ADD CHANGE HERE!/" CHANGELOG.md
return
fi
const genWordList = (text) => {
var str = ''
var wordMap = {}
text.replace(/[^A-Za-z0–9\/]+/g, "").split(" ").forEach(word=>{
var keyToCheck = word.toLowerCase()
if (wordMap[keyToCheck]){
wordMap[keyToCheck] += 1
} else {
wordMap[keyToCheck] = 1
}
import {useState} from 'react';
import Visualization from './Visualization'
import * as htmlToImage from 'html-to-image';
const HtmlToImage = ({data, saveAs, }) =>{
const [time, setTime] = useState(null)
const exportAsPicture = () => {
import {useState} from 'react';
import Visualization from './Visualization'
import html2canvas from "html2canvas";
const HtmlToCanvas = ({data, saveAs}) =>{
const [time, setTime] = useState(0)
const exportAsPicture = () => {
@macro6461
macro6461 / randomnumber.js
Created April 1, 2021 13:10
This is the gist for How to Obtain Random Numbers Within a Range Using JavaScript.
const randomNumber = (a, b) => {
var min = a > b ? b : a
var max = a > b ? a : b
//Use below if final number doesn't need to be whole number
//return Math.random() * (max - min + 1) + min;
return Math.floor(Math.random() * (max - min + 1) + min);
}