elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía actualizada para evitar que un ransomware ataque tu empresa


  Mostrar Mensajes
Páginas: 1 2 3 [4] 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... 238
31  Comunicaciones / Mensajería / Re: Me están puteando en: 30 Octubre 2018, 00:50 am
Denunció y que? Si está borrado el perfil  y no tengo la prueba de que sea ese numero.  No hay amenazas ni nada.  Sólo tonteo con otra.  Igual se ríen de mi

La privacidad de alguien es sagrada, y es perfectamente denunciable.

Lo que puedes hacer es instalar en tu dispositivo algo que te monitorice las conexiones (via IP) a tu movil (que no se si existirá, pero para Windows se llama netcut) y así podrás ver la IP del que te la está haciendo. Con la IP, si eres rápido, quizás una denuncia te valga de algo. Aunque si el otro utiliza una proxy poco vas a poder hacer. (Haz un lookup de la IP)

Ojo: No mandes mensajes con ese movil (ni conexiones) aquí ya que el polizón que te esté haciendo la jugarreta podrá saberlo.

No se si se podrá, pero tu movil está infectado, si tienes algún amigo técnico o algo, mira a ver que te puede recomendar, lo más seguro, es que piense en algo similar.

Solución: A parte de una denuncia obvia, restablece tu movil de fábrica y san sacabo.

Y bueno, a las malas podrías meterle al ordenador de tu novia algún tipo de grabadora de pantalla o algo para que se sepa el nombre de la persona que está haciendo eso.

Otra solución sería un enlace que registrase la IP de quien ha mandado el mensaje, pero sería muy arriesgado aún así con ingenería social ni lo intentaría.
32  Foros Generales / Sugerencias y dudas sobre el Foro / Re: Limpieza usuarios del foro (Diciembre 2016) en: 28 Octubre 2018, 12:13 pm
No lo hagas, yo soy usuario desde 2002, y mi última conexión fue hace 4 años, aún así me paso de vez en cuando y vaya nostalgia, me alegra ver que nada (ni el diseño) ha cambiado.

Solo se borraron los usuarios con 0 mensajes. Si hubieses tenido 0 mensajes no hubieses corrido la misma suerte.
33  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de códigos C# (Compartan aquí sus códigos) en: 23 Octubre 2018, 18:31 pm
Simplificar una lista de puntos para obtener las esquinas (dicho de otra forma, obtener la minima cantidad de puntos que puedan definir dicha forma)

Esto ya lo respondí en Stackoverflow: https://stackoverflow.com/a/52952874/3286975 (Pero lo traduciré)

Citar
Después de horas de investigación he encontrado una librería Simplify.NET que internamente ejecuta el algoritmo de Ramer–Douglas–Peucker.

También, os puede interesar el algoritmo de Bresenham, con este algoritmo podéis dibujar una linea a partir de dos puntos.

Con este algoritmo, se podría comprobar si la tolerancia del primer algoritmo es muy alta (comprobando los puntos generados y los que ya tenías antes de simplificar, haciendo una función que te devuelva un porcentaje de similitud). Por suerte, la implementación de Simplify.NET es rápida (unos 25.000 ticks de Stopwatch), llamandose unas 10 veces solo llevaría unos ~30 ms.

Finalmente, es interesante mencionar el algoritmo Concave Hull y Convex Hull (y sus respectivas implementaciones en Unity3D).

Lo que he obtenido con esta implementación:





Nota:
  • Los puntos azules son los puntos iterados.
  • Los puntos verdes son los puntos simplificados.

Y mi implementación: https://dotnetfiddle.net/aPOhPi

Es muy importante decir que los puntos deben de estar ordenados de tal forma que estén conectados. Si la forma es concava (como se puede ver en la segunda foto) quizás necesites una implementación que itere pixel a pixel dentro de la pared de la figura.

Aquí podéis ver una implementación gracias a Bunny83.

Un saludo.
34  Foros Generales / Foro Libre / Re: Ausencia obligada en: 22 Octubre 2018, 21:13 pm
Ánimo simorg, improvistos de última hora tenemos todos. :P
35  Programación / Programación General / Re: Tengo un error en C# en: 22 Octubre 2018, 21:09 pm
Eso ocurre porque banco_palabras[numero_palabra] seguramente será MANUELITO y si haces un substring(0, 1), esto devuelve una "M"...

Lo que deberías hacer:

Código
  1. etiqueta = etiqueta.SubString(0, 1) + new string('-', etiqueta.Length - 2);
