Skip to content

Instantly share code, notes, and snippets.

View cwardzala's full-sized avatar
🏠
Working from home

Cameron Wardzala cwardzala

🏠
Working from home
View GitHub Profile
@cwardzala
cwardzala / randomPort.js
Created January 31, 2023 14:42
Random Port JS
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
function newRandomPort() {
document.getElementById("randomport").textContent = "" + getRandomInt(1024, 65534)
}
@cwardzala
cwardzala / useAudio.jsx
Created March 12, 2021 16:10
Basic React hook around `new Audio()`
import React from 'react';
const useAudio = (initialSrc = null) => {
const [src, setSrc] = React.useState(initialSrc);
const [isPlaying, setIsPlaying] = React.useState(false);
const [progress, setProgress] = React.useState(0);
let audio = React.useRef(new Audio());
React.useEffect(() => {
let currentAudio = audio.current;
@cwardzala
cwardzala / yup_helpers.js
Last active June 30, 2022 15:38
Yup helper functions.
import {string, addMethod } from 'yup';
/**
* string().isbn()
* @param {String} message message to display when invalid.
*/
// eslint-disable-next-line no-template-curly-in-string
addMethod(string, 'isbn', function (message = '${path} must be a valid ISBN') {
const rISBN = /(?:(?=.{17}$)97[89][ -](?:[0-9]+[ -]){2}[0-9]+[ -][0-9]|97[89][0-9]{10}|(?=.{13}$)(?:[0-9]+[ -]){2}[0-9]+[ -][0-9Xx]|[0-9]{9}[0-9Xx])/;
return this.matches(rISBN, {
@cwardzala
cwardzala / iubenda-react.js
Created February 28, 2020 18:21
React component to embed Iubenda privacy policy.
const Iubenda = ({
policyId
}) => {
useEffect(() => {
var s = document.createElement("script");
let tag = document.getElementsByTagName("script")[0];
s.src="https://cdn.iubenda.com/iubenda.js";
tag.parentNode.insertBefore(s,tag);
@cwardzala
cwardzala / .posthtmlrc
Created June 11, 2018 19:02
Parcel HTML test
{
"xmlMode": true,
"lowerCaseAttributeNames": false
}
function getSopMonth (asText = false) {
let date = new Date();
let month = date.getUTCMonth() + 1; // date.getMonth() is zero indexed.
let names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
if (asText) {
return names[month];
}
tell application "iTerm"
tell current session of current window
set btm to (split horizontally with default profile)
tell btm
split vertically with default profile
end tell
end tell
end tell
data = {};
$('section.tab-content').each((i, el) => {
let section_data = [];
let title = $(el).find('h2');
let h3s = $(el).find('h3');
let rows = $(el).find('.row-default');
console.log(title.text());
h3s.each((i, h3el) => {
@cwardzala
cwardzala / MusicSync.sh
Last active November 2, 2016 14:17
Music Scripts
#!/bin/bash
rsync --progress --ignore-existing -avzu --exclude=".*/" "/Users/cwardzala/Music/iTunes/iTunes Media/Music" "/Volumes/Shared Media/"
@cwardzala
cwardzala / Slug Iterator.py
Created September 27, 2016 19:40
Slug Iterator created by cwardzala - https://repl.it/X3G/4604
#!/usr/bin/env python
import re
import json
def slugify(title):
title = title.lower()
empties = re.compile('[-\\s]+')
title = empties.sub('-', title)
odds = re.compile('[^\w\s-]')