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


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Mensajes
Páginas: 1 ... 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 [854] 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 ... 1254
8531  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 17 Agosto 2013, 20:03 pm
Una función para abreviar cantidades de dinero al estilo americano.

PD: He preguntado a gente americana como son las abreviaturas para cifras más grandes de un Trillón pero al parecer no existen abreviaturas Standards, así que me las he inventado un poco basándome en el nombre de las cantidades. http://ell.stackexchange.com/questions/9123/money-abbreviations

EDITO: Corregido la ubicación del caracter del dolar, parece ser que se pone a la izquierda de la cantidad, no a la derecha.
Código
  1.    #Region " Money Abbreviation "
  2.  
  3.       ' [ Money Abbreviation Function ]
  4.       '
  5.       ' // By Elektro H@cker
  6.       '
  7.       ' Examples :
  8.       '
  9.       ' MsgBox(Money_Abbreviation(1000))           ' Result: 1 K
  10.       ' MsgBox(Money_Abbreviation(1000000))        ' Result: 1 M
  11.       ' MsgBox(Money_Abbreviation(1500000, False)) ' Result: 1,5 M
  12.  
  13.       Private Function Money_Abbreviation(ByVal Quantity As Object, _
  14.                                           Optional ByVal Rounded As Boolean = True) As String
  15.  
  16.           Dim Abbreviation As String = String.Empty
  17.  
  18.           Select Case Quantity.GetType()
  19.  
  20.               Case GetType(Int16), GetType(Int32), GetType(Int64)
  21.                   Quantity = FormatNumber(Quantity, TriState.False)
  22.  
  23.               Case Else
  24.                   Quantity = FormatNumber(Quantity, , TriState.False)
  25.  
  26.           End Select
  27.  
  28.           Select Case Quantity.ToString.Count(Function(character As Char) character = Convert.ToChar("."))
  29.  
  30.               Case 0 : Return String.Format("${0}", Quantity)
  31.               Case 1 : Abbreviation = "k"
  32.               Case 2 : Abbreviation = "M"
  33.               Case 3 : Abbreviation = "B"
  34.               Case 4 : Abbreviation = "Tr."
  35.               Case 5 : Abbreviation = "Quad."
  36.               Case 6 : Abbreviation = "Quint."
  37.               Case 7 : Abbreviation = "Sext."
  38.               Case 8 : Abbreviation = "Sept."
  39.               Case Else
  40.                   Return String.Format("${0}", Quantity)
  41.  
  42.           End Select
  43.  
  44.           Return IIf(Rounded, _
  45.                  String.Format("{0} {1}", StrReverse(StrReverse(Quantity).Substring(StrReverse(Quantity).LastIndexOf(".") + 1)), Abbreviation), _
  46.                  String.Format("{0} {1}", StrReverse(StrReverse(Quantity).Substring(StrReverse(Quantity).LastIndexOf(".") - 1)), Abbreviation))
  47.  
  48.       End Function
  49.  
  50.    #End Region





Contar la cantidad de coincidencias de un caracter dentro de un string.

Código
  1. #Region " Count Character "
  2.  
  3.    ' [ Count Character Function ]
  4.    '
  5.    ' // By Elektro H@cker
  6.    '
  7.    ' Examples :
  8.    ' MsgBox(Count_Character("Elektro", "e"))       ' Result: 1
  9.    ' MsgBox(Count_Character("Elektro", "e", True)) ' Result: 2
  10.  
  11.    Public Function Count_Character(ByVal str As String, ByVal character As Char, _
  12.                                    Optional ByVal IgnoreCase As Boolean = False) As Integer
  13.  
  14.        Return IIf(IgnoreCase, _
  15.                   str.ToLower.Count(Function(c As Char) c = Convert.ToChar(character.ToString.ToLower)), _
  16.                   str.Count(Function(c As Char) c = character))
  17.  
  18.    End Function
  19.  
  20. #End Region
8532  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 17 Agosto 2013, 19:17 pm
Una función para convertir entre tasas de transferencia de telecomunicaciones y tasas de transferencia de datos, es decir, entre Bp/s y B/s.

