Git Tip : Restore a deleted tag

A little tip that can be very useful, how to restore a deleted Git tag.

If you juste deleted a tag by error, you can easily restore it following these steps. First, use

git fsck --unreachable | grep tag

then, you will see the unreachable tag. If you have several tags on the list, use

git show KEY

to found the good tag and finally, when you know which tag to restore, use

git update-ref refs/tags/NAME KEY

and the previously deleted tag with restore with NAME.

Thanks to Shawn Pearce for the tip.

Write and read binary files in C++

To write the EDDI compiler, I had to write and read binary files. Writing text files is really easy in C++, directly using the << operator on the stream, but writing binary is a little harder and, I must say, a lot less elegant.

First, to write to a binary file, we have to use the binary flag when we create the file :

std::ofstream stream("yourFile", std::ios::binary);

and then, we have to use the write method to write to the file. But this function is really basic and takes only a char and the size of the data we wan't to write, so we have to convert our data to char. A good way to do that is using the reinterpret_cast function and the sizeof operator. For example, to write an int, you can make that :

int test = 22;
outStream.write(reinterpret_cast<const char*>(&test), sizeof(int));

But your code is quickly polluted if you have of write operations to do.

Read more…

EDDI : A new programming language project

The project I'm working on for my Bachelor thesis is a C++ project. I've never worked on a big C++ project, so I decided to start a personal project in C++.

I wanted to develop my own language for a long time now. So I chose to develop a new language : EDDI

Because I didn't want to write assembly code, EDDI follows the same model as the Java language. The EDDI source files are first compiled into intermediate byteode file and then this compiled file is executed by a virtual machine.

I didn't use a generator for the lexer and the structural analysis, because I wanted to write these parts by myself, but perhaps in the future I will consider using it, like lex & yacc.

Of course, I don't write this language to compete with the other programming languages, it's only a way for me to learn C++ better and to improve my skills in general.

Now, EDDI is only in version 0.1 and you can almost do nothing with this programming language. The only thing you can do with this language is to print strings to the console, but I will continue to work on the compiler and the virtual machine to add new instructions and to improve the compiler and the vm.

Here is an example of an EDDI program:

Print("Hello World");

And this program is compiled like this:

HEADER
PUSH S13Hello World
PRINT
EXIT

The result doesn't appear like that in the compiled file because the output is made in binary files but this correspond to the EDDI bytecode instructions.

As you can see, I used a stack system. The PUSH instruction add something on the stack and the PRINT instruction pop the head of the stack and print it.

This project is distributed under the Boost Software License 1.0. The sources of the project are available on Github :

  • The compiler, eddic : https://github.com/wichtounet/eddic/
  • The virtual machine, eddivm : https://github.com/wichtounet/eddivm/
  • A commons library used by the two projects : https://github.com/wichtounet/eddi-commons/

If you want to see the exact version reffered to in this subject, you can select the tag v0.1.

I'm open to any kind of comments regarding the project, the source code or anything else related to EDDI.

I'll try to post some informations about my work on this project on this blog, the decisions made, the technical challenges, ...

For those who are interested on the origins of the name, it comes from EDsger Wybe DIjkstra, the famous computer scientist.

Upload files to FTP using Bash

This morning, I wanted to automatically update a little website from my computer without using Filezilla. So I searched a little bit and found that there is a very useful tool called nftp. To install it, you only have to use apt-get :

sudo apt-get install ncftp

This tool can be used directly from bash to upload files to FTP (and also to get files of course).

In my case, I just have to put a complete hierarchy of files into a specific folder of my website. So I wrote a little script that put everything on the FTP server :

read -s -p "Enter Password: " mypassword
ncftp <<EOF
open -u username -p $mypassword yoursitehost
cd "folder on the website"
lcd "folder on the computer"
put -R *
bye
EOF

This script asks you your password. With that, you don't have to put it in clear inside your program. The most important command here is the put -R * that make a recursive upload of the current folder in the current remote folder.

If I launch it from my computer (using the good values of course), it gives me that :

