Wednesday, November 30, 2011

XML (w/o) Higlighting in Latex + using it in a figure - 2

Well.. I had a style conflict with my previous solution. So I gave up using a highlighted version, but just an XML text (with correct tab indentations of course!). I also needed to put a frame outside my xml document, and got this I found a nice Latex package called "fancyvrb". With a simple "frame" attribute, it works great.. Hope it helps!..

\begin{figure}[htbp]
\begin{Verbatim}[frame=single]
<task id="..." performer="..." type="...">
    <name>...</name>           
    <description>...</description>       
    <params>
        <param type="..." name="..." datatype="..."/>
        .
        .
    </params>  
</task>
\end{Verbatim}
% \vskip
\label{fig:spec_task}
\end{figure}

Monday, November 28, 2011

XML Higlighting in Latex + using it in a figure

It's been a while that I did not have time to write something.. It doesn't mean that I don't have anything to write about.. and.. of course I have! :)

I'm busy with writing my thesis using Latex, it's sometimes a great tool to use.. And other times, you're getting really frustrated to achieve what you really wanna do!


This time I was trying to simply put an XML content in a table/figure or such, because I needed to refer to it later on in my thesis.. I cannot just put the content as it is.. If you are in trouble just like me, am sure you found two great XML highlighters: "minted" and using "listings" package. Both work like a charm, but the problem is when you wanna put XML content in a table/figure. Well, highlighting sucks in such cases.

One solution that I found is as the following:

\begin{figure}[htbp]
\begin{minted}{xml}
   <book isbn="978-0452284234"> 
      <name<Nineteen Eighty Four</name>
      <author<George Orwell</author>
   </book>
\end{minted}
\caption[XML Representation Example]{XML Representation Example}
% \vskip
\label{fig:xml}
\end{figure}

I did not try for "listings" package, but I think it will also work.. With this, you'll get a result as the following:
Photobucket

Hope it helps!..

Sunday, August 28, 2011

Format a disk with HFS+ using GParted on Ubuntu

If you have a Mac, it means that you always have trouble :P

You are using Ubuntu or any other linux dist, and have an external drive. You HAVE to format it with HFS+ because you want to use it with a Mac. Grrr...

No panic.. You are able to format your external drive using Ubuntu.. First thing to do is that you have to install "hfsprogs" package. Simply install it by typing the following in a terminal:

sudo apt-get install hfsprogs


Then, you can just use GParted to format your drive. Go to System > Administration > Gparted, select your external drive from the dropdown menu on the right. When you choose to format your disk/partition, you'll see "HFS+" as an option. Select it and wait a little bit. And.. Da daaa.. Now you can use your external drive with a Mac!

Hope it helps!.. Enjoy..

Python on the Fly Code Generator

Hey everyone,

I know that I'm not blogging for a while. It doesn't mean that I don't have anything to share :P
I'm currently working on my master thesis and I'm using Python for coding part. Today, I was looking for a python library to be able to generate python code on the fly. Of course, first idea is to create a file, adding imports, classes, methods and so on.. I only found a helper class written by Fredrik Lundh in this blog post.

I liked this idea and extended the code just a little bit. I want to work on a more complete library in few months. Do not forget to check my blog for the updates. And here is the simple class code:

#
# a Python code generator backend
#
# fredrik lundh, march 1998
#
# fredrik@pythonware.com
# http://www.pythonware.com
#
# extended by Nadin Kokciyan
# nadin.kokciyan@boun.edu.tr
#
import sys, string

class PyGen:

    def __init__(self):
        self.code = []
        self.tab = "    "
        self.level = 0

    def end(self):
        return string.join(self.code, "")

    def write(self, string):
        self.code.append(self.tab * self.level + string + "\n")

    def newline(self, no=1):
        res=""        
        i = 1        
        while(i<=no):
            res += "\n"
            i += 1
        self.code.append(res)

    def indent(self):
        self.level = self.level + 1

    def dedent(self):
        if self.level == 0:
            raise SyntaxError, "internal error in code generator"
        self.level = self.level - 1