PD: En este snippet @IkillNukes me ha ayudado con los cálculos matemáticos de las enumeraciones, que me daban ciertos problemas.

Código
  1. #Region " Telecommunication Bitrate To DataStorage Bitrate "
  2.  
  3.    ' [ Base64 To String Function ]
  4.    '
  5.    ' // By Elektro H@cker & IKillNukes
  6.    '
  7.    ' Examples :
  8.    '
  9.    ' MsgBox(Telecommunication_Bitrate_To_DataStorage_Bitrate(365, _
  10.    '        Telecommunications_Bitrates.Kilobips, _
  11.    '        DataStorage_Bitrates.Kilobytes)) ' Result: 45
  12.    '
  13.    ' MsgBox(Telecommunication_Bitrate_To_DataStorage_Bitrate(365, _
  14.    '        Telecommunications_Bitrates.Kilobips, _
  15.    '        DataStorage_Bitrates.Kilobytes)) ' Result: 45,625
  16.  
  17.    Private Enum Telecommunications_Bitrates As Long
  18.        Bips = 1 ' bit/s
  19.        Kilobips = 1000 ' bit/s
  20.        Megabips = 1000000 ' bit/s
  21.        Gigabips = 1000000000 ' bit/s
  22.        Terabips = 1000000000000 ' bit/s
  23.    End Enum
  24.  
  25.    Private Enum DataStorage_Bitrates As Long
  26.        Bytes = 8 ' bits
  27.        Kilobytes = 8000 ' bits
  28.        Megabytes = 8000000 ' bits
  29.        Gigabytes = 8000000000 ' bits
  30.        Terabytes = 8000000000000  ' bits
  31.    End Enum
  32.  
  33.    Private Function Telecommunication_Bitrate_To_DataStorage_Bitrate( _
  34.                       ByVal BitRate As Single, _
  35.                       ByVal Telecommunications_Bitrates As Telecommunications_Bitrates, _
  36.                       ByVal DataStorage_Bitrates As DataStorage_Bitrates, _
  37.                       Optional ByVal Rounded As Boolean = True
  38.                     ) As Single
  39.  
  40.        Return IIf(Rounded, _
  41.                   (BitRate * Telecommunications_Bitrates) \ DataStorage_Bitrates, _
  42.                   (BitRate * Telecommunications_Bitrates) / DataStorage_Bitrates)
  43.  
  44.    End Function
  45.  
  46. #End Region
8533  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 17 Agosto 2013, 05:48 am
Convierte una fecha a formato de fecha Unix

