Skip to content

Instantly share code, notes, and snippets.

View agustinprosperi's full-sized avatar

Agustin Prosperi agustinprosperi

View GitHub Profile
@agustinprosperi
agustinprosperi / example-translate.java
Created August 8, 2024 10:49
Ednpoint para obtener traducciones de un archivo en formato JSON para otro properties
@CrossOrigin
@RestController
@RequestMapping("/api/example")
public class Exampleresource {
@GetMapping(path = "/translate", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> translate() {
// String result = "Ok";
String file1Path = "src/main/resources/transfile1.txt";
String file2Path = "src/main/resources/transfile2.txt";
<?php
/**
* Funciones utiles
*/
if (!defined('ABSPATH')) {
exit('No direct access allowed');
}
if (!defined('TT_SESSION_TRANSIENT_KEY')) {
$cookie_key = 'tt_sesiones_' . COOKIEHASH;
$session_transient_key = !empty($_COOKIE[$cookie_key]) ? $_COOKIE[$cookie_key] : '';
@agustinprosperi
agustinprosperi / cmb2_metaboxes.php
Created August 1, 2022 14:35
Snippets para cmb2
<?php
/**
* Limitar maximo de items de un group field con la opcion rows_limit
* @param array $cmb_id The current box ID.
* @param int $object_id The ID of the current object.
* @param string $object_type The type of object you are working with.
* @param array $cmb This CMB2 object.
*/
add_action('cmb2_after_form', 'js_limit_group_repeat', 10, 4);
function js_limit_group_repeat($cmb_id, $object_id, $object_type, $cmb) {
Gracias por darte de alta. Muy pronto recibirás nuestras noticias.
Thank you for signing up. You will receive our news very soon.
Hubo un error intentando enviar tu mensaje. Por favor inténtalo de nuevo más tarde.
There was an error trying to send your message. Please try again later.
Introduce tu dirección de e-mail.
Enter your email address.
Hubo un error intentando enviar tu mensaje. Por favor inténtalo de nuevo más tarde.
// extensions installed
Alignment
Auto Close Tag
js-beautify for VS Code
vscode-expand-region
highlight-matching-tag
Path Intellisense
Intelephense
vscode-phpcs
phpfmt for Visual Studio Code
@agustinprosperi
agustinprosperi / utiles_cortos.php
Last active May 12, 2020 11:51
tt_reorder_multiarray_by_numeric_subvalue
<?php
// tt_reorder_multiarray_by_numeric_subvalue
function tt_reorder_multiarray_by_numeric_subvalue($matriz, $subkey){
function cmp($key) {
return function($a, $b) use ($key){
$an = intval($a[ $key ]);
$bn = intval($b[ $key ]);
if($an==$bn){
return 0;
}
@agustinprosperi
agustinprosperi / list_upload_dir-tt_lower_image_weight.php
Created January 20, 2017 14:47
Listar archivos recursivamente y reducir tamaño de imágenes con Imagick
<?php
// Listar archivos recursivamente y reducir tamaño de imágenes con Imagick
if( isset($_GET['list_upload_dir']) )
add_action( "init", "list_upload_dir" );
function list_upload_dir(){
$wud = wp_upload_dir();
$iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $wud['basedir'] ) );
$i = 0;
echo'<meta charset="UTF-8">';
echo'<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">';
@agustinprosperi
agustinprosperi / add_rewrite_rule-y-add_rewrite_tag.php
Last active January 16, 2017 09:35
Custom add_rewrite_rule y add_rewrite_tag para url personalizadas
<?php
// custom add_rewrite_rule y add_rewrite_tag
add_action('init', 'custom_rewrite_rule');
function custom_rewrite_rule() {
$rp = getFirstPostByTemplate('template-revistas.php');
if( empty($rp) ) return false;
$param1 = 'categoria';
$param2 = 'entrada';
add_rewrite_tag('%'.$param1.'%', '([^&]+)');
add_rewrite_tag('%'.$param2.'%', '([^&]+)');
@agustinprosperi
agustinprosperi / wp_get_current_page_url.php
Created January 3, 2017 17:06 — forked from leereamsnyder/wp_get_current_page_url.php
In WordPress, get current URL including query string
<?php
/**
Re-use some existing WordPress functions so you don't have to write a bunch of raw PHP to check for SSL, port numbers, etc
Place in your functions.php (or re-use in a plugin)
If you absolutely don't need or want any query string, use home_url(add_query_arg(array(),$wp->request));
Hat tip to:
+ http://kovshenin.com/2012/current-url-in-wordpress/
@agustinprosperi
agustinprosperi / wp_insert_attachment.php
Created November 29, 2016 10:31
wp_insert_attachment from an existing file
<?php
add_action( 'init', function(){
if( !isset($_GET['test_adjuntar']) ) return false;
if ( !function_exists('media_sideload_image') ){
require_once( ABSPATH.'/wp-admin/includes/media.php' );
require_once( ABSPATH.'/wp-admin/includes/file.php' );
require_once( ABSPATH.'/wp-admin/includes/image.php' );
}
$uploadpath = wp_get_upload_dir();