Skip to content

Instantly share code, notes, and snippets.

View robertosanval's full-sized avatar

Roberto Santana robertosanval

  • Spain
View GitHub Profile
@nicomollet
nicomollet / gravity-forms-use-woocommerce-email-template-for-notifications.php
Last active December 12, 2023 04:49
Gravity Forms: Use WooCommerce emails templates for notifications
<?php
/**
* Gravity Forms: Use WooCommerce emails templates for notifications.
*
* @param string $template
*
* @return string
*/
public function custom_gform_html_message_template_pre_send_email( string $template ) {
@jhoff
jhoff / Enums.php
Last active November 18, 2023 20:47
Laravel Model Enumeration Trait
<?php
namespace App\Traits;
use Illuminate\Support\Str;
use App\Exceptions\InvalidEnumException;
trait Enums
{
/**
@alesf
alesf / blog.md
Last active September 16, 2023 07:28
Laravel - Eloquent: Cascading delete, forceDelete and restore

If you want to delete a model with related models you can use Laravel model events. There is also a special case if your models cascade.

Lets say you have Folder and File Eloquent models that are related and use SoftDeletes trait and when you delete a folder you also want to delete files in folder and all subfolders with files.

In the boot method or Folder model you catch delete and restore events (actually deleting and restoring events that trigger before restoring or deleting happens). You can delete/restore all files in folder you're deleting/restoring with $folder->files()->delete(); and $folder->files()->withTrashed()->restore();.

Folders on the other hand cascade (folder in a folder in a folder) and because events do not trigger if you don't pull the models (->get() method), the model events won't trigger for subfolders. That's why you need to pull the folders and iterate trough them (->each() method) and delete/restore them.

You could use database CASCADE feature but that does

@enekochan
enekochan / LoginController.php
Last active October 22, 2015 12:38
Autologin URL with random hash for FOSUserBundle
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
@Remiii
Remiii / README.md
Last active March 6, 2024 19:52
How to delete Vault (AWS Glacier) 🗻

How to delete Vault (AWS Glacier)

This Gist give some tips in order to remove AWS Glacier Vault with AWS CLI (ie. https://aws.amazon.com/en/cli/).

Step 1 / Retrive inventory

$ aws glacier initiate-job --job-parameters '{"Type": "inventory-retrieval"}' --vault-name YOUR_VAULT_NAME --account-id YOUR_ACCOUNT_ID --region YOUR_REGION
@jamesdixon
jamesdixon / custom-fonts.php
Created March 9, 2015 21:54
Wordpress Allow Custom Font Upload
<?php
// add to your theme's functions.php file
add_filter('upload_mimes', 'add_custom_upload_mimes');
function add_custom_upload_mimes($existing_mimes) {
$existing_mimes['otf'] = 'application/x-font-otf';
$existing_mimes['woff'] = 'application/x-font-woff';
$existing_mimes['ttf'] = 'application/x-font-ttf';
$existing_mimes['svg'] = 'image/svg+xml';
$existing_mimes['eot'] = 'application/vnd.ms-fontobject';
return $existing_mimes;
@rojan
rojan / node_crypto.js
Last active March 19, 2023 15:14
Encrypt in nodejs and decrypt in php or vice versa
var crypto = require('crypto');
var key = 'MySecretKey12345';
var iv = '1234567890123456';
var cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
var text = 'plain text';
var encrypted = cipher.update(text, 'utf8', 'binary');
encrypted += cipher.final('binary');
hexVal = new Buffer(encrypted, 'binary');
@Sets88
Sets88 / get_mac_vendors_list.py
Last active February 11, 2023 06:13
Get MAC address vendor list from ieee and place it into sqlite3 database
#! /usr/bin/python
import os
import sys
import urllib2
import re
import sqlite3
def get_mac_table_file(filename="oui.txt"):
request = urllib2.urlopen("http://standards.ieee.org/develop/regauth/oui/oui.txt")
with open(filename, "w") as f:
@marydn
marydn / LoginSuccessHandler.php
Created December 20, 2013 20:57
Custom URL redirect by role after success login on Symfony 2 using a service listener without FOSUser Bundle.
# src/Acme/DemoBundle/Security/Authentication/Handler/LoginSuccessHandler.php
<?php
namespace Acme\DemoBundle\Security\Authentication\Handler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\SecurityContext;
@duncansmart
duncansmart / progressive-ace.htm
Created March 28, 2013 23:29
Integrating ACE Editor in a progressive way
<textarea name="my-xml-editor" data-editor="xml" rows="15"></textarea>
...
<textarea name="my-markdown-editor" data-editor="markdown" rows="15"></textarea>
...
<script src="//d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js"></script>
<script>
// Hook up ACE editor to all textareas with data-editor attribute
$(function () {