Showing posts with label c#. Show all posts
Showing posts with label c#. Show all posts

Friday, September 25, 2026

Analyzing Frontier Model Progress with My Favourite Game: Prince of Persia (Apple II, 1989) by Jordan Mechner

I first played Prince of Persia in 1995 on an IBM PC XT. I still go back to it from time to time: the rotoscoped animation, the way the prince hangs from a ledge, the clank of a gate slamming shut. Thirty years later it still feels like nothing else.

In 2012 Jordan Mechner published the original Apple II 6502 assembly source, recovered from 3.5" floppy disks that had sat in a box for over 20 years (the restoration itself is quite a story): github.com/jmechner/Prince-of-Persia-Apple-II

C# is my favourite language, so I set myself an experiment. I would hand that source to an AI model and ask it to port the game to C#. I wouldn't read the code or edit it myself. My only job was to play the result and say what was wrong. Every new frontier model that came out got the same project, with nothing but prompts.

Source is in https://github.com/priyanr/PrinceOfPersia_C-Sharp_Port_By_AI

 Here's how it went.

Tuesday, October 9, 2012

AmazonGlacierGUI - A GUI Client for Amazon Glacier


I have created a tool for Amazon glacier ,
checkout

http://amazonglaciergui.codeplex.com/

Its a WPF MVVM application in C#

Amazon glacier pricing information is confusing , a pricing calacultor is available at
https://github.com/brandt/amazon-glacier-calc


Tuesday, May 4, 2010

A generic excel file Importer / Reader - Converting Excel rows into Strongly typed entity

Its my blog post after a long time ,
Its simply a class it can be used to map Excel columns to an entity fields by adding an attribute to the property

Eg: An excel file with two columns Name and Phone Number
Our Entity is

public class ExcelItem
{
[ExcelColumnIndex(Index=0)]
public string Name {get;set;}
[ExcelColumnIndex(Index=1)]
public string Phone {get;set;}
}
To get List <ExcelItem> containg the excel rows, simply
Importer<ExcelItem> _Importer = new Importer<ExcelItem>();
List<ExcelItem> data=_Importer.ParseExcel("FILE PATH", "sheet1");


ExcelImporter.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.OleDb;
namespace ExcelImporter
{
//3-may-2010 Priyan R
public class Importer where T : new()
{
public List ParseExcel(string filePath,string sheetName)
{
string tempFile, connectionString, query;
OleDbConnection con = null;
OleDbDataReader reader = null;
OleDbCommand command = null;
//
connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
filePath + @";Extended Properties=""Excel 8.0;HDR=YES;""";
query = "SELECT * FROM [" + sheetName + "$]";
//
var ret = new List();
try
{
con = new OleDbConnection(connectionString);
con.Open();
command = new OleDbCommand(query, con);
reader = command.ExecuteReader();
while (reader.Read())
{
var entry = new T();
foreach (var property in entry.GetType().GetProperties())
{
var attributes = property.GetCustomAttributes(false);
var attribute = property.GetCustomAttributes(false)
.Where(p => p.GetType() == typeof(ExcelColumnIndex)).FirstOrDefault(); ;
if (attribute != null)
{
property.SetValue(entry, reader[((ExcelColumnIndex)attribute).Index].ToString(), null);
}
}
ret.Add(entry);
}


}
catch
{
throw;
}
finally
{
if (con != null && con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
}
return ret;
}
}
public class ExcelColumnIndex : Attribute
{
public int Index { get; set; }
}
}



Download sample application


Wednesday, September 23, 2009

URL Rewriting with ASP.NET 3.5 using System.Web.Routing.UrlRoutingModule

In asp.net 2.0 we used Context.RewritePath() or other URL rewrite modules. With asp.net 3.5 its easy to do. I did it for my blog for better SEO.

      • Add reference to system.Web.Routing
        Add System.Web.Routing.UrlRoutingModule http module to web.config
        Implement an IRouteHandler
        Registering routes in global.asax

I am going to rewrite blogs/Posts/{BlogPostID}/{*BlogPostTitle}

I implemented a generic IRouteHandler , it will copy url parameters( eg: BlogPostID,BlogPostTitle ) to http context item collection, so i can URL rewrite any page , without modifying IRouteHandler implementation.



using System;
using System.Web;
using System.Web.Routing;
using System.Web.Compilation;
using System.Web.UI;
public class SiteRouteHandler : IRouteHandler
{
//30 june 2009 Priyan R

public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
Page page;
page = BuildManager.CreateInstanceFromVirtualPath(PageVirtualPath, typeof(Page)) as Page;
foreach (var item in requestContext.RouteData.Values)
{
HttpContext.Current.Items["qparam." + item.Key] = item.Value;
}
return page;
}
public string PageVirtualPath { get; set; }
}

