Skip to content

Instantly share code, notes, and snippets.

View jinsley8's full-sized avatar

Jon Insley jinsley8

View GitHub Profile
@wpeasy
wpeasy / default-to-list.php
Last active January 5, 2024 07:21
Bricks Default Colors to a List
<?php
add_action('get_footer', function(){
if (!class_exists('Bricks\Capabilities')) {
return;
}
if( !bricks_is_builder() ) return;
?>
@Nerd-Rush
Nerd-Rush / Client editing disclaimer PHP snippet
Last active January 29, 2024 00:15
Dismissable WordPress message to your clients.
// Client editing disclaimer
function custom_admin_notice_with_logo() {
$user_id = get_current_user_id();
if (get_user_meta($user_id, 'custom_notice_dismissed', true) !== 'yes') {
if (current_user_can('administrator') || current_user_can('editor') || current_user_can('author')) {
$nonce = wp_create_nonce('custom_notice_dismiss_nonce');
$image_url = 'https://nerdrush.com/wp-content/uploads/2023/08/Nerd-Rush-Logo-Blue-2023.svg'; // External image URL
?>
<div class="notice notice-warning custom-notice" style="padding-top: 20px;">
<img src="<?php echo esc_url( $image_url ); ?>" alt="Logo" style="width: 120px; display: block; margin-bottom: 10px;">
@zenorocha
zenorocha / invite.ics
Last active September 19, 2024 15:28
Resend with iCal
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
SUMMARY:Access-A-Ride Pickup
DTSTART;TZID=America/New_York:20130802T103400
DTEND;TZID=America/New_York:20130802T110400
LOCATION:1000 Broadway Ave.\, Brooklyn
DESCRIPTION: Access-A-Ride to 900 Jay St.\, Brooklyn
STATUS:CONFIRMED
@wpeasy
wpeasy / main.css
Created October 1, 2023 00:57
Grouping WordPress CPTs
#adminmenu [id*="menu-posts-"]{
background-color: var(--bricks-color-primary);
}
#adminmenu [id*=menu-posts-] > a {
color: black;
}
#adminmenu [id*=menu-posts-] > a .wp-menu-image::before{
color: black;
}
@codingforentrepreneurs
codingforentrepreneurs / nextjs-pbkdf2.js
Created July 18, 2023 16:02
A custom crypto pbkdf2 method for Next.js
/*
Next.js/Edge function method for hasing passwords
Using the Web API Crypto feature instead of
Built-in Node.js Crypto
*/
export default async function pbkdf2(password, salt, iterations, keylen) {
const enc = new TextEncoder();
const passwordBuffer = enc.encode(password);
const saltBuffer = enc.encode(salt);
@codingforentrepreneurs
codingforentrepreneurs / isValidURL.js
Created July 12, 2023 19:58
Verify if a URL is valid or not via Regex in Next.js Server Components
export default async function isValidURL(url, disallowedDomains) {
// Construct a regular expression pattern to match disallowed domains
const disallowedPattern = `^https?:\\/\\/(?:${disallowedDomains.join('|')})\\b`;
let disallowedRegex = new RegExp(disallowedPattern, 'i');
// Regular expression pattern to match a URL (excluding localhost)
const urlPattern = /^(https?:\/\/)?((?!localhost)[\w.-]+)\.([a-z]{2,})(:\d{1,5})?(\/.*)?$/i;
let urlRegex = new RegExp(urlPattern);
// Test the URL against both URL pattern and disallowed domain pattern
@ShinyObjectLabs
ShinyObjectLabs / BaseForm.tsx
Last active August 1, 2024 18:09
Framer Form Component
/*
MIT License
Copyright © Joel Whitaker
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@cullylarson
cullylarson / config.ts
Last active January 30, 2024 14:23
Example configuration file
const stages = ['production', 'staging', 'development', 'test'] as const;
type Stage = typeof stages[number];
function getStage(stages: Stage[]) {
if (!stages.length) return 'production';
for (const stage of stages) {
// if any of the provided stages is production, assume we are in production
if (stage === 'production') {
@MCarlomagno
MCarlomagno / metamask.ts
Last active July 19, 2023 22:36
🦊🪝 React hook for Metamask extension using ethers.js. The hook includes some of the most common use cases such as wallet connection, events listening, transaction, addresses and signer management.
import * as ethers from 'ethers';
import {
ExternalProvider,
JsonRpcSigner,
Network,
Web3Provider
} from '@ethersproject/providers';
import { useState } from 'react';
declare global {
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "@openzeppelin/contracts@4.7.1/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.7.1/access/Ownable.sol";
import "@openzeppelin/contracts@4.7.1/utils/Counters.sol";
contract MyToken is ERC721, Ownable {
using Counters for Counters.Counter;