Skip to content

Instantly share code, notes, and snippets.

View andria-dev's full-sized avatar
:octocat:
surviving under Capitalism, striving for Communism

Andria Brown andria-dev

:octocat:
surviving under Capitalism, striving for Communism
View GitHub Profile
use anyhow::bail;
pub struct Recipe {
template: String,
}
impl Recipe {
const VARIABLES: [&'static str; 4] = ["URL", "SHA", "VERSION", "NEW_CHECK"];
pub fn new(template: String) -> Self {
@andria-dev
andria-dev / confetti.jsx
Created December 20, 2023 04:27
React Tag Prop Pattern
// You can also use TypeScript types to make the rest of ...props match
// what the HTML props or component props would be for that tag.
function Confetti({ tag: Tag, options, ...props }) {
const nodeRef = useRef(null);
/* logic */
return <Tag ref={nodeRef} {...props}>{/* stuff */}</Tag>;
}
@andria-dev
andria-dev / logging.jsx
Last active November 30, 2023 17:23
React Logging Examples
// Same as useEffect in <App> but abstracted
function useLog(...values) {
useEffect(() => {
console.log(...values)
}, values)
}
function App() {
const [todos, setTodos] = useState([]);
@andria-dev
andria-dev / bad_chars.py
Last active July 3, 2021 05:35
Python Buffer Overflow Bad Characters
#!/usr/bin/env python3
"""
# Usage
Copy and paste the below line of code into your Python interpreter and
it will give you a string of all characters from 1 to 255 inclusive that
you can copy and paste into your Python code to generate your payload.
You can also just copy the result that I already have here lol.
"""

Accessibility of Burger Menu Structures

When creating a navigation menu that can be expanded/opened and closed, it is important that the navigation landmark itself, the , remain visible at all times for those using a screen reader that are looking for that landmark. Alongside this, the button that is used to expand the navigation menu needs to be inside of the navigation landmark for the most accessible experience. When the button is inside the , the screen reader user can easily find that button when jumping to the navigation landmark.

@andria-dev
andria-dev / wsl.sh
Last active January 4, 2023 20:18
WSL Config
#!/bin/bash
# function definitions
pressAnyKeyToContinue() {
read -n 1 -s -r -p "Press any key to continue."
}
# Get sudo privileges beforehand
sudo -v
@andria-dev
andria-dev / front-end.jsx
Created February 16, 2021 03:57
Example usage of use-shopping-cart for README
// Front-End: Let's pick our product, ask for a Session ID, and redirect to the checkout page.
import { useShoppingCart, formatCurrencyString } 'use-shopping-cart'
function Product({ product }) {
const { redirectToCheckout } = useShoppingCart()
const { name, image, description, currency } = product
const price = formatCurrencyString({ value: product.price, currency, language: 'en-US' })
async function buyNow() {
const response = await fetch("/.netlify/functions/create-session", {
@andria-dev
andria-dev / Get-NodePackages.ps1
Created November 5, 2020 20:22
A Powershell function to get all of the node dependencies defined in a JSON file that match a pattern.
# Usage: yarn remove $(Get-NodePackages -Pattern 'gatsby')
function Get-NodePackages {
param (
$Pattern = '.*',
$PackagePath = '.\package.json'
)
$package = ConvertFrom-Json $(gc $PackagePath | Out-String)
$dependencies = $package.dependencies ?? @()
$devDependencies = $package.devDependencies ?? @()
@andria-dev
andria-dev / half-precision-floats.js
Last active April 16, 2020 18:04
A function for converting a floating point number into binary (half precision)
// Half Precision Floats
/**
* @description Converts a binary number like: 1100101011000000
* sign | exponent | significand
* 1 | 10010 | 1011000000
*
* back into it's decimal representation, in this case it's -13.5
*
* @param {string} binaryString a binary number in string format
@andria-dev
andria-dev / preact-prop-checker.js
Last active November 30, 2018 00:30
A simple preact prop checker that uses custom functions to verify props.
import preact from 'preact';
function printWarning(message) {
message = `Warning: ${message}`;
if (typeof console !== 'undefined') {
console.error(message);
}
}
// installs global prop checker