Saturday, September 1, 2012

Send a facebook message using php

Facebook API does not provide any method for sending a message to the inbox of a user. Fortunately, messages can also be sent using XMPP, which is used by facebook chat, but can also be used for sending a message to a user that is offline (i.e., the message will appear in the user's inbox).

In this link you can find a php class that utilizes facebook's XMPP functionality and sends a message to a facebook user.

In order to use this class you need to obtain an API key, by registering your application here. In order to use this class you should provide, your API key, your user id, the current authorization token, and the user id of the user to which you wish to send a message.

In order to get your user id, you can user the facebook php sdk and use the getUser() method of the Facebook class. In order to get the authorization token you can invoke the getAccessToken() of the Facebook class

Wednesday, August 1, 2012

A proxy re-encryption implementation

Proxy re-encryption is scheme that allows a proxy to re-encrypt a ciphertext, encrypted with the public key of a user A, into a ciphertext that can be decrypted with a private key of a user B, without having access to the private key of A or B, as well as to the plaintext.

Green and Ateniese describe an Identity-based proxy re-encryption scheme in their paper and prove its security. An implementation of their solution can be found in my github repository. This is a python implementation using the Charm Crypto tool

Sunday, July 1, 2012

Export excel diagrams to pdf and use them in latex

If you are creating your diagrams using Excel 2007, there is an easy way to export them in .pdf and then use them as figures in your latex documents.

 Open your excel document, select your diagram and then press the office logo and select save as->pdf or exps. Choose a file name and select save as file type tou be PDF (*.pdf). This will result in a pdf file with the diagram and a lot of blank space. In order to remove the blank space use pdfcrop. This a utility is included both in MikTex (latex for windows) as well as in texlive-extra-utils ubuntu package. Alternatevily you can download it from here

Friday, June 1, 2012

Running an IIS7 site from a network drive

Running a web site, located in a network share, in IIS7 can be really tricky, as it usually ends up with IIS7 complaining about permission problem. This usually happens because IIS processes run as a different user, who is not allowed to access network shares. In this blog post it is shown how a web site can be run in the context of a user that is eligible to access a network share.

 But before we start an important note: Running a web site in the context of a privileged user may possibly entail security risks.

In this blog post the following setup is considered: a network drive with IP 192.168.2.6 and share called fotiou, which is password-protected. The share has been mapped, by user User_NAME, to a network drive (Z:), windows have been configured to connect to that drive on start up, and our web site is located in Z:\wordpress.

 From the IIS7 manager console add a new web site. In our case the site is named wordpress. In the Physical path textbox insert the full URI to the website and not the mapped drive (in our case this would be \\192.168.2.6\fotiou\wordpress), and press OK.

Now navigate in the Application Pools located above the Sites option (see the picture below)

From the Application Pools list select the newly created site (named wordpress in our example, as depicted below)

Right click and select Advanced Settings. The in the Process Model tab, edit the Identity option, by selecting the Custom account option, and by setting it to the current user, as in the picture below


Now navigate back to the Sites tree, select your web site and double click the Authentication option


Double click on the Anonymous Authentication option and select Application pool identity


Now your web site can be run without permission problems.

Tuesday, May 1, 2012

Handle Geek characters in an Access database with Java

When reading Greek characters from an access database special action needs to be taken in order to properly display them. The following code prints two string fields named name and surname, stored in an access database:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "THE_MDB_FILE";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database += filename.trim() + ";DriverID=22;READONLY=true;useUnicode=true}";
dbConnection = DriverManager.getConnection(database);
Statement s = dbConnection.createStatement();
String query = "Select * from Users";
ResultSet rs = s.executeQuery(query);
String name = new String(rs.getBytes("Name"),"ISO8859_7");
String surname = new String(rs.getBytes("SurName"),"ISO8859_7");
System.out.println("Name:" + name + " Surname:" + surname);

Sunday, April 1, 2012

Fast file searching in C#

This code shows how can you search for a file in C# using windows index and OleDB. The code below is tested in windows Vista where file indexing is enable by default. The following function, when called, outpust the fullpath of the file in request. It uses the operating system's file index therefore is very fast!


using System;
using System.Data.OleDb;

namespace MyBrowser
{
    class Browser
    {
        public void findFile(string fileName)
        {
            
            try
            {
                string url = "provider=Search.CollatorDSO.1;" +
                    "EXTENDED PROPERTIES=\"Application=Windows\"";
                OleDbConnection connection = new OleDbConnection(url);
                string queryString = "Select System.ItemPathDisplay from "+
                    "SystemIndex where System.FileName ='" + fileName + "' ";
                Console.WriteLine(queryString);
                OleDbCommand command = new OleDbCommand(queryString, connection);
                connection.Open();
                OleDbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine(reader[0].ToString());
                }
                reader.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            
        }
    }
}

Thursday, March 1, 2012

C++ map random value

This code shows how can you get a random value out of a C++ map structure


map<string, int> myMap;
 /*
  * Put code here that fills the map
  */
map<string, int>::iterator iter = myMap.begin();
map<string, int>::size_type myMapSize;
myMapSize = myMap.size();
int random_integer =  intrand(myMapSize);
advance(iter,random_integer);
cout <<iter->first;