Example Usage:
c = PyGen()

c.write("for i in range(1000):")
c.indent()
c.write("print 'code generation is trivial'")
c.write("print i")
c.dedent()

c.newline(no=5) # adding 5 new lines
c.write("print 'end of my code'") 
print c.end()
And the output is:
for i in range(1000):
    print 'code generation is trivial'
    print i




print 'end of my code'

Of course, you will create an empty py file and write this generated content to it.. Hope it helps!..

Thursday, May 19, 2011

JBoss 5.1.0GA with Ubuntu 10.04

That was the first time that I tried to install Jboss server on a linux platform(it doesn't mean that I installed it on a different OS :P). After downloading "installation and getting started guide", I started to follow installation steps and configure our server environment. I won't rephrase what is already written in the guide so I want to share some important points that may help you. 

1. Configure your java environment: If sun jdk is not installed on your system, you have to start with this step. 
  • DO NOT forget adding java related environment variables for your users. It is a good idea to set those variables within .bashrc files. Add those lines to your files:
    export JAVA_HOME=/usr/java/jdk_versionNo
    export PATH=$PATH:$JAVA_HOME/bin

    Update your java home path as you prefer.
  • DO NOT forget to update your java alternatives. Because it is possible that you have more than one java installation, and you have to tell your system which java version to use. Use the command:

    $ update-alternatives --config java

    Note: It is possible that you don't see your previously downloaded java version. In this case, you have to manually add this option using the command:

    $ update alternatives --install "/usr/bin/java" "java" "/usr/lib/Java6/bin/java" 1

    Parameters are respectively as the following: system-wide java command, for "java", your previously installed java installation path and priority. After adding this option, you can update your java version as described above.
2. Download JBoss: In my case, I downloaded binary zip file of JBoss 5.1.0GA, and extracted files to a folder.

3. Set the JBOSS_HOME variable: As we set java environment variables, this time we will set jboss related environment variables. You will edit .bashrc files of your users, and specify jboss home path by adding those lines:

export JBOSS_HOME=/usr/jboss/jboss-release_no
export PATH=$PATH:$JBOSS_HOME/bin
Update your jboss home location as you prefer. 

4. Test your installation: The most exciting part is this step :) Simply, you go to JBOSS_HOME/bin directory and execute "run.sh" script as the following:
$ ./run.sh
Note that you need to have privileges to execute this command. 

If everything goes well, go to "localhost:8080" page on your favourite web browser, then you will see a jboss welcome page. Good news! :) Note that instead of "localhost", you have to type "127.0.0.1" for some systems. 

If there is no other application using your 8080 port, and you work on a local machine, all steps described above will help you to set up your jboss server. I needed to work more on it because I did this installation on a server environment, thus I needed to start Jboss on a specific ip using 8080 as port number. Again you need to execute "run.sh" script but with additional parameters:
$ ./run.sh -b "ip_number"
That command will start Jboss server on this ip with the default port 8080. 

Everything is going well, we started the server without any problem. BUT.. Of course, we need additonal things!.. What if your system reboots? Jboss won't start because we didn't do anything about it. So let's work on a init script. This page helped me to do things right. 

5. Add an init script: In our JBOSS_HOME/bin directory, you will see some init script example files. I used "jboss_init_redhat.sh" as a template, modified jboss home, jboss user, java path, jboss bind address(-b parameter value) settings. Find this line:
JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"} and above this line insert this one:
JBOSS_HOST=${JBOSS_HOST:-"ip_number"} If not specified Jboss server will start on localhost. 

Then, rename this file as "jboss" and move it to your "/etc/init.d" directory.
  • DO NOT forget to make this script executable. And again, take care of user access rights as necessary according to your needs. 
  • Use this command to create necessary symbolic links for yout init script:
    /etc/init.d/$ update-rc.d jboss defaults
    Now your script will run on boot up.
