Archive for category Languages

Read from Excel in ASP

I always had a hard time finding correct documentation on the old ASP (active server pages) language and I needed it one more time in the last few days to create a script that read from an excel file.

As I believe that it might be handy for a handful of people around the world (is there actually anybody else still developing in ASP these days?), I hereby share my little piece of code with you guys.

Any suggestions or comments are always welcome.

In my example we read from an excel file that has 1 small table that has 1000 lines and columns from A until G.
The first row contains all the column names.

'initialize variables
Dim objConn, strSQL
Dim x

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "DRIVER={Microsoft Excel Driver (*.xls)}; IMEX=1; HDR=NO; "&_
 "Excel 8.0; DBQ=" & Server.MapPath("filename.xls") & "; "
strSQL = "SELECT * FROM A1:G1000"

Response.Write("<table border=""1"">")
Response.Write("<tr>")
'write all columnNames
For x=0 To objRS.Fields.Count-1
 Response.Write("<th>" & objRS.Fields(x).Name & "</th>")
Next
Response.Write("</tr>")

Do Until objRS.EOF

' write as much columns as there are in your excel file
Response.Write("<td>" & objRS.Fields(0).Value & "</td>")
Response.Write("<td>" & objRS.Fields(1).Value & "</td>")
Response.Write("<td>" & objRS.Fields(2).Value & "</td>")
Response.Write("<td>" & objRS.Fields(3).Value & "</td>")
Response.Write("<td>" & objRS.Fields(4).Value & "</td>")
Response.Write("<td>" & objRS.Fields(5).Value & "</td>")
Response.Write("<td>" & objRS.Fields(6).Value & "</td>")

objRS.Close

Response.Write("</table>")

Set objRS=Nothing

Tags: , , ,

How to force symfony colors on windows with PuttyCyg?

Those of you who’re developing with symfony under windows will have noticed that, when running tasks in the command prompt, no colors are used. This is because the windows command prompt isn’t compatible with the color notation.
Most of you also have cygwin installed (shame on you if you didn’t :p). But even if you run the tasks through “PuttyCyg”, which is fully compatible with the color notation, you will not benefit from the colors.

Why?

Read the rest of this entry »

Tags: , , ,

html 5 experiment

html5-canvas-particles2This is super cool!!!!

9Elements created a completely html page containing nothing more then Javascript and some of the tags that are created in the new HTML version.

This is really amazing as it is really the first time that I see a website that does some things I thought could only be done with Flash. I m overwhelmed with it an I suggest you take a look at it!! Be sure to look at it in an advanced browser ( Google Chrome 3.0, Safari 4 or the latest Firefox 3.5 version).

LOOK AT IT NOW

Tags: , ,

The future of Web: HTML 5 by Google

Tags: ,

an infinite image carousel

One of my favorite blogs is that of jQuery 4 Designers and this time he created a cool tutorial on how to create one with jQuery.

It has always been a struggle to create a nice carousel but i think this guy managed to create a real cool one. Also one of the most interesting things about this website is that all the code he writes in jQuery also works after disabling JavaScript. Try it!

for more information and other cool tutorials you can visit his website: jQuery4Designers

Tags: ,

the future of web development

It is always hard to tell what the future will bring, especially in a world where everything is evolving so quickly. But it’s always good to know what libraries, languages or applications will influence the way we work or the language we code in. There for I took the time to create an overview of what could be interesting in the near and far future.  If you have any remarks or other ideas, I would be happy to hear them in the comments.

HTML 5

Jon Von Tetzchner (director of Opera) recently announced that HTML 5 will replace Flash almost completely. Will it go that far? I don’t think so, but what we will be able to do with it is quite impressive!

  • Extension of the DOM with new elements like: section, audio, video, canvas, etc…
  • New attributes like: ping, charset, async
  • Id, tabindex and repeat for every element

As you can see the HTML 5 will be an expansion of HTML 4 but with rather important differences. We can expect HTML 5 to get its W3C Candidate Recommendation in 2012 but it will be able to use some of the features sooner. One of those is canvas that is already a widely implemented element.

