Showing posts with label How to. Show all posts
Showing posts with label How to. Show all posts

2011-03-09

How to turn off the Shutdown Event Tracker for Windows Server

Configure the Shutdown Event Tracker
  1. Click Start, Run, and then enter gpedit.msc. Click OK.
  2. The Group Policy Object Editor console opens.
  3. In the left pane, expand Computer Configuration, and then Administrative Templates.
  4. Click System
  5. In the right pane, find and double-click the Display Shutdown Event Tracker.
  6. When the Display Shutdown Event Tracker Properties dialog box opens, select one of the following options:
    • Not Configured
    • Enabled
    • Disabled
  1. If you select the Enabled option, you can choose between the following options to specify when the Shutdown Event Tracker should be displayed:
    • Always: This option is self explanatory. 
    • Server Only: When selected, the Shutdown Event Tracker is displayed for only Windows Server 2003/2008 servers.
    • Workstation Only: When selected, the Shutdown Event Tracker is displayed for only Windows XP Professional workstations.
  2. If you want to view help information on the Shutdown Event Tracker application, click the Explain tab.
  3. Click OK, and then close the Group Policy Object Editor console.

2010-07-13

NotImplementedError: Unable to find the Python PIL library

I have been playing with Google App engine on both mac and windows and in both cases when using images.resize I get the following error:
NotImplementedError: Unable to find the Python PIL library.  Please view the SDK documentation for details about installing PIL on your system.
After using my friend Google I found the solution.

For Mac OSX:
  1. Open to Terminal by navigating to your Applications folder, open Utilities, and double click on Terminal. You will be greeted with a message similar to this:
    Last login: Tue Mar 6 17:21:36 on console
    Welcome to Darwin!
    imac:~ Matt$
  2. Type in "sudo easy_install --find-links http://www.pythonware.com/products/pil/ Imaging" into the Terminal and press enter.
  3. Enter in your password when prompted and then you are done.
For Windows:
  1. Download "Python Imaging Library 1.1.7 for Python 2.6" from their website and install.
  2. Reboot and then you are done.
Simple huh?

2010-05-16

Good Bye JSP

I have tried using JSP on several occasions and every time I realise that I hate it, but when I started playing with Google App Engine(GAE) and the GWT I came to a conclustion that I am not a fan of that either.

I first started with GAE and Python and found that django was quite nice in the way it let you seperate the code and presentation easily, were someone with not python knowladge could easily edit the template.

So I turned to google and types in "JSP alternative", the first one I found was Freemaker so I downloaded the latest version and set out to complete this tutorial. There was one small problem the tutorial was a little out of date and try as I might I could not the the <list>. It turns out the the tutorial is a little old is not for the newest version(2.3.16 at the time of posting) of Freemarker and there have been a few changes with one major change, that being tags such as <list> and <if> now have a # before them so they look like <#list> and <#if> I made the change and the example worked!

To go from JSP to Freemarker I had to make a few changes. First I added freemarker.jar to /war/WEB-INF/lib/.
Next I created a template file called index.html and added to the war folder here is the template.
<html>   <body>   <ul>   <#list files as file>     <li>       <a href="/filestorage?name=${file.name}">${file.name}</a> (${file.mime})     </li>   </#list>   </ul>   <hr />   <form enctype="multipart/form-data" action="/filestorage" method="POST">     <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />     Choose a file to upload:     <input name="uploadedfile" type="file"/>     <br/>     <input type="submit" value="Upload File"/>   </form>   </body> </html>

After that I added a function to the serverlet to set the template values and display the template
/*  * Displays the template  */ private void DisplayTemplate(HttpServletResponse resp) {   //Now loads the data and adds it to a SimpleHash   SimpleHash modelRoot = new SimpleHash();   modelRoot.put("files", FileDAL.getFilesHash());   try {     resp.setContentType("text/html");     Configuration cfg = new Configuration();     Template tpl = cfg.getTemplate("index.html");     tpl.process(modelRoot, resp.getWriter());   } catch (Exception e) {     System.out.println(e.getLocalizedMessage());   } }

Last of all I replaced resp.sendRedirect("/index.jsp"); with DisplayTemplate(resp); and thats it.
The source is available from github.

2009-11-14

MonoTouch - Image View in Interface Builder

I have been playing with MonoTouch recently in an attempt to make a iPhone app. I was playing quite happily there just one problem. I couldn't work out how to set the image for the "Image View" in Interface Builder I searched the internet for a few hours and still couldn't find a thing. So it was time to start randomly clicking and compiling until it worked. Here is what I did....

  1. Create a new iPhone Solution in MonoDevelop.
  2. Drag the image you want to use in to the Solution Explorer.
  3. Click Copy on the dialog box.
  4. Right click the image in the solution and select "Properties", the Properties panel should show up.
  5. Change the "Build Action" to "Content".
  6. Double Click MainWindow.xib in the "Solution Explorer" and Interface builder should open up.
  7. Click "Tools" > "Library", the library window will pop open.
  8. Drag and "Image View" (under "Library" > "Cocoa Touch" > "Data Views") to the "Window".
  9. Click on the Image View, then click "Tools" > "Attribute Inspector".
  10. Type the name of the image in the "Image" field. The image view will be replaced with a question mark icon
  11. Close interface builder.
  12. In MonoDevelop Click "Run" > "Run".
  13. Wait for the iPhone Simulartor to start and enjoy the results.

2009-10-22

Single Quotes in TSQL

Recently I had a to format some data, originally the formatting was done using the MVC.NET page but there was one for small problem it took over five minutes to return 2,000 records which is just a little bit to long for my liking.

We only had a day to fix this problem so it was time for a dirty yet brilliant hack. I created a table variable and for the formatted data added the data to it and returned the date all in one stored procedure, there was one problem tho I needed to generate T-SQL and run it using EXECUTE (I know its not the best way to do things). I was working away at this and then a problem popped up there is no way to escape single quotes that I could work out in T-SQL.

But with a little trickery.....

DECLARE @singleQuote CHAR(1);
SET @singleQuote = CHAR(39);

Problem Solved!

2009-07-22

Free Flex IDE

Ok so flex is great but there is one small problem and thats the US$ 299 for the IDE from adobe. Yes there is a free trial available so you can at least spend 60 days trying the IDE but what happens after your 60 days are up and you still want to use flex but don't have US $299 laying around to buy yourself the full version. With Flash Develop and a two little plugins you can.

Installing First you need to download all the required files listed below:

Now you have a directory full of downloads it is time to start installing(please note [version] is a place holder for the current version of the file you downloaded):

  1. Run the installer(FlashDevelop[version].exe) for Flash Develop and and leave everything as the defaults.
  2. Install the Java SE Runtime Environment (jre-[number]-windows-i586.exe).
  3. Extract the Flex SDK(flex_sdk_3.zip) to "C:\Flex\3\".
  4. Install the Design View AIR app(designview.air) by double clicking it.
  5. Open the Design View plugin(FlexDesignView-[version].zip) and copy the contents of "Data" to "C:\Program Files\FlashDevelop\Data\" and the contents of "Plugins" to "C:\Program Files\FlashDevelop\Plugins\".
  6. Extract the Debugger Plugin(FlexDbg.zip) to "C:\Program Files\FlashDevelop\Plugins\"".

Now Everything is in installed all you need to do is set up flex in Flash Develop:

  1. Open the Flash Develop(Start > Applications > Flex Develop > Flex Develop).
  2. Once the application is opened press F10 or go to "Tool > Program Settings" to open the Program Settings.
  3. Click on AS3Content button (1. in the image below).
  4. Then set the "Flex SDK Location" (2. in the image below) to "C:\Flex\3\".
  5. Click Close, and enjoy Flash Develop.

Program Settings Settings Screen

Update: as requested here are some screen shots with FlashDevelop in both Source and Design Views.

2009-07-06

Excel Reader Writer (excel not required)

Ok as promised here it is a very simple(1 days work) wrapper for reading and writing excel files using 2007 Office System Driver: Data Connectivity Component. Below is an example function that shows what the class library can do. Remember to include a reference to the library in you project.
public void CorichExcel()
{
    string file = "C:/excel.xls";

    string sheet = "";

    try
    {
        //Gets a liost of sheets from the excel file
        string[] sheets = Corich.Excel.ReaderWriter.GetSheets(file);
        sheet = sheets[0];
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
        return;
    }
    
    //Check to see if the sheet exist
    if (Corich.Excel.ReaderWriter.SheetExists(file, sheet))
    {

        //gets a list of colums from the first sheet in the excel file
        string[] columns = Corich.Excel.ReaderWriter.GetColumns(file, sheet);

        //Loads the data in the first excel sheet into a data table
        DataTable data = Corich.Excel.ReaderWriter.Read(file);

        //Writes the data from the first sheet to a new excel file, currently only writes to xlsb files
        Corich.Excel.ReaderWriter.Write("C:\new_file.xlsb", data);

        //Writes the data from the first sheet to a new excel file in the temp directory then opens it, currently only writes to xlsb files
        Corich.Excel.ReaderWriter.WriteToTemp("new_file.xlsb", data, true);
    }

}

You can download the .dll and the source here the code is under the GNU GPL licence it would be nice to point people to my site if you use it.

2009-07-03

Excel Sheet Names using ODBC

I recently needed to import data from excel into a c# application after doing some searching I found the 2007 Office System Driver: Data Connectivity Components there is a lot of good info on the net so I quickly got it up and running. There was only one problem nowhere I looked could I find out how to get the sheet names. I stared putting various stuff into a data grid until I cam up with the code below.
string filename = "your filename";
string connectionString;
connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};dbq=" + filename + ";fil=excel 12.0;readonly=0;usercommitsync=Yes";

