<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Net code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 02:31:29 GMT</pubDate>
    <description>DZone Snippets: Net code</description>
    <item>
      <title>ProjectX client-side code</title>
      <link>http://snippets.dzone.com/posts/show/5150</link>
      <description>This Ruby code uses a unified XML format to create a password record on a web server. It's intended to be run as a batch file which gets called from another Ruby application called maintain_projectx which gets called from a cronjob.&lt;br /&gt;&lt;br /&gt;In this example the password is stored on the server not for authentication but simply to provide a reminder service in the event the user forgets it.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'rexml/document'&lt;br /&gt;include REXML&lt;br /&gt;&lt;br /&gt;class ProjectXClient&lt;br /&gt;  attr :doc&lt;br /&gt;  def initialize(raw_url)&lt;br /&gt;    url = URI.escape(raw_url)&lt;br /&gt;    xml_data = Net::HTTP.get_response(URI.parse(url)).body&lt;br /&gt;    @doc = Document.new(xml_data)&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;if __FILE__ == $0&lt;br /&gt;&lt;br /&gt;  xml_project = &lt;&lt;PROJECT&lt;br /&gt;  &lt;project name='password'&gt;&lt;br /&gt;    &lt;method name='create'&gt;&lt;br /&gt;      &lt;params&gt;&lt;br /&gt;        &lt;param var='password' val='p6789c'/&gt;&lt;br /&gt;        &lt;param var='title' val='hotmail'/&gt;&lt;br /&gt;      &lt;/params&gt;&lt;br /&gt;    &lt;/method&gt;&lt;br /&gt;  &lt;/project&gt;&lt;br /&gt;PROJECT&lt;br /&gt;  &lt;br /&gt;  pxc = ProjectXClient.new("http://yourdomain.com/p/projectx.cgi?xml_project=" + xml_project)&lt;br /&gt;  doc = pxc.doc&lt;br /&gt;  puts doc&lt;br /&gt;    &lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;output -what's returned from the server is an XML response containing a result. The result echos the method executed and the output from that method, which in this instance is the xml record node 'entry'.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;result method='rtn_create'&gt;&lt;br /&gt;  &lt;append id='19367'&gt;&lt;br /&gt;    &lt;entry id='19367'&gt;&lt;br /&gt;      &lt;password&gt;p6789c&lt;/password&gt;&lt;br /&gt;      &lt;title&gt;hotmail&lt;/title&gt;&lt;br /&gt;      &lt;description/&gt;&lt;br /&gt;    &lt;/entry&gt;&lt;br /&gt;  &lt;/append&gt;&lt;br /&gt;&lt;/result&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 18 Feb 2008 18:49:42 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5150</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Getting Started With WWW::Mechanize</title>
      <link>http://snippets.dzone.com/posts/show/5134</link>
      <description>This Ruby code uses WWW:mechanize to act like a web browser.  &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt; require 'rubygems'&lt;br /&gt; require 'mechanize'&lt;br /&gt;&lt;br /&gt; agent = WWW::Mechanize.new&lt;br /&gt; page = agent.get('http://google.com/')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Refer to the documentation at http://mechanize.rubyforge.org/mechanize/. Then gem install mechanize, and try running the code in an irb session.&lt;br /&gt;&lt;br /&gt;output (extract):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;=&gt; #&lt;WWW::Mechanize::Page&lt;br /&gt; {url #&lt;URI::HTTP:0xfdbbbb286 URL:http://www.google.com/&gt;}&lt;br /&gt; {meta}&lt;br /&gt; {title "Google"}&lt;br /&gt; {iframes}&lt;br /&gt; {frames}&lt;br /&gt; {links&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Images"&lt;br /&gt;   "http://images.google.com/imghp?hl=en&amp;tab=wi"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Maps"&lt;br /&gt;   "http://maps.google.com/maps?hl=en&amp;tab=wl"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "News"&lt;br /&gt;   "http://news.google.com/nwshp?hl=en&amp;tab=wn"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Shopping"&lt;br /&gt;   "http://www.google.com/prdhp?hl=en&amp;tab=wf"&gt;&lt;br /&gt;  #&lt;WWW::Mechanize::Page::Link&lt;br /&gt;   "Gmail"&lt;br /&gt;   "http://mail.google.com/mail/?hl=en&amp;tab=wm"&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 12 Feb 2008 17:53:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5134</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Syntax-at-a-Glance for the C# programming language</title>
      <link>http://snippets.dzone.com/posts/show/4529</link>
      <description>// Copyright (C) 2001 StructureByDesign.  All Rights Reserved.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// CLASS1.CS -- Syntax-at-a-Glance for the C# programming language.&lt;br /&gt;// A quick code reference for programmers who work in many languages.&lt;br /&gt;// Executable code, minimal comments document the essence of the language.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections;&lt;br /&gt;using System.IO;&lt;br /&gt;&lt;br /&gt;namespace StructureByDesign.Syntax&lt;br /&gt;{&lt;br /&gt;public class Class1: Object&lt;br /&gt;{&lt;br /&gt;    public static int Main(string[] args)       // Entry point.&lt;br /&gt;    {&lt;br /&gt;        System.Console.WriteLine("Hello");&lt;br /&gt;        Class2 aclass2 = new Class2();&lt;br /&gt;        aclass2.run();&lt;br /&gt;        return 0;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;interface Interface1&lt;br /&gt;{&lt;br /&gt;    void run();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class Class2: Class1, Interface1&lt;br /&gt;{&lt;br /&gt;    public const int CONSTANT = 1;          // Access not restricted, implicitly static.&lt;br /&gt;    private int m_intPrivateField;          // Access limited to containing type.&lt;br /&gt;    public Class2() : base()                // Constructor.&lt;br /&gt;    {&lt;br /&gt;        initialize();&lt;br /&gt;    }&lt;br /&gt;    protected void initialize()             // Object initialization.&lt;br /&gt;    {                                       // Access limited to containing class or types derived.&lt;br /&gt;        Number = 1;&lt;br /&gt;    }&lt;br /&gt;    protected int Number                    // Language property feature.&lt;br /&gt;    {&lt;br /&gt;        get&lt;br /&gt;        {&lt;br /&gt;            return m_intPrivateField;&lt;br /&gt;        }&lt;br /&gt;        set&lt;br /&gt;        {&lt;br /&gt;            m_intPrivateField = value;      // Implicit parameter.&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    public void run()&lt;br /&gt;    {&lt;br /&gt;        anonymousCode();&lt;br /&gt;        arrays();&lt;br /&gt;        collections();&lt;br /&gt;        comparison();&lt;br /&gt;        control();&lt;br /&gt;        filesStreamsAndExceptions();&lt;br /&gt;        numbersAndMath();&lt;br /&gt;        primitivesAndConstants();&lt;br /&gt;        runtimeTyping();&lt;br /&gt;        strings();&lt;br /&gt;    }&lt;br /&gt;    void anonymousCode()&lt;br /&gt;    {&lt;br /&gt;        Delegate adelegate = new Delegate(Run);&lt;br /&gt;        adelegate();&lt;br /&gt;    }&lt;br /&gt;    delegate void Delegate();&lt;br /&gt;    void Run()&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine("Run");&lt;br /&gt;    }&lt;br /&gt;    void arrays()&lt;br /&gt;    {&lt;br /&gt;        int[] arrayOfInts = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};&lt;br /&gt;        arrayOfInts[0] = 9;&lt;br /&gt;        assert(arrayOfInts[0] == arrayOfInts[9]);&lt;br /&gt;&lt;br /&gt;        String[] arrayOfStrings = new String[10];&lt;br /&gt;        assert(arrayOfStrings[0] == null);&lt;br /&gt;        assert(arrayOfStrings.Length == 10);&lt;br /&gt;&lt;br /&gt;        arrayOfStrings = new String[] { "one", "two" };&lt;br /&gt;&lt;br /&gt;        byte[,] arrayOfBytes = { {0,0,0},&lt;br /&gt;                                 {0,1,2},&lt;br /&gt;                                 {0,2,4}};&lt;br /&gt;        assert(arrayOfBytes[2,2] == 4);&lt;br /&gt;    }&lt;br /&gt;    void collections()&lt;br /&gt;    {&lt;br /&gt;        IList ailist = new ArrayList();&lt;br /&gt;        ailist.Add("zero"); ailist.Add("one"); ailist.Add("three");&lt;br /&gt;        ailist[2] = "two";&lt;br /&gt;        assert(ailist[2].Equals("two"));&lt;br /&gt;        ailist.Remove("two");&lt;br /&gt;        ((ArrayList)ailist).Sort();&lt;br /&gt;        for(IEnumerator aie = ((ArrayList)ailist).GetEnumerator(); aie.MoveNext(); )&lt;br /&gt;            ;&lt;br /&gt;        foreach(String astring in ailist)&lt;br /&gt;            ;&lt;br /&gt;&lt;br /&gt;        IDictionary aidictionary = new Hashtable();&lt;br /&gt;        aidictionary.Add("key", "value");&lt;br /&gt;        assert(aidictionary["key"].Equals("value"));&lt;br /&gt;&lt;br /&gt;        // Set not available.&lt;br /&gt;    }&lt;br /&gt;    void comparison()&lt;br /&gt;    {&lt;br /&gt;        int aint1 = 1;&lt;br /&gt;        int aint2 = 2;&lt;br /&gt;        int aint = 1;&lt;br /&gt;        String astring1 = "one";&lt;br /&gt;        String astring2 = "two";&lt;br /&gt;        String astring = astring1;&lt;br /&gt;&lt;br /&gt;        assert(aint == aint1);&lt;br /&gt;        assert(aint1 != aint2);&lt;br /&gt;        assert(astring == astring1);&lt;br /&gt;        assert(astring1 == String.Copy("one"));         // For strings == is overloaded to compare values.&lt;br /&gt;        assert(!astring1.Equals(astring2));&lt;br /&gt;        assert(astring1.Equals(String.Copy("one")));&lt;br /&gt;&lt;br /&gt;        astring = null;&lt;br /&gt;        if (astring != null &amp;&amp; astring.Length &gt; 0)      // Conditional evaluation.&lt;br /&gt;            assert(false);&lt;br /&gt;&lt;br /&gt;        if (aint2 &lt; 0 || 1 &lt; aint2)&lt;br /&gt;            assert(true);&lt;br /&gt;    }&lt;br /&gt;    void control()&lt;br /&gt;    {&lt;br /&gt;        if (true)&lt;br /&gt;            assert(true);&lt;br /&gt;        else&lt;br /&gt;            assert(false);&lt;br /&gt;        /////&lt;br /&gt;        switch ('b') {&lt;br /&gt;            case 'a':&lt;br /&gt;                assert(false);&lt;br /&gt;                break;&lt;br /&gt;            case 'b':&lt;br /&gt;                assert(true);&lt;br /&gt;                break;&lt;br /&gt;            default:&lt;br /&gt;                assert(false);&lt;br /&gt;                break;&lt;br /&gt;        }&lt;br /&gt;        /////&lt;br /&gt;        for (int ai1 = 0; ai1 &lt; 10; ai1++)&lt;br /&gt;            assert(true);&lt;br /&gt;        /////&lt;br /&gt;        int ai = 0;&lt;br /&gt;        while (ai &lt; 10) {&lt;br /&gt;            assert(true);&lt;br /&gt;            ai++;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        do&lt;br /&gt;            ai--;&lt;br /&gt;        while (ai &gt; 0);&lt;br /&gt;&lt;br /&gt;        for (int x = 0; x &lt; 10; x++)        // Labeled break/continue not available.&lt;br /&gt;            for (int y = 0; y &lt; 10; y++)&lt;br /&gt;                if (x == 9)&lt;br /&gt;                    break;&lt;br /&gt;                else&lt;br /&gt;                    continue;&lt;br /&gt;    }&lt;br /&gt;    void filesStreamsAndExceptions()&lt;br /&gt;    {&lt;br /&gt;        FileInfo afileinfo = new FileInfo("list.txt");&lt;br /&gt;        try {&lt;br /&gt;            StreamWriter asw = new StreamWriter("list.txt");&lt;br /&gt;            asw.WriteLine("line");&lt;br /&gt;            asw.WriteLine("line");&lt;br /&gt;            asw.Close();&lt;br /&gt;&lt;br /&gt;            assert(afileinfo.Exists);&lt;br /&gt;&lt;br /&gt;            StreamReader asr = new StreamReader("list.txt");&lt;br /&gt;            String astringLine;&lt;br /&gt;            while ((astringLine = asr.ReadLine()) != null)&lt;br /&gt;                assert(astringLine.Equals("line"));&lt;br /&gt;            asr.Close();&lt;br /&gt;        } catch (IOException aexception) {&lt;br /&gt;            System.Console.WriteLine(aexception.Message);&lt;br /&gt;            throw new NotSupportedException();&lt;br /&gt;        }&lt;br /&gt;        finally {&lt;br /&gt;            afileinfo.Delete();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    void numbersAndMath()&lt;br /&gt;    {&lt;br /&gt;        assert(Int32.Parse("123") == 123);&lt;br /&gt;        assert(123.ToString().Equals("123"));&lt;br /&gt;&lt;br /&gt;        assert(Math.PI.ToString("n3").Equals("3.142"));&lt;br /&gt;&lt;br /&gt;        assert(Int32.MaxValue &lt; Int64.MaxValue);&lt;br /&gt;&lt;br /&gt;        assert(Math.Abs(Math.Sin(0) - 0) &lt;= Double.Epsilon);&lt;br /&gt;        assert(Math.Abs(Math.Cos(0) - 1) &lt;= Double.Epsilon);&lt;br /&gt;        assert(Math.Abs(Math.Tan(0) - 0) &lt;= Double.Epsilon);&lt;br /&gt;&lt;br /&gt;        assert(Math.Abs(Math.Sqrt(4) - 2) &lt;= Double.Epsilon);&lt;br /&gt;        assert(Math.Abs(Math.Pow(3,3) - 27) &lt;= Double.Epsilon);&lt;br /&gt;&lt;br /&gt;        assert(Math.Max(0,1) == 1);&lt;br /&gt;        assert(Math.Min(0,1) == 0);&lt;br /&gt;&lt;br /&gt;        assert(Math.Abs(Math.Ceiling(9.87) - 10.0) &lt;= Double.Epsilon);&lt;br /&gt;        assert(Math.Abs(Math.Floor(9.87) - 9.0) &lt;= Double.Epsilon);&lt;br /&gt;        assert(Math.Round(9.87) == 10);&lt;br /&gt;&lt;br /&gt;        Random arandom = new Random();&lt;br /&gt;        double adouble = arandom.NextDouble();&lt;br /&gt;        assert(0.0 &lt;= adouble &amp;&amp; adouble &lt; 1.0);&lt;br /&gt;        int aint = arandom.Next(10);&lt;br /&gt;        assert(0 &lt;= aint &amp;&amp; aint &lt; 10);&lt;br /&gt;    }&lt;br /&gt;    enum Season: byte { Spring=0, Summer, Fall, Winter };&lt;br /&gt;&lt;br /&gt;    void primitivesAndConstants()&lt;br /&gt;    {&lt;br /&gt;        bool abool = false;&lt;br /&gt;        char achar = 'A';           // 16 bits, Unicode&lt;br /&gt;&lt;br /&gt;        byte abyte = 0x0;           // 8 bits, unsigned, hex constant&lt;br /&gt;        sbyte asbyte = 0;           // 8 bits, signed&lt;br /&gt;&lt;br /&gt;        short ashort = 0;           // 16 bits, signed&lt;br /&gt;        ushort aushort = 0;         // 16 bits, unsigned&lt;br /&gt;&lt;br /&gt;        int aint = 0;               // 32 bits, signed&lt;br /&gt;        uint aunit = 0;             // 32 bits, unsigned&lt;br /&gt;&lt;br /&gt;        long along = 0L;            // 64 bits, signed&lt;br /&gt;        ulong aulong = 0;           // 64 bits, unsigned&lt;br /&gt;&lt;br /&gt;        float afloat = 0.0F;        // 32 bits&lt;br /&gt;        double adouble = 0.0;       // 64 bits&lt;br /&gt;&lt;br /&gt;        decimal adecimal = 0;       // 128 bits, financial calculations&lt;br /&gt;&lt;br /&gt;        Season aseason = Season.Fall;&lt;br /&gt;        assert((byte)aseason == 2);&lt;br /&gt;    }&lt;br /&gt;    void runtimeTyping()&lt;br /&gt;    {&lt;br /&gt;        assert(new int[] { 1 } is int[]);&lt;br /&gt;        assert(new ArrayList() is ArrayList);&lt;br /&gt;&lt;br /&gt;        assert((new ArrayList()).GetType() == typeof(ArrayList));&lt;br /&gt;        assert(typeof(Int32) is Type);      // Type of primitive type.&lt;br /&gt;&lt;br /&gt;        assert(Type.GetType("System.Collections.ArrayList") == typeof(ArrayList));&lt;br /&gt;    }&lt;br /&gt;    void strings()&lt;br /&gt;    {&lt;br /&gt;        String astring1 = "one";&lt;br /&gt;        String astring2 = "TWO";&lt;br /&gt;&lt;br /&gt;        assert((astring1 + "/" + astring2).Equals("one/TWO"));&lt;br /&gt;        assert(astring2.ToLower().Equals("two"));   // Equals ignoring case not available.&lt;br /&gt;        assert(astring1.Length == 3);&lt;br /&gt;        assert(astring1.Substring(0,2).Equals("on"));&lt;br /&gt;        assert(astring1[2] == 'e');&lt;br /&gt;        assert(astring1.ToUpper().Equals("ONE"));&lt;br /&gt;        assert(astring2.ToLower().Equals("two"));&lt;br /&gt;        assert(astring1.CompareTo("p") &lt; 0);&lt;br /&gt;        assert(astring1.IndexOf('e') == 2);&lt;br /&gt;        assert(astring1.IndexOf("ne") == 1);&lt;br /&gt;        assert(astring1.Trim().Length == astring1.Length);&lt;br /&gt;&lt;br /&gt;        assert(Char.IsDigit('1'));&lt;br /&gt;        assert(Char.IsLetter('a'));&lt;br /&gt;        assert(Char.IsWhiteSpace('\t'));&lt;br /&gt;        assert(Char.ToLower('A') == 'a');&lt;br /&gt;        assert(Char.ToUpper('a') == 'A');&lt;br /&gt;    }&lt;br /&gt;    private void assert(bool abool)&lt;br /&gt;    {&lt;br /&gt;        if (!abool)&lt;br /&gt;            throw new Exception("assert failed");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Sep 2007 05:53:00 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4529</guid>
      <author>dubby (Dave)</author>
    </item>
    <item>
      <title>Reading an xml file from a URL and  saving it locally</title>
      <link>http://snippets.dzone.com/posts/show/4512</link>
      <description>// description of your code here&lt;br /&gt;This code reads an xml file, modifys an element and saves the file locally. &lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;require 'rexml/document'&lt;br /&gt;&lt;br /&gt;url = 'http://www.example.com/journal080907.xml'&lt;br /&gt;&lt;br /&gt;element_name = ARGV[0] # basic_category&lt;br /&gt;xpath = ARGV[1] # eg.'entries/entry'&lt;br /&gt;file = ARGV[2] # eg. 'journal080907.xml'&lt;br /&gt;element_value = ARGV[3] # 'ruby'&lt;br /&gt;&lt;br /&gt;file = File.new(file,'w')&lt;br /&gt;# get the XML data as a string&lt;br /&gt;xml_data = Net::HTTP.get_response(URI.parse(url)).body&lt;br /&gt;&lt;br /&gt;# extract event information&lt;br /&gt;doc = REXML::Document.new(xml_data)&lt;br /&gt;docx = doc&lt;br /&gt;&lt;br /&gt;node = docx.elements[xpath]&lt;br /&gt;element = node.elements[element_name]&lt;br /&gt;puts element.text&lt;br /&gt;element.text = 'ruby'&lt;br /&gt;file.puts docx&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 08 Sep 2007 14:20:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4512</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Acceder a la fecha en la que una foto fue tomada en VB .NET</title>
      <link>http://snippets.dzone.com/posts/show/2931</link>
      <description>//Funci&#243;n a la que se le pasa el archivo jpg o jpge y devuelve la fecha en la que fue tomada&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    Public Function ObtieneFecha(ByVal RutaArchivo As String) As Date&lt;br /&gt;&lt;br /&gt;        Dim image As New Bitmap(RutaArchivo)&lt;br /&gt;        Dim propItems As System.Drawing.Imaging.PropertyItem() = image.PropertyItems&lt;br /&gt;&lt;br /&gt;        Dim encoding As New System.Text.ASCIIEncoding&lt;br /&gt;&lt;br /&gt;        For i As Integer = propItems.GetLowerBound(0) To propItems.GetUpperBound(0)&lt;br /&gt;            If propItems(i).Id.ToString = "36868" Then&lt;br /&gt;                Dim strAux1() As String = Split(encoding.GetString(propItems(i).Value), " ")&lt;br /&gt;                Dim strAux2() As String = Split(strAux1(0), ":")&lt;br /&gt;                Dim strAux3() As String = Split(strAux1(1), ":")&lt;br /&gt;                Return CDate(strAux2(0) &amp; "/" &amp; strAux2(1) &amp; "/" &amp; strAux2(2) &amp; " " &amp; strAux3(0) &amp; ":" &amp; strAux3(1) &amp; ":" &amp; strAux3(2))&lt;br /&gt;            End If&lt;br /&gt;        Next&lt;br /&gt;        image.Dispose()&lt;br /&gt;    End Function&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 30 Oct 2006 22:16:11 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2931</guid>
      <author>ceronegativo (Pablo)</author>
    </item>
    <item>
      <title>Python - getFile Internet</title>
      <link>http://snippets.dzone.com/posts/show/2746</link>
      <description>// Scaricare un file dalla rete&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;package get.file.example;&lt;br /&gt;&lt;br /&gt;import java.io.BufferedInputStream;&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import java.net.MalformedURLException;&lt;br /&gt;import java.net.URL;&lt;br /&gt;&lt;br /&gt;public class GetFileExample&lt;br /&gt;{&lt;br /&gt;	public GetFileExample()&lt;br /&gt;	{&lt;br /&gt;		try&lt;br /&gt;		{&lt;br /&gt;			byte[] bite = new byte[2048];&lt;br /&gt;			int read;&lt;br /&gt;			URL url = new URL("http://switch.dl.sourceforge.net/sourceforge/pys60miniapps/FlickrS60_src_v0.1b.tar.bz2");&lt;br /&gt;			&lt;br /&gt;			BufferedInputStream bis = new BufferedInputStream(url.openStream());&lt;br /&gt;			FileOutputStream fos = new FileOutputStream("/tmp/file.tar.bz2");&lt;br /&gt;			&lt;br /&gt;			while((read = bis.read(bite))&gt;0)&lt;br /&gt;			{&lt;br /&gt;				fos.write(bite, 0, read);&lt;br /&gt;				System.out.println("--");&lt;br /&gt;			}&lt;br /&gt;			&lt;br /&gt;			fos.close();&lt;br /&gt;			bis.close();&lt;br /&gt;			&lt;br /&gt;			System.out.println("FINE");&lt;br /&gt;			&lt;br /&gt;		}&lt;br /&gt;		catch(MalformedURLException e)&lt;br /&gt;		{&lt;br /&gt;			e.printStackTrace();&lt;br /&gt;		}&lt;br /&gt;		catch(IOException e)&lt;br /&gt;		{&lt;br /&gt;			e.printStackTrace();&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	public static void main(String[] args)&lt;br /&gt;	{&lt;br /&gt;		new GetFileExample();&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 30 Sep 2006 22:35:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2746</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Use the del.icio.us API via HTTPS from Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2431</link>
      <description>Found at &lt;a href="http://www.juretta.com/log/2006/08/13/ruby_net_http_and_open-uri/"&gt;http://www.juretta.com/log/2006/08/13/ruby_net_http_and_open-uri/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/https'&lt;br /&gt;require "rexml/document"&lt;br /&gt;&lt;br /&gt;username = "" # your del.icio.us username&lt;br /&gt;password = "" # your del.icio.us password&lt;br /&gt;&lt;br /&gt;resp = href = "";&lt;br /&gt;begin      &lt;br /&gt;  http = Net::HTTP.new("api.del.icio.us", 443)&lt;br /&gt;  http.use_ssl = true&lt;br /&gt;  http.start do |http|&lt;br /&gt;    req = Net::HTTP::Get.new("/v1/tags/get", {"User-Agent" =&gt; &lt;br /&gt;        "juretta.com RubyLicious 0.2"})&lt;br /&gt;    req.basic_auth(username, password)&lt;br /&gt;    response = http.request(req)&lt;br /&gt;    resp = response.body&lt;br /&gt;  end     &lt;br /&gt;  #  XML Document&lt;br /&gt;  doc = REXML::Document.new(resp)    &lt;br /&gt;  # iterate over each element &lt;tag count="200" tag="Rails"/&gt;&lt;br /&gt;  doc.root.elements.each do |elem|&lt;br /&gt;    print elem.attributes['tag']  + " -&gt; " + elem.attributes['count'] + "\n"&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;rescue SocketError&lt;br /&gt;  raise "Host " + host + " nicht erreichbar"&lt;br /&gt;rescue REXML::ParseException =&gt; e&lt;br /&gt;  print "error parsing XML " + e.to_s&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 16 Aug 2006 21:37:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2431</guid>
      <author>jswizard (JavaScript Wizard)</author>
    </item>
    <item>
      <title>Removing accents in NET 2.0 with C#</title>
      <link>http://snippets.dzone.com/posts/show/1962</link>
      <description>Removing accents in NET 2.0&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;static string UrlSanitize(string url)&lt;br /&gt;{&lt;br /&gt;	url = Regex.Replace(url, @"\s+", "-");&lt;br /&gt;	string stFormD = url.Normalize(NormalizationForm.FormD);&lt;br /&gt;	StringBuilder sb = new StringBuilder();&lt;br /&gt; &lt;br /&gt;	for (int ich = 0; ich &lt; stFormD.Length; ich++)&lt;br /&gt;	{&lt;br /&gt;		UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(stFormD[ich]);&lt;br /&gt;		if (uc != UnicodeCategory.NonSpacingMark)&lt;br /&gt;		{&lt;br /&gt;			sb.Append(stFormD[ich]);&lt;br /&gt;		}&lt;br /&gt;	}&lt;br /&gt; &lt;br /&gt;	return (sb.ToString());&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 26 Apr 2006 16:10:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1962</guid>
      <author>brau ()</author>
    </item>
    <item>
      <title>conectarte a una base de datos con .net</title>
      <link>http://snippets.dzone.com/posts/show/1854</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;SqlConnection conn = null;&lt;br /&gt;SqlCommand cmd = null;&lt;br /&gt;SqlDataReader dr = null;&lt;br /&gt;&lt;br /&gt;String s = null;&lt;br /&gt;Product prod = null;&lt;br /&gt;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;	conn = new SqlConnection("Provider=SQLOLEDB;SERVER=sissql2;UID=sa;PWD=AlfaRoma440;DATABASE=genericatest2");&lt;br /&gt;&lt;br /&gt;	s = " ";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;	cmd = new SqlCommand(s,conn);&lt;br /&gt;	dr = cmd.ExecuteReader();&lt;br /&gt;	// lleno el objeto producto&lt;br /&gt;&lt;br /&gt;	while( dr.Read())&lt;br /&gt;	{&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;catch (Exception ex)&lt;br /&gt;{&lt;br /&gt;	// poner el manejo de errores	&lt;br /&gt;}&lt;br /&gt;finally&lt;br /&gt;{&lt;br /&gt;	dr.Close();&lt;br /&gt;	conn.Close();&lt;br /&gt;}&lt;br /&gt;dr.Close();&lt;br /&gt;conn.Close();&lt;br /&gt;return prod;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 06 Apr 2006 21:44:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1854</guid>
      <author>ivan_cursos (Ivan)</author>
    </item>
    <item>
      <title>URI Parse</title>
      <link>http://snippets.dzone.com/posts/show/1012</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'net/http'&lt;br /&gt;res = Net::HTTP.get_response(URI.parse('http://www.example.com'))&lt;br /&gt;print res.body&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 24 Dec 2005 00:28:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1012</guid>
      <author>joe_black (joe black)</author>
    </item>
  </channel>
</rss>