Serge Jespers wrote a post on his weblog as a reaction on what Jon Von Tetzchner said and you can read about it here http://www.webkitchen.be/2009/05/27/adobe-versus-the-open-web/ He is an Adobe platform evangelist and Adobe pays his payckeck every month, but I do think the guy has a point.

JavaScript 2.0

With JavaScript being more popular than ever this is certainly worth taking a look at. John Resig created a slideshow on what will be changed in the 2.0 version and I must say that it looks promising.

PHP 6

A lot of people swear by the use of PHP over other language (like me :-) ) and a lot of other people say that PHP just isn’t sufficient enough. They are probably right because there are some insufficiencies in PHP, but in version 6 a few of those will be reviewed and adjusted. For now v6 is available as a developer snapshot so if you want you can already try it out.

Improved Unicode support.
This was a really necessary to keep up with other languages like JAVA that have a better i18n (internationalization) support, in this way PHP will close up the gap it had and support you with a much broader set of characters.

Namespaces
Namespaces are a way of avoiding name collisions between functions and classes without using prefixes in naming conventions that make the names of your methods and classes unreadable. By using namespaces we can never have the problem that 2 classes with the same name interfere with each other. I’m still wondering if this is the best solution but we’ll have to find out in the future. I’m only struggling with the idea that this only moves the problem to a higher level, as you now have to make sure your namespaces aren’t the same.

XML
XMLReader and XMLWriter will become part of the PHP core, which will make it easier to work with XML in PHP.

Magic_quotes and register_globals will be removed from PHP as they are a huge problem in PHP security.

It is from version 6 required to use tags as the ASP-style tags are no longer supported (<% %>)

Those are the biggest changes, again, just like in JavaScript some of these changes are already implemented in a PHP5.3
So in a nutshell, I do believe that PHP has a superb future in front of it, but that is also because of frameworks like Symfony, CakePhp, Zend, etc.

Tags: , , , ,

Mantis in Eclipse with Mylyn

This is a post especially for those who use Mantis as a bug tracker software and Eclipse as development software. For our PHP and JAVA development we do all the programming in Eclipse and wouldn’t it be easy if Eclipse recognized the bugs we are working? Wouldn’t it be easy if we could just get an automatic link between mantis and the commits we do in subversion (svn).

Well, praise the lord, ’cause there is an open source project out there that does all these things called Mylyn.

Mylyn is a task-focused interface for Eclipse that reduces information overload and makes multi-tasking easy. It does this by making tasks a first class part of Eclipse, and integrating rich and offline editing for repositories such as Bugzilla, Trac, and JIRA. Once your tasks are integrated, Mylyn monitors your work activity to identify relevant information, and uses this task context to focus the user interface on the task-at-hand. This puts the information you need at your fingertips and improves productivity by reducing searching, scrolling, and navigation. By making task context explicit Mylyn also facilitates multitasking, planning, reusing past efforts, and sharing expertise.

tasklist-splash-31
After a quick install and doing the configuration in Eclipse the interface is installed in Eclipse and ready to work with. And it is great! Easy overviews of all the bugs sorted by filter as you personally prefer, great layout to create and manage the bugs, etc.

It communicates quite nice with mantis, it could be a bit faster but let’s not fall over that tiny thing. The cool thing though is when working for a specific bug, all changes will be committed on those files with a reference to that specific bug. This makes it very easy to get see what files where changed for a specific bug.

For example when you commit changed files you will be asked to comment your committed files. Mylyn links your files directly to the current bug you are working on and puts this in the comment area: “fixed issue #178: Change user name to full name” . The number of the issue and the state are first mentioned and the title completes your comment.

In the screenshot you can see how a bug can be inserted or edited in a easy layout and inside the eclipse environment. Click on the image or here to see a larger image
mylyn-31-screenshot

My colleague Toni also installed WebSVN that gives us a super overview on all those changes and files committed in subversion.

