Quick tip: All-in-One Gestures on Firefox 3.5

Filed Under (Tips & Tricks) by The Chef on 30-06-2009

Tagged Under : , , ,

Today the new Firefox 3.5 has arrived. But after installing it the addons nightmare begins: incompatible versions. I can live without some of them but no TabMixPlus and All-in-One Gestures. I found a TMP version for Firefox 3.5b but there was no gestures and instinctively the contextual menu was popping around. After some research I managed to trick the old version to work on the new Firefox 3.5. Here is how:

  1. Go to the plugin page: All-in-One Gestures
  2. Right click on the “add to firefox” button and save link as
  3. You will get a .xpi file which is a zip archive
  4. Rename the .xpi adding .zip to the end
  5. Open it and extract install.rdf
  6. Open install.rdf with a text editor and look forĀ  <em:maxVersion>3.0.*</em:maxVersion>
  7. Change it to <em:maxVersion>4.0.*</em:maxVersion>
  8. Copy the new install.rdf into the zip
  9. Remove the .zip extension
  10. Drag the .xpi to firefox

Enjoy !

Simple ImageShack upload using C#

Filed Under (c#) by The Chef on 08-06-2009

Tagged Under : , , ,

First of all this class is based on the http helper class. The rest is trivial. Here is a piece of code

    public static class ImageShack
    {
        private static http http = new http();

        public static String UploadImage(String filename)
        {
            http.PostMode = PostMode.Multipart;
            http.AddPostKey("xml", "yes");
            http.AddPostFile("fileupload", filename);
            return http.GetUrl("http://www.imageshack.us/index.php");
        }
    }

The result is an xml. You can deserialize it using the XML serializer/deserializer from the previous post.

    [Serializable]
    public class links
    {
        public String image_link;
        public String thumb_link;
        public String ad_link;
        public String thumb_exists;
        public int total_raters;
        public float ave_rating;
        public String server;
        public String image_name;
        public String done_page;
        public String resolution;
        public int filesize;
        public String image_class;
    }

.
.
.
imageshark isr=new imageshark();
links lnk = new links();
lnk = XMLData.ObjectXMLSerializer<links>.LoadString(ImageShack.UploadImage("picture.png"));
Console.WriteLine(lnk.image_link);

Hope it helps. Enjoy

XML class serializer in C#

Filed Under (c#) by The Chef on 06-06-2009

Tagged Under : , , , ,

Here it is a short class very useful for serializing and deserializing. This is a good for settings file or configuration files.

using System.Xml.Serialization;
using System.IO;
using System.Text;

namespace XMLData
{
    public static class ObjectXMLSerializer<T> where T : class
    {
        public static T Load(string path)
        {
            T mRet = null;

            using (TextReader textReader = new StreamReader(path))
            {
                XmlSerializer mXmlSerializer = new XmlSerializer(typeof(T));
                mRet = mXmlSerializer.Deserialize(textReader) as T;
            }

            return mRet;
        }

        public static void Save(T serializableObject, string path)
        {
            using (TextWriter mTextWriter = new StreamWriter(path))
            {
                XmlSerializer mXmlSerializer = new XmlSerializer(typeof(T));
                mXmlSerializer.Serialize(mTextWriter, serializableObject);
            }
        }
        public static T LoadString(string mString)
        {
            T mRet = null;

            using (MemoryStream textReader = new MemoryStream(Encoding.ASCII.GetBytes(mString)))
            {
                XmlSerializer mXmlSerializer = new XmlSerializer(typeof(T));
                mRet = mXmlSerializer.Deserialize(textReader) as T;
            }

            return mRet;
        }
    }
}

Here it is a short usage example:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            links lnk = new links();
            lnk.str = "something";
            lnk.integer = 23;
            lnk.floatnumber = 0.23f;
            lnk.stringlist.Add("element 1");
            lnk.stringlist.Add("element 2");
            lnk.stringlist.Add("element 3");
            //save class to xml
            XMLData.ObjectXMLSerializer<links>.Save(lnk, @"c:\test.xml");
            //load class from xml
            lnk = XMLData.ObjectXMLSerializer<links>.Load(@"c:\test.xml");
        }

    }

    [Serializable]
    public class links
    {
        public String str;
        public int integer;
        public float floatnumber;
        public List<string> stringlist = new List<string>();
    }
}

and this is the xml it produces:

<?xml version="1.0" encoding="utf-8"?>
<links xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <str>something</str>
  <integer>23</integer>
  <floatnumber>0.23</floatnumber>
  <stringlist>
    <string>element 1</string>
    <string>element 2</string>
    <string>element 3</string>
  </stringlist>
</links>