Blogger - SyntaxHighlighter
Sunday, October 17, 2010 in blogger, syntax highlighting
How to enable SyntaxHighlighter from Google to your Blogger blog.
Click Design tab and then Edit HTML.
Go to SyntaxHighlighter (http://syntaxhighlighter.googlecode.com/svn/trunk/Styles/SyntaxHighlighter.css) and copy all classes from the stylesheet.
In your blogger HTML template paste the css classes in the css information section, between <b:skin><![CDATA[ and ]]></b:skin>, just before the end.
Between the header tags, paste the javascripts, between <head> and </head>, just before the end.
I've disabled some of the languages I wont use, save some loading time.
<script src="http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shCore.js" type="text/javascript"> <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCSharp.js' type='text/javascript'/> <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCss.js' type='text/javascript'/> <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJava.js' type='text/javascript'/> <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushJScript.js' type='text/javascript'/> <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushSql.js' type='text/javascript'/> <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushXml.js' type='text/javascript'/> <!-- <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushCpp.js' type='text/javascript'/> --> <!-- <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushDelphi.js' type='text/javascript'/> --> <!-- <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPhp.js' type='text/javascript'/> --> <!-- <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushPython.js' type='text/javascript'/> --> <!-- <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushRuby.js' type='text/javascript'/> --> <!-- <script src='http://syntaxhighlighter.googlecode.com/svn/trunk/Scripts/shBrushVb.js' type='text/javascript'/> -->
Between the body tags paste the following script.
<script language='javascript'>
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
</script> In your blog post where you want some source code, click Edit HTML and enter your code between pre tags.
<pre class="c-sharp" name="code"> </pre>
The complete list of languages can be found at SyntaxHighlighter (http://code.google.com/p/syntaxhighlighter/wiki/Languages). Read On No Comments
Perst - Object Database - The Basics
Thursday, October 14, 2010
For you who haven't seen or heard about Perst before, Perst is a open source object database available in two implementations, one for Java and one developed in C# making it runnable under the .NET framework. Perst for .NET can also be used to develop applications for .NET Compact Framework.
Perst leaves a very small footprint, around 500KB for the .NET implementation, and supports LINQ (Language Integrated Queries).
This little example is based on the standard .NET implementation and will rely heavily on code and less on describing what is happening behind the scene.
We begin our little example by downloading Perst for .NET (C#) from McObject, current version is build 426.
Create a new project in your favourite development tool (VS2010), I've created a Console Application, and add a reference to PerstNet35.dll found in the bin folder.
Import necessary namespaces at the top or you wont get far.
using Perst;
Begin by calling the CreateStorage method from the StorageFactory singleton, after that we call the Open method to create the Perst storage container, this will create the database if missing or open it if already present.
var filePath = Path.Combine(@"C:\", "perst.dbs"); var storage = StorageFactory.Instance.CreateStorage(); storage.Open(filePath, 0);
Next step is to create a database wrapper around our newly created storage, the database wrapper gives us an interface to work with similar to relational databases. The database wrapper gives us all kind of neat methods for handling tables and records.
var database = new Database(storage);
That´s all it takes to get the database up and running!
Now, there are two ways of creating tables for classes, the easiest way is to create a class which inherits from Perst.Persistent. When added, the table is created.
Begin with a simple class for an order.
public class Order : Persistent
{
public string Id
{
get;
set;
}
public string CustomerId
{
get;
set;
}
public Order(string orderId, string customerId)
{
Id = orderId;
CustomerId = customerId;
}
}
Add our newly created order by calling AddRecord method on the database wrapper, don´t forget to call the Commit method on storage to persist changes.
var order = new Order("Order #1", "Customer #1");
database.AddRecord(order);
storage.Commit();
To get our orders back from the storage we simply call GetRecords to get all orders or use Select to build more precise queries.
var orders = database.GetRecords<Order>(); var numberOfOrders = orders.Count();
var orders = database.Select<Order>("Id = 'Order #1'");
var numberOfOrders = orders.Count();
In order to delete a record we call the method DeleteRecord.
database.DeleteRecord<Order>(order);
To drop table use DropTable.
database.DropTable(typeof (Order));
This covers the most basic functions of Perst, there are a lot more to be done regarding indexes, relations and so forth but that's for another post.