OdbcConnection myConnection = new OdbcConnection(connectionString);

myConnection.Open();
DataTable data = myConnection.GetSchema("Tables");
myConnection.Close();

List sheets = new List();
foreach (DataRow sheet in data.Rows)
{
    sheets.Add(sheet["TABLE_NAME"].ToString().Trim('\'').TrimEnd('$'));
}

P.S. I have built a whole static class library to read and write excel sheets I will post it here when I have some time to comment it.

2008-11-25

Auto Redirect to Login in page on an ASP.NET Website and keep styles

I have been working on an ASP.NET website recently and I ran into a problem where if I automatically redirected to the login page I lost my styles. I found a solution tho and here it is:
<!-- allows access Styles and Images directories-->
 <location path="Styles">
   <system.web>
     <authorization>
       <allow users="?">
     </allow></authorization>
   </system.web>
 </location>
 <location path="Images">
   <system.web>
     <authorization>
       <allow users="?">
     </allow></authorization>
   </system.web>
 </location>

<system.web>
   ...

   <authentication mode="Forms">
     <!-- When a user does not have access redirects to the login-->
     <forms loginUrl="Login.aspx" name="Login">
   </forms></authentication>
   <!-- Blocked access to all undecleared directores/files-->
   <authorization>
     <deny users="?">
   </deny></authorization>


   ...
</system.web>

2008-10-31

Regualar Expression bug in C#

I am currently working on a exception reporting system for work. As part of the system I am Creating a way to automatically create a bug in our bug reporting system when someone creates an error report or increase the count when an error has occured more than once. To do this I created an regular expression that grabs the relative filename and line number, I used this code:

Regex regex = new Regex("^.*\\(?'filename'.*):line (?'line'[0-9].)");
Match match = regex.Match(stackTrace);

I tested the code and got an following error

parsing "^.*\(?'filename'.*):line (?'line'[0-9].)" - Too many )'s.

After googleing i found exactly nothing that would help and 2 hours after that I came up with a nasty hack, my thinking was the proble is to do with the "\\" so how about replacing all the "\" with an "`" and then using String.Replace to replace the string(see below) it worked.

Regex regex = new Regex("^.*@(?'filename'.*):line (?'line'[0-9].)");
Match match = regex.Match(stackTrace.Replace('\\', '@')); 

Probably someting you want to fix Microsoft.

2008-06-30

idisk on Vista

On the weekend I signed up for a .mac account so that I could back up my photos to the web because I am just to lazy to burn them to CD and move send the to my parents for safe keeping. Everything was going fine (ok, it did take ages to put my photos up but there were a few) until I got to work and wanted to jam a some work 0n my idisk to take home with me.
I goggled and found there was indeed a client for idisk for Windows but after I installed it and ran it I got the a an error message.


Bugger so I turned to google again and found that here was no client but luckily you can just map it as a network drive, and you to can doing it following these simple steps;
  1. In windows explorer right click Network and select "Map Network Drive..."
  2. In the folder text box add "https://idisk.mac.com/[username]"
  3. Click "Connect using a different user name"
  4. Fill in your .mac details and click ok
  5. Click Finish
Thats it now you should have a new drive letter that links to your idrive.

2008-03-13

How I Fixed - SQL Server Error 310

I have just spent an hour trying to work out why my Sql Server Agent would not start. I kept getting this error message
SQLServerAgent could not be started (reason: Unable to connect
to server'(local)'; SQLServerAgent cannot start).

It was making me really angry when I realised what was wrong, I did not have the account for the Windows user the agent was running under in my database to. I created an account and gave it full access to the db and now everything is going fine.

P.S. Yes I know i am an idiot.

How to Move the Default Databases for MS SQL Server

I have juss finshed the painful task of moving of moving all the default databases (Master.mdf etc) from program files to more useful places on the database server. I wrote my self a little guide in google docs and thought someone else might like to use it. Here is the guide.

2008-02-25

WebBrowser Control Loading Hack

I was having a problem with the where I was trying to set some a the DocumentText on the load of my windows from but that browser control was not intilizied correctly and would not load the DocumentText. It took me a while but I worked out a way around it. Here is how I did it:
  1. I created a class variable called WebControlFirstLoad and set it to true.
  2. I set the DocumentCompleted event for the browser control to:
    if (!this.WebControlFirstLoad) return;
    this.WebControlFirstLoad = false
    [...load page code here...]
Now it all works fine.

2007-10-26

Using a custom database for ASP.NET Membership

I needed to use a custom database for my membership and roles in an ASP.NET service it took me a little while to sort out in the web.config so I thought that I would post my web.config here just in case anyone wants to copy it. just replace the words in square brackets with the correct values.
<?xml version="1.0"?>
<configuration >

 <appSettings/ >
 <connectionStrings >
  <add  name="ApplicationConnectionString"
   connectionString="[ConnectionString]"
           providerName="System.Data.SqlClient" / >
  <add name="MembershipConnectionString"
  connectionString="[ConnectionString]"
  providerName="System.Data.SqlClient" / >
 </connectionStrings >

 <system.web >

  <compilation debug="true" / >

  <authentication mode="Forms" / >

  <membership defaultProvider="SqlMembershipProvider"  >
   <providers >
    <clear / >
    <add name="SqlMembershipProvider"
     connectionStringName="MembershipConnectionString"
    applicationName="AssetManagement"
    type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" / >
   </providers >
  </membership >
  <roleManager enabled="true" >
   <providers >
    <clear / >
    <add connectionStringName="MembershipConnectionString"
    applicationName="AssetManagement"
    name="AspNetSqlRoleProvider"
    type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" / >
   </providers >
  </roleManager >
 </system.web >
</configuration >
Oh and to add the tables you need to your database use the following command from the command line replacing the words in square brackets with the correct values;
C:\WINDOWS\Microsoft.NET\Framework\[Framework]\aspnet_regsql.exe –E -S [Server] -d [DatabaseName] -A mr
Here is some more info on aspnet_regsql.exe.

CTRL + ALT + DEL on Remote Desktop

I was having trouble today drying to can a servers password when I remembered the reason it was not working was because I was using the wrong command(this may have taken half an hour). So kids remember when you want to use "CTRL + ALT + DEL" on a Remote desktop it is actually "CTRL + ALT + END".

2005-02-25

How I Fixed - Error 1352

Today while trying to install the dot net framework on my virtual machine I got an error just before the install started and it wouln’t install. The error was “Error 1325 - ‘documents’ is not a valid short file name” so I went to good old google and tried to find it… I found a page by micro$oft saying it occurs when you uninstall stuff and all you need to do is install this program to fix it. Sadly nothing was installing including that program, so it didn’t work.

I was starting to get rather angry and everything I found said I needed to re-install the service pack, which is a problem because my Windows XP came with Service Pack 2 already installed. While yelling at the stupid computer and cursing Micro$ofts name it occured to me the “My Documents” folder links to a share called documents, maybe thats the problem. I reset the “My Documents” path back to the default, tried the install, and it worked.

So in summary if you get an error message saying “Error 1325 - ‘File/directory name‘ is not a valid short file name” it is probably because you are using a share and pointing to it directly instead of using a virtual network drive. If you check this or restore the “My Documents” folder back to the default value it will probably fix it.