36  Programación / .NET (C#, VB.NET, ASP) / Re: Error en Codigo Minusculas a Mayusculas C# en: 22 Octubre 2018, 21:04 pm
Debes poner un Console.Read();

Aquí más info: https://stackoverrun.com/es/q/2306334
37  Foros Generales / Foro Libre / Re: debo crear un proyecto que cree, envié y reciba un archivo xml en: 22 Octubre 2018, 19:46 pm
Ya que estamos en foro libre.

Me apuesto lo que quieras a que ni te has molestado en ver como se lee un XML (ya te lo digo yo: con serialización)

Si te sirve, esto lo implemente el otro día:

Código
  1. using System;
  2. using System.IO;
  3. using System.Xml.Serialization;
  4. using UnityEngine;
  5.  
  6. namespace GTAMapper.Extensions
  7. {
  8.    public static class SerializerHelper
  9.    {
  10.        public static string Serialize<T>(this T data, SerializeFormat format = SerializeFormat.XML)
  11.        {
  12.            switch (format)
  13.            {
  14.                case SerializeFormat.XML:
  15.                    return SerializeToXml(data);
  16.  
  17.                case SerializeFormat.JSON:
  18.                    return SerializeToJson(data);
  19.  
  20.                default:
  21.                    return string.Empty;
  22.            }
  23.        }
  24.  
  25.        public static T Deserialize<T>(this string data, SerializeFormat format = SerializeFormat.XML)
  26.        {
  27.            switch (format)
  28.            {
  29.                case SerializeFormat.XML:
  30.                    return DeserializeToXml<T>(data);
  31.  
  32.                case SerializeFormat.JSON:
  33.                    return DeserializeFromJson<T>(data);
  34.  
  35.                default:
  36.                    return default(T);
  37.            }
  38.        }
  39.  
  40.        /*public static string SerializeToXml<T>(T data)
  41.         {
  42.             var serializer = new DataContractSerializer(data.GetType());
  43.             var builder = new StringBuilder();
  44.             var writer = XmlWriter.Create(builder);
  45.             serializer.WriteObject(writer, data);
  46.             writer.Flush();
  47.             return builder.ToString();
  48.         }*/
  49.  
  50.        private static string SerializeToXml<T>(T data)
  51.        {
  52.            var xmlSerializer = new XmlSerializer(typeof(T));
  53.            // xmlSerializer.WriteProcessingInstruction("xml", "version='1.0'");
  54.  
  55.            using (var stringWriter = new StringWriter())
  56.            {
  57.                xmlSerializer.Serialize(stringWriter, data);
  58.                return stringWriter.ToString();
  59.            }
  60.        }
  61.  
  62.        /*public static T DeserializeToXml<T>(string data)
  63.         {
  64.             var serializer = new DataContractSerializer(data.GetType());
  65.             var writer = XmlReader.Create(GenerateStreamFromString(data));
  66.             var result = serializer.ReadObject(writer);
  67.             return (T)result;
  68.         }*/
  69.  
  70.        private static T DeserializeToXml<T>(string data)
  71.        {
  72.            try
  73.            {
  74.                var xmlSerializer = new XmlSerializer(data.GetType());
  75.                using (var stream = GenerateStreamFromString(data))
  76.                {
  77.                    var result = xmlSerializer.Deserialize(stream);
  78.                    return (T)result;
  79.                }
  80.            }
  81.            catch (Exception ex)
  82.            {
  83.                Debug.LogException(ex);
  84.                Debug.Log(data);
  85.                return default(T);
  86.            }
  87.        }
  88.  
  89.        private static Stream GenerateStreamFromString(string s)
  90.        {
  91.            // using
  92.            var stream = new MemoryStream();
  93.            var writer = new StreamWriter(stream, System.Text.Encoding.UTF8);
  94.  
  95.            writer.Write(s);
  96.            writer.Flush();
  97.            stream.Position = 0;
  98.  
  99.            return stream;
  100.        }
  101.  
  102.        private static string SerializeToJson<T>(T data)
  103.        {
  104.            //return JsonConvert.SerializeObject(data);
  105.            throw new NotImplementedException();
  106.        }
  107.  
  108.        private static T DeserializeFromJson<T>(string data)
  109.        {
  110.            //return JsonConvert.DeserializeObject<T>(data);
  111.            throw new NotImplementedException();
  112.        }
  113.    }
  114.  
  115.    public enum SerializeFormat
  116.    {
  117.        XML = 1,
  118.        JSON = 2
  119.    }
  120. }

Pero voy a poner el mismo esfuerzo (para explicar el código) que has puesto tu en formular tu pregunta. 2 líneas.

Un saludo. ;)
38  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de códigos C# (Compartan aquí sus códigos) en: 22 Octubre 2018, 19:33 pm
SendMessageContext: Una implementación Thread-Safe de SendMessage

