Command line to delete every file older than 30 days
Posted by shawson in Uncategorized on February 19th, 2010
I found a new command line directive i’d never heard of today, along with a brilliant example of it’s use- once you have changed your working directory, running this will remove any files or folders older than 30 days;
FORFILES /D -30 /C “CMD /C IF @isdir==FALSE (echo Deleting File @file) & (ATTRIB -H @file) & (DEL /F /Q @file) ELSE (echo Deleting Directory @file) & (ATTRIB -H @FILE) & (RD /S /Q @FILE)”
WCF 404.3 Errors
I built a WCF service recently which would run fine in the visual studio test web server, but when i tried to actually hit it from real life IIS7 also on my local box, i receievd the following error:
HTTP Error 404.3 – Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
Luckily, i found the solution on David Waddleton’s blog and it was as simple as turning on a windows feature in add remove programs- on my vista box i had to go to Control Panel > Programs and features > Turn on/ off Windows features > Microsoft.NET framework 3.0 and tick the WCF activitation options!
Getting started with WCF and REST web services
I’m building some REST WCF services at the moment and found this great guide online www.robbagby.com/rest/rest-in-wcf-blog-series-index
The HiREST stuff shows you how to create fully fledged REST services utilising all of the HTTP verbs.
Heres a quick summary of the most useful bits;
The service itself is just added to the project as a normal WCF service. The following needs adding to the Web.config to setup the end
points;
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AJAXFriendly">
<enableWebScript />
</behavior>
<behavior name="RESTFriendly">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyNamespace.AjaxServiceClassName">
<endpoint address=""
behaviorConfiguration="AJAXFriendly"
binding="webHttpBinding"
contract="CatalogService" />
</service>
<service name="MyNamespace.RESTServiceClassName">
<endpoint address=""
behaviorConfiguration="RESTFriendly"
binding="webHttpBinding"
contract="MyNamespace.IRESTServiceInterfaceName" />
</service>
</services>
</system.serviceModel>
Remember the class names in the web.config need to be fully qualified.
An example class for passing around the service;
[DataContract]
public class ProductData
{
[DataMember]
public int ProductId;
[DataMember]
public string ProductName;
[DataMember]
public string Description;
[DataMember]
public decimal Price;
[DataMember]
public string ProductImage;
}
The service itself is just a normal WCF service so consists of its usual two parts- the interface and the class. Here’s an example interface
demoing the various access methods and return serialisations;
[ServiceContract]
public interface IRESTServiceInterfaceName
{
// responds to a GET request to www.mysite.com/Servicename.svc/products/
// return is serialised to JSON
[OperationContract]
[WebGet(UriTemplate = "products/", ResponseFormat = WebMessageFormat.Json)]
List<FlotChartSeries> GetProducts();
// responds to a GET request to www.mysite.com/Servicename.svc/products/{product_id}
// return is serialised to JSON
[OperationContract]
[WebGet(UriTemplate = "products/{product_id}", ResponseFormat = WebMessageFormat.Json)]
List<FlotChartSeries> GetProductById(string product_id);
// responds to a GET request to www.mysite.com/Servicename.svc/products?brand={brand}
// return is serialised to JSON
[OperationContract]
[WebGet(UriTemplate = "products?brand={brand}", ResponseFormat = WebMessageFormat.Json)]
List<FlotChartSeries> GetProductsByBrand(string brand);
// responds to a POST, but still passing a bunch of parameters into the querystring
// no return type
[WebInvoke(Method = "POST", UriTemplate = "product/{product_id}/rate?score={score}")]
[OperationContract]
void PostProductAppRating(string product_id, string score);
// accepts a POST with a JSON encoded product data, to allow for an update
// no return
[WebInvoke(Method = "POST", UriTemplate = "product/{product_id}", RequestFormat = WebMessageFormat.Json)]
void PostProductUpdate(string product_id, ProductData data);
//responds to a PUT- passing a querystring variable for the filename- it expects the body of the push request to be a file stream
// no return type
[WebInvoke(Method = "PUT", UriTemplate = "products/{product_id}/desktopimage?filename={file_name}")]
[OperationContract]
void PutProductImage(string product_id, string file_name, Stream fileContents);
}
Note the variables in the curly braces must match the real parameters to the method signitures for the value to be automatically mapped.
Responses are generally done using HTTP response codes. At the top of each method you need to grab the current WebOperationContext which
will allow you to set the return codes;
WebOperationContext ctx = WebOperationContext.Current;
ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK; // .. if everything is ok!
ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest; // on error
ctx.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Created; // after an insert
// all of the http response codes are mapped here
ctx.OutgoingResponse.SetStatusAsNotFound(); // if record cannot be found or similar
Gravitar
Posted by shawson in Uncategorized on February 14th, 2010
Where do you setup and managed your Gravitar image, used by many wordpress and other blogs I hear you ask? en.gravatar.com
MySQL Backup & Restore
I did this on an install of MySQL 5 Community Server running on Windows 2008 Server Web Edition- From the command line- backup:
mysqldump -u [username] -p[password] [database name] > FILE.sql
restore;
mysql -u [username] -p[password] [database name] < FILE.sql
Remember; if you have restored your core mysql database, which contains all the info on users and privileges, you will need to do a
FLUSH PRIVILEGES;
before you will be able to login using those user accounts!
Web site’s back!
Posted by shawson in Uncategorized on January 29th, 2010
Just a quick note to say everything is back up and running after the past 24 hours worth of downtime. I’ve rebuilt the server here with a fresh install of windows server 2008 and the latest releases of php for IIS and MySQL5, as well as a whole new backup plan.
Karma, now available on iTunes!
My first published iPhone app, “Karma” is now available on the iTunes store http://itunes.com/apps/karma
Submitted “Karma” to Apple for approval
Posted by shawson in Uncategorized on January 18th, 2010
I’ve just submitted my second ever iPhone app to apple for approval- you can find details of the app on the dedicated Karma iPhone app support page on my new iPhone projects site.
I shall post again once it’s been accepted (hopefully!)
Cocos2d documentation on Easing effects for animating sprites
Posted by shawson in Objective C, iPhone on January 15th, 2010
just found this ; http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:actions_ease?s=ease after ages of searching! shows you how to do smooth scrolling movements which ease out.
Full Text Reindex, scheduled job has no steps!
Posted by shawson in SQL Server on January 12th, 2010
We have a SQL Server 2005 box, on which we have a database which has a full text index. The database gets a massive refresh of its data each night, meaning the full text index needs rebuilding. I added a schedule to my full text index (Databases > [DBName] > Storage > Full Text Catalogs > Right click your index – click properties > Population Schedule) and this created me a new job (SQL Server Agent > Jobs) but when i opened it up and went to steps, nothing was there! If i tried running the job it would fail because there are no steps!
I found this as a documented bug in the initial release candidate of sql 2005 (since fixed in the service packs) on the microsoft connect site, and added a workaround – basically just add your own job, using the following sql (which i found on msdn) to rebuild your index;
ALTER FULLTEXT CATALOG [catalogue_name] REBUILD;
Of course, this is only a workaround until we can get the latest service pack installed.