If you use Mantis and Eclipse and SVN I highly recommend that you use these two utilities.

Tags: , , , ,

TestFest 2009

Tomorrow on the 9th of may an event called ‘PHP TestFest 2009′ will take place in the offices of Combell. (visit the website)

What is TestFest you ask?

The TestFest is an event that aims at improving the code coverage of the test suite for the PHP language itself. As part of this event, local User Groups (UG) are invited to join the TestFest. These UGs can meet physically or come together virtually. The point however is that people network to learn together. Aside from being an opportunity for all of you to make friends with like minded people in your (virtual) community, it also will hopefully reduce the work load for the PHP.net mentors. All it takes is someone to organize a UG to spearhead the event and to get others involved in writing phpt tests. The submissions will then be reviewed by members of php.net before getting included in the official test suite.

This event will take place in different countries but for the dutch speaking PHP community you can go to these addresses:

Hogeschool Domstad, Koningsbergerstraat 9, 3531 AJ Utrecht,The Netherlandstestfest_big-276x300

And

Combell offices Ghent, Skaldenstraat 121, 9042 Gent, Belgium (more info)

There will be a workshop to get the needed information and then it’s your turn to contribute to the development of the PHP language.

Felix De Vliegher is the mentor for Belgium and did the most tests in 2008 in the whole freaking world. With his experience and vision, this will be a piece of cake, be there or be square…. (maybe I will write about Felix later in our topic interesting people)

For those who will be on this event, have fun!!!!

Tags: , , , , , ,

Basic forms with Symfony

SymfonyOur goal is to create a little crud that contains 4 fields

id (auto increment integer)
name (varchar 50)
value (double)
type (0 or 1)

What I will explain is how to change your fields in the form after creation with generation of a module. So we start with a clean module that contains 1 action class and 3 templates (new, edit and index) and 1 partial (form) that is included on the new and edit template.
We created this module not by hand but with the very easy command: symfony propel:generate-module.

Read the rest of this entry »

Tags: , ,

Symfony Form: unsetAllFieldsExcept()

When creating forms in symfony which extends from a Base (ORM) class, you sometimes do not need all fields that Propel/Doctrine generates for you. If you want to remove them you have several ways to do so.

1. Unset the fiels you don’t need.

public function configure() {
  unset($this['field1'], $this['field2'], ... );
}

Simple way to remove the fields you don’t want, but if you change something in your database, which has an impact on that form (new column, foreignkey, etc ), it will be added in the (generated) super class. And if you don’t update the unset function with that extra field, it will be expected in the form. Unless you have unit tests for all your forms this could brake it without knowing it.

2. Override the setup function.

/**
 * @override
 */
public function setup()
  {
    parent::setup();

    $this->setWidgets(...);

    $this->setValidators(...);
  }

Another way is to override the setup function and do your own widgets and validators initialization. This is a good way to only intialize the fields you really need, but you’ll have to do what your ORM generated for you.

3. Use a function which unsets all fields except the one you need (like the enableAllPluginsExcept function).

$this->unsetAllFieldsExcept(array(
      'field1',
      'field2',
      'field3',
      ...));

This would be usefull, because it will remove all fields you do not want to use, and even if new fields are added it will not use them. The drawback is that if you have 20 fields and only need to unset one of them, you’ll have more type work ;) .
Since it does not exist in symfony, I quickly created our own function. This function should be added in the class BaseFormPropel.class:

abstract class BaseFormPropel extends sfFormPropel
{
  public function setup() {
  }

  protected function unsetAllFieldsExcept($fields = array()) {

    $unsetFields = array_diff(array_keys($this->getWidgetSchema()->getFields()), $fields);

    foreach($unsetFields as $value) {
      unset($this[$value]);
    }
  }
}

Which one to use ?
None of them are better. But if you need to reset a majority of the fields the ORM has generated then I would go for the method 2. If you only need to unset the fields you do not want to use then I would use the function unsetAllFieldsExcept().

Which method do/would you use ?

Tags: , ,