Básicamente, el puñetero de Unity no te deja llamar la función SendMessage desde otro hilo, así que gracias a esta implementación que estuve probando, resolví el problema, para luego darme cuenta de que usaba (blocking) instrucciones en el main thread (dentro de una coroutina gracias a esta utilidad (https://assetstore.unity.com/packages/tools/thread-ninja-multithread-coroutine-15717) es facil/visual cambiar de contexto) :xD (Sí, así somos los programadores cuando tenemos sueño, implementamos cosas que luego ni usaremos)

La utilidad en cuestión: https://forum.unity.com/threads/sendmessage-argumentexception-error.73134/

Mi implementación:

Código
  1. using System.Collections.Concurrent;
  2. using UnityEngine;
  3.  
  4. namespace GTAMapper.Extensions.Threading
  5. {
  6.    public class SendMessageHelper : MonoBehaviour
  7.    {
  8.        private static ConcurrentQueue<SendMessageContext> QueuedMessages = new ConcurrentQueue<SendMessageContext>();
  9.  
  10.        public static void RegisterSendMessage(SendMessageContext context)
  11.        {
  12.            QueuedMessages.Enqueue(context);
  13.        }
  14.  
  15.        private void Update()
  16.        {
  17.            if (QueuedMessages.Count > 0)
  18.            {
  19.                SendMessageContext context = null;
  20.  
  21.                if (!QueuedMessages.TryDequeue(out context))
  22.                    return;
  23.  
  24.                context.Target.SendMessage(context.MethodName, context.Value, context.Options);
  25.            }
  26.        }
  27.    }
  28. }

Nota: No olvidéis añadir esto al inspector de cualquier gameobject donde se quiera usar (con añadir uno solo bastaría)

Código
  1. using UnityEngine;
  2.  
  3. namespace GTAMapper.Extensions.Threading
  4. {
  5.    public class SendMessageContext
  6.    {
  7.        public MonoBehaviour Target;
  8.        public string MethodName;
  9.        public object Value;
  10.        public SendMessageOptions Options = SendMessageOptions.RequireReceiver;
  11.  
  12.        public SendMessageContext(MonoBehaviour target, string methodName, object value, SendMessageOptions options)
  13.        {
  14.            this.Target = target;
  15.            this.MethodName = methodName;
  16.            this.Value = value;
  17.            this.Options = options;
  18.        }
  19.    }
  20. }

Algo que en el topic de arriba no está ;D

Código
  1. using UnityEngine;
  2.  
  3. namespace GTAMapper.Extensions.Threading
  4. {
  5.    public static class SendMessageExtensions
  6.    {
  7.        public static SendMessageContext SendSafeMessage(this MonoBehaviour monoBehaviour, string methodName, object value = null, SendMessageOptions sendMessageOptions = default(SendMessageOptions))
  8.        {
  9.            return new SendMessageContext(monoBehaviour, methodName, value, sendMessageOptions);
  10.        }
  11.    }
  12. }

Con esta extensión lo que se consigue es simplificar su uso, básicamente, desde un MonoBehaviour cualquiera dentro del metodo Start() (https://docs.unity3d.com/ScriptReference/MonoBehaviour.html) haciendo esto:

Código
  1. this.SendSafeMessage("pepito")

Y luego (desde el mismo MonoBehaviour):

Código
  1. public void pepito() {
  2.    // Moar code que seguirá ejecutándose en el mismo hilo desde el que se llamo "SendSafeMessage"
  3. }

Un saludo.
PD: Aquí termina el flood de snippets, staff no preocuparse, llevo muchos días picando código, y he querido compartir post a post mis utilidades :xD
PD2: Ale ya puedo borrar todo lo que no uso. Que no es poco. ;-) ;-)
39  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de códigos C# (Compartan aquí sus códigos) en: 22 Octubre 2018, 19:16 pm
ThreadedDebug: Una utilidad que funciona junto NamedThread & ThreadMarker mostrándote información del Thread actual al debuggear en Unity3D

Código
  1. using GTAMapper.Extensions.Threading;
  2. using System;
  3. using UnityEngine;
  4.  
  5. namespace GTAMapper.Utils.Debugging
  6. {
  7.    public static class ThreadedDebug
  8.    {
  9.        private static double TimeRunning
  10.        {
  11.            get
  12.            {
  13.                return (DateTime.Now - System.Diagnostics.Process.GetCurrentProcess().StartTime).TotalSeconds;
  14.            }
  15.        }
  16.  
  17.        public static void Log(object obj, bool jumpBack = true)
  18.        {
  19.            Debug.Log($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + obj.ToString());
  20.        }
  21.  
  22.        public static void LogFormat(string str, params object[] objs)
  23.        {
  24.            LogFormat($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + str, true, objs);
  25.        }
  26.  
  27.        public static void LogFormat(string str, bool jumpBack = true, params object[] objs)
  28.        {
  29.            Debug.LogFormat($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + str, objs);
  30.        }
  31.  
  32.        public static void LogWarning(object obj, bool jumpBack = true)
  33.        {
  34.            Debug.LogWarning($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + obj.ToString());
  35.        }
  36.  
  37.        public static void LogWarningFormat(string str, params object[] objs)
  38.        {
  39.            LogWarningFormat($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + str, true, objs);
  40.        }
  41.  
  42.        public static void LogWarningFormat(string str, bool jumpBack = true, params object[] objs)
  43.        {
  44.            Debug.LogWarningFormat($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + str, objs);
  45.        }
  46.  
  47.        public static void LogError(object obj, bool jumpBack = true)
  48.        {
  49.            Debug.LogError($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + obj.ToString());
  50.        }
  51.  
  52.        public static void LogErrorFormat(string str, params object[] objs)
  53.        {
  54.            LogErrorFormat($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + str, true, objs);
  55.        }
  56.  
  57.        public static void LogErrorFormat(string str, bool jumpBack = true, params object[] objs)
  58.        {
  59.            Debug.LogErrorFormat($"[{ThreadMarker.Name} | {TimeRunning.ToString("F2")}] " + str, objs);
  60.        }
  61.  
  62.        public static void LogException(System.Exception ex, bool jumpBack = true)
  63.        {
  64.            Debug.LogException(ex);
  65.        }
  66.    }
  67. }

Básicamente, se usa igual que Debug.LogXX de Unity (https://docs.unity3d.com/ScriptReference/Debug.html) pero este a diferencia, te muesta el momento en el que se ha llamado, y desde el Thread que lo ha hecho.

Ejemplo:



PD: En el ejemplo, vemos dos Count, simplemente, estaba probando que el ConcurrentQueuedCoroutines funcionaba bien, viendo como ConcurrentQueued almacena los datos en todos los contextos usando la instrucción lock(...) internamente.
40  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de códigos C# (Compartan aquí sus códigos) en: 22 Octubre 2018, 19:07 pm
Named Thread & Thread Marked: Pon nombres a tus threads

Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4.  
  5. namespace GTAMapper.Extensions.Threading
  6. {
  7.    public class ThreadMarker : IDisposable
  8.    {
  9.        //[ThreadStatic]
  10.        //private static string __Name = $"Unity Thread #{Thread.CurrentThread.ManagedThreadId}";
  11.  
  12.        private static Dictionary<int, string> ThreadNames = new Dictionary<int, string>();
  13.  
  14.        public static string Name
  15.        {
  16.            get
  17.            {
  18.                lock (ThreadNames)
  19.                {
  20.                    try
  21.                    {
  22.                        return ThreadNames[Thread.CurrentThread.ManagedThreadId];
  23.                    }
  24.                    catch
  25.                    {
  26.                        return $"Unity Thread #{Thread.CurrentThread.ManagedThreadId}";
  27.                    }
  28.                }
  29.            }
  30.        }
  31.  
  32.        public ThreadMarker(string name)
  33.        {
  34.            lock (ThreadNames)
  35.            {
  36.                ThreadNames.AddOrSet(Thread.CurrentThread.ManagedThreadId, name);
  37.            }
  38.  
  39.            // __Name = name;
  40.        }
  41.  
  42.        public void Dispose()
  43.        {
  44.            ThreadNames.Remove(Thread.CurrentThread.ManagedThreadId);
  45.            // __Name = "Un-Owned";
  46.        }
  47.    }
  48. }

Código
  1. using System;
  2.  
  3. namespace GTAMapper.Extensions.Threading
  4. {
  5.    public class NamedHandler<TArg>
  6.    {
  7.        public readonly Func<string, TArg> Handler;
  8.  
  9.        public NamedHandler(Func<string, TArg> handler)
  10.        {
  11.            Handler = arg =>
  12.            {
  13.                using (new ThreadMarker(arg))
  14.                {
  15.                    return handler(arg);
  16.                }
  17.            };
  18.        }
  19.    }
  20. }

Caso de uso:

Código
  1. int TaskId = new Random().Next();
  2.  
  3. ThreadPool.QueueUserWorkItem(new NamedHandler<WaitCallback>(name => new WaitCallback(BackgroundRunner)).Handler($"Ninja #{TaskId}"));
Páginas: 1 2 3 [4] 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ... 238
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines