Posts

Showing posts from April, 2009

Scripting with PowerShell - part II

In my last entry I showed you some ways to get data from the user in different ways. We are now going to use this data to ready the environment for Qt programming. To be able to build with Qt, or any other programming library, Windows needs to know the whereabouts of all libraries and tools that will be used. This is included in the environment variables. To list all the environment settings in PS type: Get-ChildItem env: In the section below I will include the complete script and comment the code inside the script. When you comment your code in PS you prefix the lines with #. This will cause PS to ignore this line while running. Also note that I am organizing my code in three functions. One to clean the environment, one to set the environment and one main function that calls the other classes. # We fetch the input $firstArg = $args[0] # Clean any QTDIR from the path function cleanPath(){ # We use the net function split() to split the Windows # path into an array using the ; cha

Scripting with PowerShell

It has been a few weeks since the last blogpost on PS now, so it is indeed time for a new one. I'm getting hang of this PS scripting environment and I think it's time again to share some knowledge. This time around I will dig more into how to create scripts and especially how we pass data to the script in different ways. Scripts are useful because they are both simple and complicated at the same time. Simple in the sense that they are easy to create, and simple to use. Complicated because they can do advanced sets of tasks so that you don't have to do them over and over again. One task that I need to do is to set a working environment for programming in Windows. I need to configure paths and other environment variables. I also need to create simple projects and want them to be organized in a special way. I want to do this simple and quickly without passing a whole heap of lines to my shell. This means that I need to build myself a tool that can execute commands, copy and o

Running and making scripts with PowerShell

Here is another small blog entry on how to use PowerShell. When you download and install this tool you want to get to work right away. However, there are a few small obstacles to sort out. There are a few reasons why Microsoft is focusing on security but I will not move further in on that discussion here. Let's just say that they do and that PS is no exception. The default setting for this scripting environment is ironically enough that you cannot run your own scripts on it:) In order to do this you have to change this you need to set the ExecutionPolicy. It is set to "Restricted" by default. This policy can have four different values. "Restricted" will not load configuration tools or run any scripts. "AllSigned" will only run scripts and configuration files that have been signed by a trusted publisher. This also includes your own scripts. "RemoteSigned" is the one you would want to use if you only want to run your own scripts. It will st

More power with PowerShell

For quite some time now I've wanted to be able to create scripts a bit more complicated than plain batch files. I mainly use Windows in my daily work so switching to Linux just for the sake of making cool scripts wasn't a desire of mine and as I discovered not even needed. I accidentally discovered Windows PowerShell (PS) while playing around with Windows 7 beta looking for new ways to set up a programming enviroment for Qt programming. While PS will be implemented in Windows 7 by default, it is to my supprice, and good fortune, also available for both Windows XP and Windows Vista. So enough of this Windows commercial - I'm not getting paid.(Really!) In a small series of blogg entries I will have a look at several functions PS can provide, and try to set up some scenarios on how to use them. I do this as much for my own learning as for the attempt to educate the masses:) Lets start with some basic stuff to kick off. Playing around with text and files is both usefull a

Styling your elements.

A few weeks ago I promised to create a few examples on how to style different elements using CSS. We have already seen how to do this in several different ways but not so much which options we have for the specific element. First we need a webpage and we will start with a simple one like the example below. It contains of a small collection of elements. There are three DIV containers used to limit the geometry of the child elements. Also there are an unordered list, UL, and a paragraph, P. Last but not least there are a collection of links, A HREF, in the list functioning as a menu. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <link rel="stylesheet" href="css/foo.css" type="text/css" /> </head> <body>

Styling you page using Cascading style sheets.

Fourteen years ago(from today 2008) a guy called Håkon Wium Lie created the first version of Cascading style sheets for HTML and similar markup languages. The intention was to devide the strukture containing data and the semantics describing the layout of the data. Later this language has evolved and became a W3C standard. Now, this blogposts will describe a couple of ways to implement CSS to your web page. You are welcome to comment and ask questions. I will respond as well as I can. Now, in the previous bloggpost I described how to implement an external css file to your webpage. You can do this in three ways actually. Either in the header, in an external document linked in the header or you can add it to a specific element by using the style attribute. Below is given an example of the three. You may use one or more of the method, just remember that the last one read by the browser, is the one that will be executed. A browser starts reading documents from the top and down. That me

The building blocks - DOM structure and page elements

The DOM structure or the Document Object Model is the backbone of the structure that builds up every single webpage and most other information wrappers on the internet. The structure can be viewed as a tree structure. Only instead of looking at the branches of the tree we look at the roots. This also can be compared to the DOM structure directly because what we see is the result of the DOM structure being parsed by the web-browser and not the structure itself. First of all, the DOM structure is not only bound to HTML. It is actually derived from XML and appears as the main structure of XML, XHTML, SVG, XSLT etc. The DOM is a kind of wrapper containing all the information. Each TAG in the structure contains a bit of the data that is to be displayed. The TAG is refFered to as an element. An element can be anything from a header or paragraph to a form element or an image. The type of element is determined by its name. An image will have the element <img>. A header can have the nam

Navigating the colors of the web.

The colors of the world arround us, counts millions but (unfortunatly) web browser doesn't (for obvious reasons) include all these colors. A collection of "Web secure" colors has been set in a system that enables the web designer to specify the colors used in the code in three ways. The web colors can be specified using RGB code, a Hex RGB format or (a few colors) using enlish color names. The most effective way to use the webcolors in your code (that is in my opinion), is to use CSS in combination with the HTML DOM structure. Here is a simple example of CSS color use:  <html> <body> <div style="color:blue;background-color:#F08080; height:25px;width:100%;">foo</div> <div style="color:green;background-color:rgb (173,255,47);height:25px;width:100%;">bar</div> <body> </html> Below you can find the most common color codes. Color name RGB code Color name RGB code Color name RGB code Colo