Skip to content

Instantly share code, notes, and snippets.

View dmontero's full-sized avatar

Diego Montero dmontero

  • Montevideo, URUGUAY
View GitHub Profile
@dmontero
dmontero / SecurityController.php
Created October 27, 2021 06:05 — forked from stenno/SecurityController.php
Getting role hierarchy of logged in user in Symfony 5
<?php
namespace App\Controller;
use Symfony\Component\Security\Core\Role\RoleHierarchyInterface;
class SecurityController extends AbstractController
{
await axios.post(`${process.env.SHERPA_BASE_URL}/oauth/v2/token`, params)
.then((response)=>{
console.log(response.data)
})
.catch((error) => {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.log(error.response.data);
console.log(error.response.status);
@dmontero
dmontero / back-closes-modal.js
Created May 30, 2020 11:06
Let browser's back button close open modal. Great for bootstrap projects for Android, since users expect modals to close when hitting back
$(document).ready(function(){
// ==== CLOSES BOOTSTRAP MODAL WITH BACK BUTTON ====
let modal = $('div.modal');
modal.on('show.bs.modal', function() {
let modal = this;
window.location.hash = modal.id;
window.onhashchange = function() {
if (!location.hash){
$(modal).modal('hide');
}
@dmontero
dmontero / autobackupMysql2S3.sh
Last active May 8, 2020 12:06
Makes a full backup of mySQL databases, transfer the backup to a S3 bucket and removes old files from local
#!/bin/sh
#
# REMEMBER:
# give this file permissions chmod +x thisfile.sh
# install s3cmd sudo apt-get s3cmd
# configure s3cmd s3cmd --configure
# add this file to cron crontab -e
FILE=database.sql.`date +"%Y%m%d"`.gz
@dmontero
dmontero / ajax-form.js
Last active December 16, 2015 09:58 — forked from havvg/ajax-form.js
Permite el envio de cualquier formulario por ajax
jQuery(function($) {
$('form[data-async]').live('submit', function(event) {
var $form = $(this);
var $target = $($form.attr('data-target')); // Esto no lo necesito
$.ajax({
type: $form.attr('method'),
url: $form.attr('action'),
data: $form.serialize(), //En lugar de serialize pasarlo como ajax. Que pasa con los tildes?