Skip to content

Instantly share code, notes, and snippets.

View samhernandez's full-sized avatar
🎈

Sam Hernandez samhernandez

🎈
  • Precocity LLC
  • Plano TX
  • X @sam_h
View GitHub Profile
@samhernandez
samhernandez / mysqlsync
Last active March 22, 2024 16:14
Sync remote mysql database to local over ssh
#!/bin/bash
# This script assumes you have ssh access to a remote server
# Both databases are backed up to sql files in the same directory
# this script is executed from.
# Usage:
# 1. Make sure this file is executable with `chmod +x mysqlsync`
# 2. Set the credentials for the variables at the top
# (Remember, no spaces around the '=' sign)
# 3. Run it from a directory where you'd like the backup files to go:
@samhernandez
samhernandez / useDevBgImage.jsx
Created October 16, 2023 21:32
useDevBgImage() React hook
import { useEffect, useState } from "react";
function useDevBgImage(src) {
const [bgTop, setBgTop] = useState(0);
const [opacity, setOpacity] = useState(100);
useEffect(() => {
document.getElementById('root').style.opacity = String(opacity / 100);
}, [opacity]);
@samhernandez
samhernandez / customroutes.php
Last active October 10, 2023 10:11
A simple class to add custom routes to Wordpress.
<?php
/**
* NOTE: This gist is very old. You might want to check out recent forks
* like this one: https://github.com/Alexlytle/Wordpress_custom_route/blob/main/Wordpress_Custom_route.php
* (thanks @Alexlytle) If you have an improvement to this gist, please
* post a link in a comment for others who might benefit. Thanks!
*
* A class to create simple custom routes.
*
@samhernandez
samhernandez / haxor.twig
Last active December 2, 2022 21:40
Craft 3 gain access to admin account for support cases or when owner loses access
{#
Resets the username, password, and email address
of the first found Admin account in case of
lost admin access or for support cases.
#}
{% set values = {
username: 'me',
password: craft.app.security.hashPassword('mypassword'),
email: 'me@site.com',
passwordResetRequired: 0
@samhernandez
samhernandez / craft-contact-form-axios.html
Last active October 20, 2022 07:45
Craft Contact Form with Axios
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Contact Form Plugin Example with Axios</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
</head>
<body>
<!--
@samhernandez
samhernandez / MampHelper.php
Last active July 21, 2022 06:00
Craft CMS v3, MAMP, and mysqldump for database backups
<?php
namespace modules;
use Craft;
/**
* MAMP Helper class.
* File: /modules/MampHelper.php
*
* MySQL database backups triggered from the Craft 3 Control Panel fail because,
@samhernandez
samhernandez / round-to-nearest.js
Created May 30, 2013 16:59
Round a number to the nearest interval of a given number. (Because I always forget how darned simple this is.)
/**
* Returns the number rounded to the nearest interval.
* Example:
*
* roundToNearest(80, 100); // 100
* roundToNearest(25, 15); // 30
*
* @param {number} value The number to round
* @param {number} interval The numeric interval to round to
* @return {number}
@samhernandez
samhernandez / StopEmailModule.php
Last active December 21, 2021 03:33
Craft CMS 3 - stop sending all emails
<?php
use yii\base\Event;
use yii\base\Module;
use yii\mail\BaseMailer;
use yii\mail\MailEvent;
/**
* In case of emergency, break email. :)
*
@samhernandez
samhernandez / UploadProfileWithBase64AvatarController.php
Last active November 4, 2021 14:55
Upload base64 image from front-end profile form with CraftCMS
<?php
use craft\base\Element;
use craft\db\Query;
use craft\db\Table;
use craft\elements\Asset;
use craft\elements\Entry;
use craft\errors\ImageException;
use craft\helpers\Assets;
use craft\helpers\FileHelper;
@samhernandez
samhernandez / Module.php
Created September 6, 2019 19:24
Craft CMS - conditionally propagate entry and category titles
<?php
// File: modules\Module.php
namespace modules;
use Craft;
use craft\base\Element;
use craft\elements\Category;
use craft\elements\Entry;
use yii\base\Event;