6. Test and update your init script: Run the following command:
$ service jboss start
It works as expected, you can check it by opening "localhost:8080". But when trying to stopping the server, I had many errors and server didn't shut down.  This is because, we need to add "host" parameter to our shutdown command. Find the line beginning with "JBOSS_CMD_STOP" and update it as the following:
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown -s jnp://${JBOSS_HOST}:1099"} Bold text is the part that you have to add to this line. 

After this modification use those commands for following actions:
service jboss start --> start jboss server
service jboss stop --> stop jboss server
service jboss restart --> restart jboss server

7. (optional) Adding logging feature to your init script: Default server log files are included in:
$JBOSS_HOME/server/$JBOSS_CONF/log/ directory. JBOSS_CONF is default, minimal etc as you specified in your script file. By default, it is set to be "default". So I prefered to log init script logging in this directory, you can specify any other folder if you want. To add logging functionality to your script, update your script as the following:
JBOSS_CONSOLE="$JBOSS_HOME/server/$JBOSS_CONF/log/init_script.log" So you replace "/dev/null" by a real file. 

8. (optional) Upload your java project: After opening "localhost:8080" page, click on "Administration Console" link. Default user/pass is "admin"/"admin". You can use this page to manage your Jboss server. Go to "Web Applications" link and upload your project. 

If you want to change user settings, or add new users for administration console, you can simply edit ..server/configuration/conf/props/jmx-console-users.properties
..server/configuration/conf/props/jmx-console-roles.properties
files in your system.

Hope this blog post will help you. Enjoy it :)

Wednesday, March 30, 2011

Switching from Chrome to Firefox 4.0

For a while, I was using Chrome browser which was fast, fancy and easy to use. I haven't thought about switching from Chrome to another browser, before reading this post. I loved the idea to customize a browser. And it is true that, Chrome is not allowing its users to customize it in the way that users are comfortable with.

Also check this post, if you want to use Firefox title bar as the container of your tabs and window controls(close, minimize and maximize buttons). Note that this solution works for linux users.

At a first glance, I can say that Firefox 4 is as fast as Chrome now. Let's see, what is coming next..  Ohh.. Here is a screenshot from my Firefox 4:



(Click on the image above, to see a larger version)












Saturday, February 26, 2011

Setup Cisco VPN using VPNC Ubuntu 10.04

This post will help you to setup Cisco VPN on a linux distribution, Ubuntu 10.04 in my case. If you google about it, you will find many many solutions to setup it. I tried many of them, got frustrated then. And here you can find that solution which worked well for me, and I hope it will be useful for you too.

First of all, we need to install vpnc framework.

$ sudo apt-get install network-manager-vpnc

Then, browse to the vpnc installation directory as a root user.

$ cd /etc/vpnc

It's a good idea to create a configuration file once, then use it whenever you want to use vpn. "default.conf" file is the default configuration file that will be used by vpnc by default. So let's create this file.

$ touch default.conf

Now, you have to edit this configuration file with your favourite text editor. Put the lines below and modify bold text with your settings:


IPSec gateway hostName
IPSec ID groupName -- used for connecting to the hostname defined previously
IPSec secret groupPassword -- used for connecting to the hostname defined previously 
Domain domainName -- (optional) use a domain name if necessary
Xauth username userName -- used for authentication
Xauth password password -- used for authentication


And now we are ready to use our connection. Open a terminal and write that command.

$ sudo vpnc-connect

If everything goes well, we can see that our connection is established and running in background.


Connect Banner:
| Authentication OK
| Welcome on  VPN

| Don't forget to disconnect you at the end of your session!!!!



VPNC started in background (pid: 10351)...


As mentioned above, when you're done with that connection do not forget to disconnect you. You can do it using the following command:

$ sudo vpnc-disconnect

And you have to see something like that:

Terminating vpnc daemon (pid: 10351)


Note that the pid corresponding to this process is the same(10351 in my case), as expected. Otherwise it means that you killed a different process :P

You don't have to keep your configuration details in a file, you can just provide this information at run time, using the interactive mode of vpnc framework. For that, use this command:

$ sudo vpnc

And it will ask your connection settings, as mentioned above, and then, your connection will be established. You can use the same command to disconnect you at the end of your session.

Hope it helps..