In global.asax added


       

routes.Add(
"BlogPost",
new Route("Blogs/Posts/{BlogPostID}/{*BlogPostTitle}",
new SiteRouteHandler() { PageVirtualPath = "~/Blogs/Details.aspx" })
);


So in Details.aspx I can read the parameters



Context.Items["qparam.BlogPostID"].ToString()
Context.Items["qparam.BlogPostTitle"].ToString()

Check the code.


Download Code

Wednesday, August 12, 2009

A simple Rss Feed Parser using LINQ To XML

Download Code

A simple class that can be used to parse rss feed, Check the code attached it will display my twitter updates by parsing the rss feed using the class.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Linq;
namespace RssFeed
{

//12-aug-2009 Priyan R
public class RssParser
{
public RssParser()
{
Items = new List<RssItem>();
}
public RssParser(string url):this()
{
URL = url;
}
#region Methods
public void Parse()
{
XDocument doc = XDocument.Load(URL, LoadOptions.None);
Items = (from t in doc.Descendants("item")
select new RssItem()
{
Title = t.Element("title").Value,
Description = t.Element("description").Value,
Link = t.Element("link").Value

}
).ToList();

}
#endregion
#region properties
public string URL { get; set; }
public List<RssItem> Items { get; set; }
#endregion
}
#region RSS Item Class
public class RssItem
{
public string Title{ get; set; }
public string Description { get; set; }
public string Link { get; set; }
}
#endregion
}

Friday, June 12, 2009

Finding Total Records / Total Count returned By Object Datasource SelectCountMethod

Often SelectCountMethod may be int or long so check the type in object datasource Selected event and store the value in ViewState or a variable so it can be used in the page

protected void odSource_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue.GetType() == typeof(Int32))
{
ViewState["TotalCount"] = e.ReturnValue;
}
}

Wednesday, March 11, 2009

Free ASP.NET MVC Book

ASP.NET MVC Book written by Scott gu,Scott Hanselman, Rob Conery, and Phil Haack

http://www.amazon.com/gp/product/0470384611?ie=UTF8&tag=scoblo04-20&linkCode=xm2&camp=1789&creativeASIN=0470384611

First chaptter of this book is available as a Free Download. 185 pages of walk-through that takes us into creating a complete MVC application (Called Nerddinner) from scratch. Check the application live at http://www.nerddinner.com/. Source code available at codeplex http://nerddinner.codeplex.com/

Download the e-book and source code from scott gu's blog.
http://weblogs.asp.net/scottgu/archive/2009/03/10/free-asp-net-mvc-ebook-tutorial.aspx

Also check scott hanselman's blog about it.
http://www.hanselman.com/blog/FreeASPNETMVCEBookNerdDinnercomWalkthrough.aspx

Wednesday, February 18, 2009

Get start and end date of current week in C#



DayOfWeek day = DateTime.Now.DayOfWeek;
int days = day - DayOfWeek.Monday;
DateTime start = DateTime.Now.AddDays(-days);
DateTime end = start.AddDays(6);
Code from
http://www.codekeep.net/snippets/0d955fdd-ff9e-4403-90cb-15dac8391034.aspx

Monday, February 16, 2009

C# :Seconds TO String

This functions return a string like 1 hours ago, a day ago etc.

//Returns seconds to 1 hour ago, 10 sec ago etc.
public static string SecondsToString(double seconds)
{

string time = "";
if (seconds >= 3600)
{
time =Convert.ToInt32((seconds / 3600)).ToString();
if (seconds > 24)
{
time = Convert.ToInt32((seconds / 24)).ToString();
time += " days ago";
}
else
time += " hrs ago";
}
else if (seconds >= 60)
{
time = Convert.ToInt32((seconds / 60)).ToString();
time += " minutes ago";
}
else
{
time = Convert.ToInt32(seconds).ToString();
time += " sec ago";
}
return time;
}