$ bash website.sh
NcFTP 3.2.4 (Apr 07, 2010) by Mike Gleason (http://www.NcFTP.com/contact/).
Copyright (c) 1992-2009 by Mike Gleason.
All rights reserved.
Connecting to 74.208.211.161...                                                 
FTP Server ready.
Logging in...                                                                   
User username logged in
Logged in to baptiste-wicht.com.                                                
docs/report.pdf:                                        39.92 kB   79.26 kB/s  
docs/requirements.pdf:                                  40.60 kB   80.91 kB/s  
docs/logbook.pdf:                                       32.39 kB   64.34 kB/s  
docs/week1.pdf:                                         32.13 kB   64.05 kB/s  
docs/01.06.2011.pdf:                                    34.77 kB   69.26 kB/s  
documents.php:                                         869.00 B    6.72 kB/s  
footer.php:                                             99.00 B   45.00 B/s   
header.php:                                            851.00 B  151.56 B/s   
index.php:                                             230.00 B   37.11 B/s   
links.php:                                             188.00 B   37.73 B/s   
minutes.php:                                           254.00 B    1.96 kB/s  
styles/default.css:                                      1.00 kB    8.01 kB/s  
weeks.php:                                             237.00 B   65.24 B/s

You will see the current status of all the files during the upload. The tool is enough smart to detect if a file must be sent or not (so it upload only newer files).

I hope this can help some of you.

This website is now running WordPress 3.1.3

I just made the update of this website to WordPress 3.1.3.

I've had no problems with the update. But at the start the automatic updater throws me an Out Of Memory Error. But after disabling all my plugins, the automatic update had no problem to update my entire website without any errors :)

Don't hesitate to contact me (in the comments or via the contact form) if you found any problem on the website.

Solve "File param is missing" problem of W3 Total Cache

As you may have seen, my website had not CSS these last days.

This was due to a bug in the W3 Total Cache plugin of Wordpress. The minified CSS file wasn't accessible. When we tried to access it from the site, there was an error : "File param is missing"

There is an easy solution to solve this problem. You just have to disable the "Rewrite URL structure" option on the Minify tab in the W3 Total Cache options. This will solve the problems. The only issue with this solution, is that you will not have fancy links for your CSS and JS minified files, but I think it's a really little problem comparing to the lack of CSS :)

Hope this will be helpful to some of you.

How to solve scrolling problems in Kile when using Gnome

From this morning, I was encoutering problems when scrolling in Kile editor using Gnome. When I scrolled, not all the lines were moving and the text was only correct when I clicked on them...

After some researches, I found that the solution was to use a different graphics system. You can do that in any Qt applicaitions using the graphics-system command line option. You can choose between raster and opengl. opengl is supposed to be the fastest one, but it is still experimental. In my case, I use raster that solve the scrolling problems and it doesn't change anything, which is fine.

So you can use this command-line to start Kile :

kile --graphicssystem raster

And that will solve your scrolling problems if you encounter some. You can also use this tip to improve performances of Kile if you need. If you do, test with opengl and if it's not stable on your system, choose raster, that will improve the performance compared to the default graphics system.

Now writing from Berkeley, California

Hi,

This message has been written from California, where I'm for 3 months. I'm making my bachelor final project in Berkeley Labs.

I'll certainly give some informations about the project and my researches during the next months.

I hope that I'll have the time to write more articles this next months as I've made the last months... I had a lot of work at school and no motivation to write.

Using LINQ to query Sharepoint lists

When I started using Sharepoint 2010 with .NET, I used the Sharepoint 2010 API to query the Sharepoint Lists, but when I come with lookup column with multiple values, it started to be really difficult to use.

So I found that I can use LINQ to query Sharepoint lists and for what I saw on the internet, it was really simple to use. LINQ provide a complete API to query data and to update them. More than that, LINQ is also able to do mapping object-relational, what is really helpful in code lisibility.

In this code, I will take as example a Sharepoint site with two lists :

  • departments : only a Title column
  • projects : Title, year, nbstudents and department, a lookup column to departments with multiple values

So first of all, you need to create the entities and the data context, but you don't have to do it by hand. There is a tool that make all that for you, SPMetal.

Read more…

Export a Sharepoint 2010 site as Solution Package

Hi,

From several days, I started developing with Sharepoint 2010 for a School project. It's not as easy as I thought in my first opinion. So I will try to share some solutions I found with you

In Sharepoint 2007, we used Solution Generator to create a wsp file of the site and then we can use this wsp file in Visual Studio for example.

But in Sharepoint 2010, you can do it directly in the site administration. Go in Site Settings -> Site action and then choose "Save site as template". Then, you just have to provide a name and description and you can save  the template.

In the next view, you have a link to the Solution gallery. Go in this view and then click on your template and you can download the .wsp file.

In some cases, we can have some problems during export... Try to create a blank site et add only the things you want to export and then retry.

When you've the wsp file, you can import it in Visual Studio 2010 using New Project -> Import Sharepoint Solution Package. This can take a lot of time to import all the content of the package.

With that, you can create things in Sharepoint and then use and edit them in Visual Studio.

I hope this can be useful to someone.