<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Edgardo's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 26 Jul 2008 13:17:31 GMT</pubDate>
    <description>DZone Snippets: Edgardo's Code Snippets</description>
    <item>
      <title>Add consolas to cmd.exe</title>
      <link>http://snippets.dzone.com/posts/show/5426</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont" /v 00 /d Consolas&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;logoff</description>
      <pubDate>Thu, 24 Apr 2008 15:19:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5426</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
    <item>
      <title>Read image metadata withWPF</title>
      <link>http://snippets.dzone.com/posts/show/4164</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;FileStream fs = new FileStream("image.jpg", FileMode.Open, FileAccess.Read, FileShare.Read);&lt;br /&gt;BitmapDecoder decoder = BitmapDecoder.Create(fs, BitmapCreateOptions.None, BitmapCacheOption.Default);&lt;br /&gt;BitmapFrame frame = decoder.Frames[0];&lt;br /&gt;BitmapMetadata metadata = frame.Metadata as BitmapMetadata;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 19 Jun 2007 19:58:44 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4164</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
    <item>
      <title>Calculate MD5 hash</title>
      <link>http://snippets.dzone.com/posts/show/4108</link>
      <description>// description of your code here&lt;br /&gt;http://blogs.msdn.com/csharpfaq/archive/2006/10/09/How-do-I-calculate-a-MD5-hash-from-a-string_3F00_.aspx&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public string CalculateMD5Hash(string input)&lt;br /&gt;{&lt;br /&gt;    // step 1, calculate MD5 hash from input&lt;br /&gt;    MD5 md5 = System.Security.Cryptography.MD5.Create();&lt;br /&gt;    byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);&lt;br /&gt;    byte[] hash = md5.ComputeHash(inputBytes);&lt;br /&gt; &lt;br /&gt;    // step 2, convert byte array to hex string&lt;br /&gt;    StringBuilder sb = new StringBuilder();&lt;br /&gt;    for (int i = 0; i &lt; hash.Length; i++)&lt;br /&gt;    {&lt;br /&gt;        sb.Append(hash[i].ToString("X2"));&lt;br /&gt;    }&lt;br /&gt;    return sb.ToString();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 06 Jun 2007 21:14:46 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4108</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
    <item>
      <title>Calculate age in C#</title>
      <link>http://snippets.dzone.com/posts/show/1632</link>
      <description>using System;&lt;br /&gt;using System.Data;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public static class Snippets&lt;br /&gt;{&lt;br /&gt;    public static int CalculateAge(DateTime birthdate)&lt;br /&gt;    {&lt;br /&gt;        // get the difference in years&lt;br /&gt;        int years = DateTime.Now.Year - birthdate.Year;&lt;br /&gt;        // subtract another year if we're before the&lt;br /&gt;        // birth day in the current year&lt;br /&gt;        if (DateTime.Now.Month &lt; birthdate.Month || (DateTime.Now.Month == birthdate.Month &amp;&amp; DateTime.Now.Day &lt; birthdate.Day))&lt;br /&gt;            years--;&lt;br /&gt;&lt;br /&gt;        return years;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 04 Mar 2006 07:04:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1632</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
    <item>
      <title>Resize image with .NET</title>
      <link>http://snippets.dzone.com/posts/show/1485</link>
      <description>using System;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public static byte[] ResizeImageFile(byte[] imageFile, int targetSize)&lt;br /&gt;{&lt;br /&gt;    Image original = Image.FromStream(new MemoryStream(imageFile));&lt;br /&gt;    int targetH, targetW;&lt;br /&gt;    if (original.Height &gt; original.Width)&lt;br /&gt;    {&lt;br /&gt;        targetH = targetSize;&lt;br /&gt;        targetW = (int)(original.Width * ((float)targetSize / (float)original.Height));&lt;br /&gt;    }&lt;br /&gt;    else&lt;br /&gt;    {&lt;br /&gt;        targetW = targetSize;&lt;br /&gt;        targetH = (int)(original.Height * ((float)targetSize / (float)original.Width));&lt;br /&gt;    }&lt;br /&gt;    Image imgPhoto = Image.FromStream(new MemoryStream(imageFile));&lt;br /&gt;    // Create a new blank canvas.  The resized image will be drawn on this canvas.&lt;br /&gt;    Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);&lt;br /&gt;    bmPhoto.SetResolution(72, 72);&lt;br /&gt;    Graphics grPhoto = Graphics.FromImage(bmPhoto);&lt;br /&gt;    grPhoto.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;    grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;    grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;    grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel);&lt;br /&gt;    // Save out to memory and then to a file.  We dispose of all objects to make sure the files don't stay locked.&lt;br /&gt;    MemoryStream mm = new MemoryStream();&lt;br /&gt;    bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);&lt;br /&gt;    original.Dispose();&lt;br /&gt;    imgPhoto.Dispose();&lt;br /&gt;    bmPhoto.Dispose();&lt;br /&gt;    grPhoto.Dispose();&lt;br /&gt;    return mm.GetBuffer();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 14 Feb 2006 23:35:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1485</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
    <item>
      <title>Crop image with .NET</title>
      <link>http://snippets.dzone.com/posts/show/1484</link>
      <description>using System;&lt;br /&gt;using System.Drawing;&lt;br /&gt;using System.Drawing.Drawing2D;&lt;br /&gt;using System.Drawing.Imaging;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;public static byte[] CropImageFile(byte[] imageFile, int targetW, int targetH, int targetX, int targetY)&lt;br /&gt;{&lt;br /&gt;    Image imgPhoto = Image.FromStream(new MemoryStream(imageFile));&lt;br /&gt;    Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);&lt;br /&gt;    bmPhoto.SetResolution(72, 72);&lt;br /&gt;    Graphics grPhoto = Graphics.FromImage(bmPhoto);&lt;br /&gt;    grPhoto.SmoothingMode = SmoothingMode.AntiAlias;&lt;br /&gt;    grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;&lt;br /&gt;    grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;&lt;br /&gt;    grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), targetX, targetY, targetW, targetH, GraphicsUnit.Pixel);&lt;br /&gt;    // Save out to memory and then to a file.  We dispose of all objects to make sure the files don't stay locked.&lt;br /&gt;    MemoryStream mm = new MemoryStream();&lt;br /&gt;    bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);&lt;br /&gt;    imgPhoto.Dispose();&lt;br /&gt;    bmPhoto.Dispose();&lt;br /&gt;    grPhoto.Dispose();&lt;br /&gt;    return mm.GetBuffer();&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 14 Feb 2006 23:34:05 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1484</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
    <item>
      <title>Autenticando por UserName o Email</title>
      <link>http://snippets.dzone.com/posts/show/1317</link>
      <description>&lt;code&gt;&lt;br /&gt;protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)&lt;br /&gt;{&lt;br /&gt;    Regex r = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.Compiled);&lt;br /&gt; &lt;br /&gt;    // s&#243;lo si el usuario ingreso un email&lt;br /&gt;    if (r.IsMatch(Login1.UserName))&lt;br /&gt;    {&lt;br /&gt;        string username = Membership.GetUserNameByEmail(Login1.UserName);&lt;br /&gt; &lt;br /&gt;        // esto significa que el usuario ingres&#243; un email que no existe&lt;br /&gt;        if (String.IsNullOrEmpty(username))&lt;br /&gt;        {&lt;br /&gt;            // mostramos un mensaje de error amigable y cancelamos la autenticaci&#243;n&lt;br /&gt;            Literal error = Login1.FindControl("FailureText") as Literal;&lt;br /&gt;            error.Text = "La direcci&#243;n de email no se encuentra en nuestros registros.";&lt;br /&gt;            e.Cancel = true;&lt;br /&gt;        }&lt;br /&gt; &lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            // Encontramos el nombre de usuario :)&lt;br /&gt;            // Reemplaza el email por el UserName verdadero&lt;br /&gt;            Login1.UserName = username;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 30 Jan 2006 14:51:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1317</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
    <item>
      <title>Mandar mail con ASP.NET 2.0</title>
      <link>http://snippets.dzone.com/posts/show/1316</link>
      <description>C#&lt;br /&gt;&lt;code&gt;&lt;br /&gt;MailMessage message = new MailMessage();&lt;br /&gt;message.From = new MailAddress("remitente@lo.que.sea");&lt;br /&gt;message.To.Add(new MailAddress("destinatario@lo.que.sea"));&lt;br /&gt;message.Subject = "Asunto";&lt;br /&gt;message.Body = "Cuerpo";&lt;br /&gt;SmtpClient client = new SmtpClient();&lt;br /&gt;client.Send(message);&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;web.config&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;system.net&gt;&lt;br /&gt;    &lt;mailSettings&gt;&lt;br /&gt;        &lt;smtp from="email@algo.com"&gt;&lt;br /&gt;            &lt;network host="localhost" port="25" defaultCredentials="true" /&gt;&lt;br /&gt;        &lt;/smtp&gt;&lt;br /&gt;    &lt;/mailSettings&gt;&lt;br /&gt;&lt;/system.net&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 30 Jan 2006 14:45:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1316</guid>
      <author>Edgardo (Edgardo Rossetto)</author>
    </item>
  </channel>
</rss>
