Skip to content

Instantly share code, notes, and snippets.

View SrChach's full-sized avatar
:octocat:
Building better humans

Ignacio Martínez Ávila SrChach

:octocat:
Building better humans
  • Mediaagility
  • Mexico City, Mexico
View GitHub Profile
@SrChach
SrChach / testingFunctions.txt
Last active February 11, 2019 19:43
Testing functions
/* @Lang: PHP
* @Description: Función para imprimir el valor y metadatos de una variable
*/
function predump($var, $imprime=false, $salir=false){
echo "<pre>";
var_dump($var);
echo "</pre>";
echo $imprime? $var : "";
$salir? exit(): true;
}
@SrChach
SrChach / manageProccesses.txt
Last active February 11, 2019 19:43
Http start/stop services
/* Inicializar servidor */
sudo systemctl start httpd.service
/* Parar servidor */
sudo systemctl stop httpd.service
/* Inicializar servicio mariadb */
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
@SrChach
SrChach / linux_permissions.txt
Last active July 31, 2019 18:17
Linux Permissions
Note: need to improve gist and move it to MarkDown.
need to add how to add permissions to httpd.conf (in another gist)
Structure of the permissions in Linux:
For example, analyzing "-rwxr-xr--"
- rwx r-x r--
[ Type of file ][Owner's permissions ][Group's permissions ][Other's permissions ]
| | 'r' = 'read' |
|'-' indicates file | 'w' = 'write' |
|'d' indicates directory | 'x' = 'execute' |
@SrChach
SrChach / vue.config.js
Last active May 24, 2019 16:08
Configuration to proxy calls to dev server
/* Create a file into the root directory of the project, and name it as "vue.config.js". Paste this code there.
*/
module.exports = {
devServer: {
proxy: {
'/auth': {
target: 'http://127.0.0.1/api', // Sitio al que va a apuntar (redirigir)
pathRewrite: {'^/auth/': '/'} // Para que, por ejemplo, no busque "/auth" en el server de datos, si no la ruta que le pasemos acá
},
@SrChach
SrChach / paginador.php
Last active April 15, 2019 17:49
Función de paginador para PHP
function botoneador($total_registros, $registros_por_pagina, $primer_registro){
$registros_por_pagina = is_numeric($registros_por_pagina) && $registros_por_pagina != 0 ? $registros_por_pagina : 10;
$total_paginas = ceil($total_registros / $registros_por_pagina);
$primer_registro = is_numeric($primer_registro) ? number_format($primer_registro) : 0;
if($primer_registro < 0 || $primer_registro > $total_registros)
$primer_registro = 0;
$pagina_actual = floor($primer_registro / $registros_por_pagina) + 1;
@SrChach
SrChach / Format.php
Last active April 11, 2019 17:58
Format of Query dates in PHP, compatibility with MySQL && SQLite
<?php
class Format {
function __construct(){
}
function query_if_varios_manejadores($nombreCampo, $valorCampo, $if_verdadero = 'NULL', $if_falso = 'NULL' , $manejador = 'sqlite'){
if($manejador == "mysql")
@SrChach
SrChach / parameters_from.js
Created April 11, 2019 17:36
Functions for get values from URL's get parameter && edit URL strings
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
function changeUrlParameter(url, parametro, value){
let separator = '&'
if(url.indexOf("?") === -1)
separator = '?'
url = window.location.href + '&'
@SrChach
SrChach / fun_json.php
Last active May 23, 2019 20:26
Manage errors and success messages in php, check if values exists
<?php
// print_if_not_failed sólo afecta si la operación fué exitosa
function json_check_print($mensaje_posible_error = 'error', $variable = null, $print_if_not_failed = false, $json = false){
$print = [
'error' => null
];
if($json)
header('Content-Type: application/json');
$failed = $variable === null || $variable === false;
if($failed)
@SrChach
SrChach / git-log.sh
Created May 23, 2019 20:38
useful ways to list changes on git/Formas útiles de listar los cambios en git
## Remember that the options below could be used together
# List all the changes made in a file
git log <path_to_folder_or_file>
# Track the change history of a file (including rename)
git log --follow <file>
# list commits by author
git log --author="example_user"
@SrChach
SrChach / dynamic_imports.py
Last active August 28, 2019 19:05
Code to dynamic imports in python
from importlib import import_module
my_module_new_name = import_module('variable.module.name')