Código
  1. #Region " DateTime To Unix "
  2.  
  3.    ' [ DateTime To Unix Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' MsgBox(DateTime_To_Unix(DateTime.Parse("01/01/2013 12:00:00"))) ' Result: 1357041600
  8.  
  9.    Public Function DateTime_To_Unix(ByVal DateTime As DateTime) As Long
  10.        Return DateDiff(DateInterval.Second, #1/1/1970#, DateTime)
  11.    End Function
  12.  
  13. #End Region

Convierte formato de fecha Unix a Fecha normal.

Código
  1. #Region " Unix To DateTime "
  2.  
  3.    ' [ Unix To DateTime Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' MsgBox(Unix_To_DateTime(1357041600)) ' Result: 01/01/2013 12:00:00
  8.  
  9.    Public Function Unix_To_DateTime(ByVal UnixTime As Long) As DateTime
  10.        Return DateAdd(DateInterval.Second, UnixTime, #1/1/1970#)
  11.    End Function
  12.  
  13. #End Region
8534  Sistemas Operativos / Windows / Re: Crear servicios de Windows?? en: 16 Agosto 2013, 19:46 pm
si alguien sabe alguna otra forma que lo comente.

1. Con la aplicación SC de Microsoft (Service Controller) -> http://technet.microsoft.com/en-us/library/bb490995.aspx

2. Desarrollando un servicio de Windows usando VisualStudio (VB, C#) -> http://msmvps.com/blogs/joacim/archive/2009/09/13/creating-a-windows-service-using-vb-net.aspx

Saludos.
8535  Foros Generales / Dudas Generales / Re: LUA Garry's Mod en: 16 Agosto 2013, 15:34 pm
Aprender un lenguaje de programación requiere tiempo, práctica y dedicación, si estás dispuesto a ello aquí tienes toda la información necesaria: http://www.lua.org/manual/5.2/

Si prefieres seguir tutoriales, en youtube tienes muchos: http://www.youtube.com/user/TheCoolSquare?feature=watch



Saludos.
8536  Programación / Scripting / Re: Ayuda script vbs borrar temporales de usuarios de internet en: 16 Agosto 2013, 14:53 pm
Me gusta proponer alternativas, ¿Porque no usar los parámetros de consola de CCLEANER? :P -> Command-line parameters for CCleaner operation

-> Delete Internet Temp Files (VBS)

Saludos
8537  Programación / Scripting / Re: como puedo enviar unos archivos de manera automatica a mi correo por Cmd en: 16 Agosto 2013, 14:48 pm
Batch no dispone de ningún comando para emails, debes recurrir a aplicaciones de terceros o en su defecto a cualquier otro lenguaje que no sea Batch.

Puedes registrarte de forma gratuita aquí y utilizar la aplicación commandline que ofrecen, para usarla en Batch: https://www.zeta-uploader.com/es , lo llevo usando años, lo bueno es que usan un server dedicado así que no es necesario enviarlo desde una cuenta de correo original y no hay limite (al menos no un limite pequeño) de tamaño.

...O puedes googlear un poco para ver ejemplos de códigos para enviar emails usando VBS, por ejemplo.

Para lo de la hora debes crear una tarea programada en tu PC -> SCHTASKS

Saludos
8538  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 16 Agosto 2013, 04:19 am
Unos tips que he codeado sobre el manejo de una lista de Tuplas, de una lista de FIleInfo, y sobre la utilización de algunas extensiones de LINQ:

PD: Es muy bueno aprender todos estos métodos para dejar en el olvido a los FOR.


List(Of Tuple)
Código
  1.        ' Create the list:
  2.        Dim TupleList As New List(Of Tuple(Of String, Boolean, Integer)) ' From {Tuple.Create("Hello world", True, 1)}
  3.  
  4.        ' Add an Item:
  5.        TupleList.Add(Tuple.Create("Elektro", False, 0))
  6.        TupleList.Add(Tuple.Create("H@cker", True, 1))
  7.  
  8.        ' Order the TupleList by a Tuple item:
  9.        TupleList = TupleList.OrderBy(Function(Tuple) Tuple.Item3).ToList
  10.  
  11.        ' Sort the TupleList by a Tuple item:
  12.        TupleList.Sort( _
  13.        Function(Comparer_A As Tuple(Of String, Boolean, Integer), _
  14.                 Comparer_B As Tuple(Of String, Boolean, Integer)) _
  15.                 Comparer_A.Item3.CompareTo(Comparer_B.Item3))
  16.  
  17.        ' Filter the list by items equals as "True" in their Tuple second item:
  18.        TupleList = TupleList.Where(Function(Tuple) Tuple.Item2 = True).ToList
  19.  
  20.        ' Display a Tuple item from a list item:
  21.        MsgBox(TupleList.Item(0).Item2)
  22.  
  23.        ' Looping the list:
  24.        For Each Item As Tuple(Of String, Boolean, Integer) In TupleList
  25.            MsgBox(Item.Item1)
  26.        Next


List(Of FileInfo)
Código
  1.        ' Create the list:
  2.        Dim Files As List(Of IO.FileInfo) = IO.Directory.GetFiles("C:\", "*") _
  3.        .Select(Function(ToFileInfo) New IO.FileInfo(ToFileInfo)).ToList
  4.  
  5.        ' Add an Item:
  6.        Files.Add(New IO.FileInfo("C:\Windows\Notepad.exe"))
  7.  
  8.        ' Order the list by a file property:
  9.        Files = Files.OrderBy(Function(File) File.Extension).ToList
  10.  
  11.        ' Sort the list by a file property:
  12.        Files.Sort( _
  13.        Function(Comparer_A As IO.FileInfo, Comparer_B As IO.FileInfo) _
  14.                 Comparer_A.Extension.CompareTo(Comparer_B.Extension))
  15.  
  16.        ' Filter the list by files containing "note" word in their filename:
  17.        Files = Files.Where(Function(File) File.Name.ToLower.Contains("note")).ToList
  18.  
  19.        ' Display a file property from a list item:
  20.        MsgBox(Files.Item(0).FullName)
  21.  
  22.        ' Looping the list:
  23.        For Each File As IO.FileInfo In Files
  24.            MsgBox(File.FullName)
  25.        Next
8539  Programación / .NET (C#, VB.NET, ASP) / Re: ¿ Se puede hacer esta consulta de fechas ? en: 16 Agosto 2013, 02:13 am
La ciencia de "1 mes" no es exacta, son todo promedios, Google dice que son 30 días como ha dicho Novlucker, pero la Wikipedia dice que son 29, y nosotros cuando decimos un mes (al menos yo) pensamos en 30 días sin tener el cuenta el més en el que estamos, pero cuando decimos "el próximos més" pensamos en el día 1 del siguiente més, en fín por todo esto creo que no hay que comerse mucho la cabeza para intentar calcular al milímetro los meses.

Así que aquí dejo el code funcional para VB que me ha proporcionado una persona, el code funciona con la fecha problemática que ha comentado @ostrede y también con los horarios:

Código
  1. #Region " Date Difference "
  2.  
  3.    ' Date Difference
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' MsgBox(DateDifference(DateTime.Parse("01/03/2013"), DateTime.Parse("10/04/2013"))) ' Result: 1 Months, 1 Weeks, 2 Days, 0 Hours, 0 Minutes and 0 Seconds
  8.    ' MsgBox(DateDifference(DateTime.Parse("01/01/2013 14:00:00"), DateTime.Parse("02/01/2013 15:00:30"))) ' Result: 0 Months, 0 Weeks, 1 Days, 1 Hours, 0 Minutes and 30 Seconds
  9.  
  10.    Private Function DateDifference(ByVal Date1 As DateTime, ByVal Date2 As DateTime) As String
  11.  
  12.        Dim Time As TimeSpan
  13.        Dim MonthDiff As Integer, WeekDiff As Integer
  14.  
  15.        Do Until Date1 > Date2
  16.            Date1 = Date1.AddMonths(1)
  17.            MonthDiff += 1
  18.        Loop
  19.  
  20.        MonthDiff -= 1
  21.        Date1 = Date1.AddMonths(-1)
  22.        Time = (Date2 - Date1)
  23.        WeekDiff = (Time.Days \ 7)
  24.        Time = (Time - TimeSpan.FromDays(WeekDiff * 7))
  25.  
  26.        Return String.Format("{0} Months, {1} Weeks, {2} Days, {3} Hours, {4} Minutes and {5} Seconds", _
  27.                             MonthDiff, WeekDiff, Time.Days, Time.Hours, Time.Minutes, Time.Seconds)
  28.  
  29.    End Function
  30.  
  31. #End Region

¿Tema solucionado? xD.

Saludos
8540  Programación / .NET (C#, VB.NET, ASP) / Re: ¿ Se puede hacer esta consulta de fechas ? en: 15 Agosto 2013, 22:50 pm
EleKtro H@cker, sin probarla, esa función no es correcta :P
¿Qué pasa si le paso como parámetros las fechas "01/01/2013 14:00:00" y "02/01/2013 13:00:30"?

Saludos

Es verdad no me di cuenta, malditas "horas" xD

Bueno todo tiene solución, entonces hay que substraer en lugar de restar:

Código
  1.    Dim HourDiff As Long = Date2.Subtract(Date1).Hours
  2.    Dim MinuteDiff As Long = Date2.Subtract(Date1).Minutes
  3.    Dim SecondDiff As Long = Date2.Subtract(Date1).Seconds
  4.    Dim MilliDiff As Long = Date2.Subtract(Date1).Milliseconds

Llevo un lio tremendo para sacar la fecha con eficacia (por ejemplo entre meses como febrero con 28 días), el valor de las semanas se resiste, pero nadie tiene la solución: http://stackoverflow.com/questions/18259835/function-to-get-a-custom-date-difference

Saludos!
Páginas: 1 ... 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 [854] 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 ... 1254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines