Blogue de Guillaume DALLAIRE's Blog

March 25, 2010

Sans fil au CÉGEP de Chicoutimi sous Ubuntu

Filed under: Internet Infrastructure — Tags: , , — gdallaire @ 4:24 pm

Voici la procédure pour configurer un ordinateur sous Ubuntu (9.10) pour utiliser le réseau wifi du CÉGEP de Chicoutimi:

Allez chercher votre certificat en vous connectant sur : http://sf.cegep-chiccoutimi.qc.ca (téléchargez votre certificat dans un fichier local)

Téléchargement du certificat

Votre assistant réseau devrait détecter le réseau “cchic”, allez modifier les propriétés:

Panneau de contrôle

C’est un de mes étudiants, Mathieu Gaudreault, qui avec plusieurs essais/erreurs est parvenu à trouver les bons paramètres.

March 22, 2010

Really basic chat client using JMS

Filed under: Java — gdallaire @ 10:33 pm

Here is a simple example of a chat client using JMS. I wrote it to show to my students how to use JMS. It implements 3 commands : /exit, /nick and /join. By default, it connects to the topic “chat.public”, entering “/join newRoom” switches the client to the “chat.newRoom” topic.

I used ActiveMQ as JMS provider. See the jndi.properties file below.

Under Eclipse, just add “activemq-all-x.y.z.jar” as External Jar (Project’s properties, Java Build Path, Add External Jars).

import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.*;

/**
 * very basic chat client over a JMS topic
 * 2010-03-20 Guillaume DALLAIRE
 *
 * Commands are:
 *    /exit : close connection and exit
 *    /nick xxxx : change user's name
 *    /join xxxx : change user's room
 */
public class Chat implements MessageListener
{
	private Destination currentDestination = null;
	private Session jmsSession;
	private Connection jmsConnection;
	private ConnectionFactory jmsConnectionFactory = null;
	private MessageConsumer jmsConsumer;
	private MessageProducer jmsProducer;
	private TextMessage jmsMessage;

	private String myNick = null;

	public Chat()
	{
		createSession();
		try
		{
			myNick = jmsConnection.getClientID();
		} catch (Exception e) {}
	}

	public void onMessage(Message message)
	{
		try
		{
			if (! (message instanceof TextMessage) )
			{
				//System.out.println("onMessage() received an unhandled: " + message.getClass().getName());
			}
			TextMessage textMessage = (TextMessage) message;
			System.out.println(textMessage.getText());
		}
		catch (Throwable t)
		{
			System.err.println((t instanceof JMSException) ? "JMSException" : "Throwable" + " Caught in onMessage(): " + t.getMessage());
		}
	}

	private void createSession()
	{
		try
		{
			Context jndiContext = null;

			try
			{
				jndiContext = new InitialContext();
			}
			catch (NamingException e)
			{
				System.out.println("Could not create JNDI API context: " + e.toString());
				System.exit(1);
			}

			try
			{
				jmsConnectionFactory = (ConnectionFactory) jndiContext.lookup(
					"connectionFactory");
			}
			catch (Exception e)
			{
				System.out.println("Connection: JNDI API lookup failed: " + e.toString());
				e.printStackTrace();
				System.exit(1);
			}

			jmsConnection = jmsConnectionFactory.createConnection();

			// create a session
			this.jmsSession = jmsConnection.createSession(
					false /* not transacted */, Session.AUTO_ACKNOWLEDGE);

			joinRoom("public");

			// now that everything is ready to go, start the connection
			jmsConnection.start();

			jmsMessage = jmsSession.createTextMessage();

		}
		catch (JMSException ex)
		{
			System.out.println("Error running program");
			ex.printStackTrace();
		}
	}

	private void joinRoom(String room)
	{
		// prefix all room's name with chat.
		room = "chat." + room;

		if (currentDestination != null)
		{
			try
			{
				jmsConsumer.close();
				jmsProducer.close();
			}
			catch (Exception e)
			{
			}
		}
		try
		{
			currentDestination = jmsSession.createTopic(room);

			jmsConsumer = jmsSession.createConsumer(currentDestination);
			jmsConsumer.setMessageListener(this); 			

			// create a producer
			jmsProducer = jmsSession.createProducer(currentDestination);
		}
		catch (Exception e)
		{
		}
	}

	private void sendMsg(String msg)
	{
		try
		{
			jmsMessage.setText(myNick+": "+ msg);
			jmsProducer.send(jmsMessage);
		}
		catch (JMSException ex)
		{
			System.out.println("Error running program");
			ex.printStackTrace();
		}
	}

	public void start() {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		while (true)
		{
			String str;
			try
			{
				str = in.readLine();
			}
			catch (IOException e)
			{
				break;
			}

			if (str.isEmpty())
				continue;

			if (str.equalsIgnoreCase("/exit"))
				break;
			if (str.startsWith("/nick"))
			{
				String tmp = str.substring(6);
				str = "was known as " + myNick;
				myNick = tmp;
			}
			if (str.startsWith("/join"))
			{
				sendMsg("is leaving this room...");
				joinRoom(str.substring(6));
				str = "is entering this room...";
			}
			sendMsg(str);
		}
	}

	private void closeSession()
	{
		try
		{
			jmsSession.close();
			jmsConnection.close();
		} catch (JMSException ex) {
			System.out.println("Error running program");
			ex.printStackTrace();
		}
	}

	public static void main(String args[])
	{
		Chat client = new Chat();
		client.start();
		client.closeSession();
	}
}

jndi.properties file :

java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory

# use the following property to configure the default connector
java.naming.provider.url = tcp://127.0.0.1:61616

# use the following property to specify the JNDI name the connection factory
# should appear as.
connectionFactoryNames = connectionFactory

March 20, 2010

Nouveau laptop Studio XPS 1340

Filed under: Uncategorized — gdallaire @ 11:54 am

Cette semaine j’ai changé d’ordinateur portable pour un Dell Studio XPS 1340 (écran 13″ (bon ratio portabilité/ergonomie d’utilisation), Core 2 Duo 2.53GHz, 4GB DDR3 RAM, HD@7.2k RPM) : Voici un extrait de dmidecode:

System Information
        Manufacturer: Dell Inc.
        Product Name: Studio XPS 1340
        Version: A07

Je voulais plus de puissance pour rouler des machines virtuelles avec KVM. J’avais un netbook MSI U100 qui allait très bien mais qui était trop démuni pour supporter la virtualisation.

Nul besoin de dire que je n’ai même pas essayé cet ordinateur avec l’OS déjà installé par défaut (Vista) : Je l’ai soulagé en installant la dernière d’Ubuntu en version 64 bits.

Ce fût un succès, tous ses composants sont bien supportés (carte wifi, carte graphique Nvidia en mode deux écrans (dual head), et le reste sauf la caméra que je n’ai pas testée. Ce succès n’est pas une surprise car Dell offre ou a offert dans le passé ce modèle pré-installé avec Ubuntu.

Le seul défaut que je lui reproche est qu’il est un peu chaud après quelques minutes de fonctionnement (c’est légèrement désagréable quand on utilise son clavier, les mains sont appuyées sur le boitier et on sent la chaleur). Peut-être qu’il faudrait que je fasse quelques ajustements sous Linux pour qu’il limite les accès au disque ou autres choses qui génèrent trop d’activités. Apparemment je ne suis pas le seul avec ce problème.

Autrement tout va bien, je peux rouler une VM Windows 7 en faisant pleins d’autres choses (Eclipse, Open Office, etc….) sans problème et l’expérience est “agréable”.

En terminant, voici le résultat de la commande lspci:

00:00.0 Host bridge: nVidia Corporation MCP79 Host Bridge (rev b1)
00:00.1 RAM memory: nVidia Corporation MCP79 Memory Controller (rev b1)
00:03.0 ISA bridge: nVidia Corporation MCP79 LPC Bridge (rev b2)
00:03.1 RAM memory: nVidia Corporation MCP79 Memory Controller (rev b1)
00:03.2 SMBus: nVidia Corporation MCP79 SMBus (rev b1)
00:03.3 RAM memory: nVidia Corporation MCP79 Memory Controller (rev b1)
00:03.5 Co-processor: nVidia Corporation MCP79 Co-processor (rev b1)
00:04.0 USB Controller: nVidia Corporation MCP79 OHCI USB 1.1 Controller (rev b1)
00:04.1 USB Controller: nVidia Corporation MCP79 EHCI USB 2.0 Controller (rev b1)
00:06.0 USB Controller: nVidia Corporation MCP79 OHCI USB 1.1 Controller (rev b1)
00:06.1 USB Controller: nVidia Corporation MCP79 EHCI USB 2.0 Controller (rev b1)
00:08.0 Audio device: nVidia Corporation MCP79 High Definition Audio (rev b1)
00:09.0 PCI bridge: nVidia Corporation MCP79 PCI Bridge (rev b1)
00:0a.0 Ethernet controller: nVidia Corporation MCP79 Ethernet (rev b1)
00:0b.0 SATA controller: nVidia Corporation MCP79 AHCI Controller (rev b1)
00:0c.0 PCI bridge: nVidia Corporation MCP79 PCI Express Bridge (rev b1)
00:10.0 PCI bridge: nVidia Corporation MCP79 PCI Express Bridge (rev b1)
00:15.0 PCI bridge: nVidia Corporation MCP79 PCI Express Bridge (rev b1)
00:16.0 PCI bridge: nVidia Corporation MCP79 PCI Express Bridge (rev b1)
00:17.0 PCI bridge: nVidia Corporation MCP79 PCI Express Bridge (rev b1)
00:18.0 PCI bridge: nVidia Corporation MCP79 PCI Express Bridge (rev b1)
01:07.0 FireWire (IEEE 1394): Ricoh Co Ltd R5C832 IEEE 1394 Controller (rev 05)
01:07.1 SD Host controller: Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter (rev 22)
01:07.2 System peripheral: Ricoh Co Ltd R5C843 MMC Host Controller (rev 12)
01:07.3 System peripheral: Ricoh Co Ltd R5C592 Memory Stick Bus Host Adapter (rev 12)
01:07.4 System peripheral: Ricoh Co Ltd xD-Picture Card Controller (rev ff)
02:00.0 VGA compatible controller: nVidia Corporation G98 [GeForce 9200M GS] (rev a1)
03:00.0 VGA compatible controller: nVidia Corporation C79 [GeForce 9400M G] (rev b1)
06:00.0 Network controller: Broadcom Corporation BCM4322 802.11a/b/g/n Wireless LAN Controller (rev 01)

Nouveau site web pour AliConseil

Filed under: Internet Infrastructure — gdallaire @ 10:52 am

Je viens de refaire une beauté au site web de l’entreprise de consultation alimentaire de ma conjointe : http://aliconseil.com

C’est pour moi une autre occasion d’aiguiser mes talents en SEO.

January 22, 2010

Easy geocoding with Google Maps using python

Filed under: python — Tags: , , , — gdallaire @ 5:16 pm

For a project, I had to resolve street address into geographic coordinates (geocode), here is a minimal piece of code using the Google Maps API Services :

import urllib
import json

def geocode(addr, api_key=''):
  url = "http://maps.google.com/maps/geo?q=%s&output=json&api_key=%s" % (urllib.quote(addr), urllib.quote(api_key))
  data = urllib.urlopen(url).read()
  return json.loads(data)['Placemark'][0]['Point']['coordinates']

data = geocode("1600 Amphitheatre Parkway Mountain View, CA 94043")
print "lat:%s long:%s" % (data[0], data[1])
Older Posts »

Powered by WordPress