12 junio 2023

C# Constructores con expresiones lambda

Constructores con cuerpo versión clásica

 

public class Person

{

    public string Name { get; }

    public int Age { get; }

 

    public Person(string name, int age)

    {

        Name = name;

        Age = age;

    }

}

 

Constructores con cuerpo de expresión

Expresiones lambda

Constructores con cuerpo de expresión utilizando las diferentes características introducidas por las tuplas:

 

public class Person

{

    public string Name { get; }

    public int Age { get; }

 

    public Person(string name, int age) => (Name, Age) = (name, age);

}

 

Referencia https://www.linkedin.com/feed/update/urn:li:activity:6952198212967419905/

 

 

 

25 abril 2023

Seguridad de redes y sistemas defensivos

Seguridad de redes y sistemas defensivos

Imagen tomada de ucsp.edu.pe

 

La seguridad de redes se refiere a la protección de las redes informáticas contra amenazas y vulnerabilidades que pueden afectar la confidencialidad, integridad y disponibilidad de la información que se transmite a través de ellas.

 

Esto incluye la implementación de medidas de seguridad tales como cortafuegos, sistemas de detección de intrusiones, autenticación y control de acceso, cifrado de datos y medidas de prevención de malware, entre otros.

 

La seguridad de redes también implica la gestión de riesgos y la elaboración de planes de contingencia en caso de fallas de seguridad o desastres, así como la educación y capacitación de los usuarios para prevenir vulnerabilidades como la ingeniería social o el phishing.

16 julio 2019

MS SQL Server - Reducir Log file BD

USE [DataBaseName]
GO

DBCC SHRINKFILE (N'DataBaseName_log' , EMPTYFILE)
GO

PHP - Pasar variables entre páginas de forma segura (codificadas)

FUNCION 1: Codificar antes de enviar

function encode_this($string)
{
    $control = "extra";
    $tmp_string = $string;
    $string = $control . $tmp_string . $control;
    $string = base64_encode($string);

    return ($string);
}

FUNCION 2: Decodificar al recibir

function decode_this($string)
{
    $string = base64_decode($string);
    $control = "extra";
    $string = str_replace($control, "", "$string");

    return $string;
}

Esta última función:
1. Decodifica en base64 el string entero (la abominación)
2. Corta del string el string de control que había DELANTE y DETRAS
3. Retorna el valor verdadero que se intentaba enviar

Forma de uso
Página 1 (indice.php)

$id = encode_this($id);
echo "<a href='/abrir_pagina.php?id_secreto=" . $id . "'>Cargar pagina 234</a>";

Página 2 (abrir_pagina.php)

if ($_GET['id_secreto']) {

    if (($id = decode_this(['id_secreto'])) != $date_hbd) {
        echo "Please wait...<br>";
        exit();
    } else {
        header("location: www.goo.gov/secretfile.php?id=" . $id);
    }
} else {
    echo "¿A dónde crees que vas sin tu ID super secreto?<br>";
    exit();
}

MS SQL Server - Ejecutar comando DOS

EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
EXEC MASTER.dbo.xp_cmdshell 'DEL D:\MsSQL\file.bak';
GO

MS SQL Server - Cambiar password sa

USE master;
GO

ALTER LOGIN sa WITH PASSWORD = 'tu-nuevo-password-sa';
GO

19 junio 2019

MS SQL Server - Cursor Template

DECLARE @Reg VARCHAR(255)
DECLARE MY_CURSOR CURSOR LOCAL STATIC READ_ONLY FORWARD_ONLY
FOR
SELECT Reg_NombreCorto FROM REGIONAL

OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @Reg
WHILE @@FETCH_STATUS = 0
BEGIN

    --mi code ini
    PRINT @Reg
    --mi code fin

    FETCH NEXT FROM MY_CURSOR INTO @Reg
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
GO

21 mayo 2018

C# - Generics and Delegates


C# - Generics and Delegates
Método para generar archivo de texto con Generics y Delegates

public class Bo
{
    public static void GenBo()
    {
        #region List Data
        List<Informations> bines = new List<Informations>
        {
        new Informations(1,"604237"),
        new Informations(2,"604238"),
        new Informations(3,"604239"),
        new Informations(4,"604240")
        };
        #endregion
        
        #region Create Directory
        DirectoryInfo directoryInfo = new DirectoryInfo("C:/PR/");
        if (!directoryInfo.Exists) directoryInfo.Create();
        #endregion
        
        #region Write File
        bines.ForEach(delegate (Informations t)
        {
            string filename = directoryInfo + t.Id.ToString() + t.Name + ".txt";
            using (FileStream fileStream = new FileStream(filename, 
            FileMode.Create, FileAccess.Write, FileShare.None))
            {
                using (StreamWriter p = new StreamWriter(fileStream))
                {
                    p.WriteLine(t.Id.ToString() + t.Name);
                }
            }
        });
        #endregion
    }
}

public class Informations
{
    public int Id { get; set; }
    public string Name { get; set; }

    public Informations(int Id, string Name)
    {
        this.Id = Id;
        this.Name = Name;
    }
}

24 abril 2018

MS SQL Server - Conteo total de registros por DB

MS SQL Server - Conteo total de registros por DB

Script SQL para realizar el conteo total de registros por table de una base de datos de MS SQL Server.

SELECT
 X.[name],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[rows]), 1), '.00', '') AS [rows],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[reserved]), 1), '.00', '') AS [reserved],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[data]), 1), '.00', '') AS [data],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[index_size]), 1), '.00', '') AS [index_size],
 REPLACE(CONVERT(varchar, CONVERT(money, X.[unused]), 1), '.00', '') AS [unused]
FROM
 (
  SELECT
  CAST(object_name(id) AS varchar(50)) AS [name],
  SUM(CASE WHEN indid < 2 THEN CONVERT(bigint, [rows]) END) AS [rows],
  SUM(CONVERT(bigint, reserved)) * 8 AS reserved,
  SUM(CONVERT(bigint, dpages)) * 8 AS data,
  SUM(CONVERT(bigint, used) - CONVERT(bigint, dpages)) * 8 AS index_size,
  SUM(CONVERT(bigint, reserved) - CONVERT(bigint, used)) * 8 AS unused
  FROM sysindexes WITH (NOLOCK)
  WHERE sysindexes.indid IN (0, 1, 255)
  AND sysindexes.id > 100
  AND object_name(sysindexes.id) <> 'dtproperties'
  GROUP BY sysindexes.id WITH ROLLUP
  ) AS X
WHERE X.[name] is not null
ORDER BY X.[rows] DESC