Friday, December 10, 2010

Windows hosted virtual private server (VPS) set up

In early 2010 I migrated my websites from shared web host that had begun to suck to a virtual private server (VPS) provided by Web24.

I did this for performance reasons as the shared web host had degraded over the course of several years, and additionally I wanted control over what was installed on the machine just like when at work.

Due to low traffic and budget constraints I'm running the VPS as a web server (IIS), DB server (SQL Server Express, and MySQL) and an SMTP server.  Here are my notes regarding the server installation and configuration so I can do it again fairly quickly if needed.

NOTE: these details were accurate at March 2010, newer versions and service packs are probably available now.

VPS Configuration
Windows Server 2003 R2, 64 bit
IIS 6
1GB RAM
10GB disk space
Parallels Power Panel
Full remote desktop access

General Utilities Installed
7zip, notepad++, Winmerge and Sysinternals Suite

Web Platform Installer
Used the WPI to install: .NET FW 2.0 .NET FW 3.5SP1, MVC 2.0

Database Servers
MySQL:

SQL Server 2008 Express:
SMTP Mail Server
hMailServer:
Web Mail
roundcube (PHP application):
Yep, that's it, too easy really.  Overall I'm pretty happy with Web24 - faster than the old shared hosting, and (almost) complete control over the environment. Only downside is a few more sysadmin tasks.

Next thing to do is switch to Server 2008 with IIS 7.

Entity Framework and LINQ2SQL Links

EF
Migrating from LINQ to SQL to Entity Framework: Eager Loading
http://blogs.msdn.com/adonet/archive/2008/10/07/migrating-from-linq-to-sql-to-entity-framework-eager-loading.aspx

Known Issues and Considerations in LINQ to Entities
http://msdn.microsoft.com/en-us/library/bb896317.aspx


LINQ2SQL

Linq to SQL DataContext Lifetime Management (Rick Strahl)


Python Libraries

Here are some useful Python libraries I've been using for conducting and visualising experiments in machine learning, forecasting and statistical learning. It is updated as I discover new libraries/applications.
Last updated April 2013.

Libraries

numpy - Numerical Python - Numerical Python adds a fast and sophisticated array facility to the Python language. NumPy is the most recent and most actively supported package.

scipy - Scientific Library for Python - SciPy is package of tools for science and engineering for Python. It includes modules for statistics, optimization, integration, linear algebra, Fourier transforms, signal and image processing, ODE solvers, and more.

matplotlib - matplotlib tries to make easy things easy and hard things possible. You can generate plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc, with just a few lines of code

PyBrain -  Python-Based Reinforcement Learning, Artificial Intelligence and Neural Network Library. PyBrain is a modular Machine Learning Library for Python. Its goal is to offer flexible, easy-to-use yet still powerful algorithms for Machine Learning Tasks and a variety of predefined environments to test and compare your algorithms.

nltk - Natural Language Toolkit — is a suite of open source Python modules, data and documentation for research and development in natural language processing.

PIL - Python Imaging Library adds image processing capabilities to your Python interpreter.

mlpy - Machine Learning PYthon - high-performance Python library for predictive modeling. Makes extensive use of  NumPy to provide fast N-dimensional array manipulation and easy integration of C code. The GNU Scientific Library ( GSL) is also required. It provides high level procedures that support, with few lines of code, the design of rich Data Analysis Protocols (DAPs) for preprocessing, clustering, predictive classification, regression and feature selection. Methods are available for feature weighting and ranking, data resampling, error evaluation and experiment landscaping.

networkx - High productivity software for complex networks - creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

neurolab - a simple and powerful Neural Network Library for Python. Contains based neural networks, train algorithms and flexible framework to create and explore other networks. Pure python + numpy.
Includes: Single layer perceptron, Multilayer feed forward perceptron, Competing layer (Kohonen Layer), Learning Vector Quantization (LVQ), Elman Recurrent network, Hopfield Recurrent network. (Sep 2011)
[Note: after using this library I prefer PyBrain since it feels more stable and better documented. However neurolab has a similar api to the MATLAB NN Toolbox]

scikits.learn - Easy-to-use and general-purpose machine learning in Python. Python module integrating classic machine learning algorithms in the tightly-knit world of scientific Python packages (numpy, scipy, matplotlib).  It aims to provide simple and efficient solutions to learning problems that are accessible to everybody and reusable in various contexts: machine-learning as a versatile tool for science and engineering. Part of SciKits. (Aug 2011)

scikits.* - SciKits (short for SciPy Toolkits), are add-on packages for SciPy, hosted and developed separately from the main SciPy distribution. All SciKits are available under the 'scikits' namespace.
Selected examples that have recent updates and look maintained: (Sep 2011)

Tablib - allows you to import, export, and manipulate tabular data sets. Advanced features include, segregation, dynamic columns, tags & filtering, and seamless format import & export. (Sep 2011)

pyneurgen - Python Neural Genetic Hybrids.  This software provides libraries for use in Python programs to build hybrids of neural networks and genetic algorithms and/or genetic programming. (Sep 2011)

pyml - machine learning in Python. PyML is an interactive object oriented framework for machine learning, it focuses on SVMs and other kernel methods.
Features:
Classifiers: support vector machines, nearest neighbor, ridge regression
Multi-class methods (one-against-rest and one-against-one)
Feature selection (filter methods, RFE)
Model selection
Preprocessing and normalization
Syntax for combining classifiers
Classifier testing (cross-validation, error rates, ROC curves)
(Sep 2011)

Pandas - pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.  R users will be pleased to find this library adopts some of the best concepts of R, like the foundational DataFrame (April 2013)

PyTables - PyTables is a package for managing hierarchical datasets and designed to efficiently and easily cope with extremely large amounts of data. PyTables is built on top of the HDF5 library, using the Python language and the NumPy package. (April 2013)

gensim - realize unsupervised semantic modelling from plain text.  Useful to determine similarity between pairs of documents.  Includes Latent Sematic Analysis and Latent Dirichlet Allocation (April 2013)

ramp - Ramp is a python package for rapid machine learning prototyping. It provides a simple, declarative syntax for exploring features, algorithms and transformations quickly and efficiently. At its core it’s a unified pandas-based framework for working with existing python machine learning and statistics libraries (scikit-learn, rpy2, etc.) (April 2013)

Statsmodels - Statsmodels is a Python module that allows users to explore data, estimate statistical models, and perform statistical tests. An extensive list of descriptive statistics, statistical tests, plotting functions, and result statistics are available for different types of data and each estimator. (April 2013)

Blaze - Blaze is the next generation of NumPy, Python’s extremely popular array library. Blaze is designed to handle out-of-core computations on large datasets that exceed the system memory capacity, as well as on distributed and streaming data. (April 2013)



Applications

IPython - IPython provides a rich toolkit to help you make the most out of using Python interactively. Its main components are:
Powerful interactive Python shells (terminal- and Qt-based).
Support for interactive data visualization and use of GUI toolkits.
Flexible, embeddable interpreters to load into your own projects.
Tools for high level and interactive parallel computing.

Orange - Open source data visualization and analysis for novice and experts. Data mining through visual programming or Python scripting. Components for machine learning. Extensions for bioinformatics and text mining. Packed with features for data analytics.

Friday, November 5, 2010

InfoVis Applications, Libraries

NOTE: This post is a work in-progress


Applications and Libraries

Gephi, App, Java (NetBeans build environment)
Gephi is an interactive visualization and exploration platform for all kinds of networks and complex systems, dynamic and hierarchical graphs. Runs on Windows, Linux and Mac OS X. Gephi is open-source and free.

prefuse, Library, Java
See also: vizster, uses prefuse to visualise social networks.
Prefuse supports a rich set of features for data modeling, visualization, and interaction. It provides optimized data structures for tables, graphs, and trees, a host of layout and visual encoding techniques, and support for animation, dynamic queries, integrated search, and database connectivity. Prefuse is written in Java, using the Java 2D graphics library, and is easily integrated into Java Swing applications or web applets. Prefuse is licensed under the terms of a BSD license, and can be freely used for both commercial and non-commercial purposes.

prefuse flare, Library, ActionScript
Flare is an ActionScript library for creating visualizations that run in the Adobe Flash Player. From basic charts and graphs to complex interactive graphics, the toolkit supports data management, visual encoding, animation, and interaction techniques.

Protovis, Library, Javascript with SVG
Protovis composes custom views of data with simple marks such as bars and dots. Unlike low-level graphics libraries that quickly become tedious for visualization, Protovis defines marks through dynamic properties that encode data, allowing inheritance, scales and layouts to simplify construction.

UbiGraph, Rendering engine, C++,  Linux only
UbiGraph is a tool for visualizing dynamic graphs. The basic version is free, and talks to Python, Ruby, PHP, Java, C, C++, C#, Haskell, and OCaml.

igraph, Library, C++ with Python module and R package
igraph contains functions for generating regular and random graphs, manipulating graphs, assigning attributes to vertices and edges. It can calculate various structural properties, graph isomorphism, includes heuristics for community structure detection, supports many file formats. The R and Python interfaces support visualization.

Graphviz, Tool set
The Graphviz layout programs take descriptions of graphs in a simple text language, and make diagrams in several useful formats such as images and SVG for web pages, Postscript for inclusion in PDF or other documents; or display in an interactive graph browser. (Graphviz also supports GXL, an XML dialect.)


People


Jeffrey Heer

Friday, April 23, 2010

Online Lectures (updated 2012)

Added 2012:


Stanford EE263: Introduction to Linear Dynamical Systems
Introduction to applied linear algebra and linear dynamical systems, with applications to circuits, signal processing, communications, and control systems.
http://www.stanford.edu/~boyd/ee263/index.html
http://www.youtube.com/playlist?list=PL06960BA52D0DB32B


MIT - 18.085 Computational Science and Engineering I
Review of linear algebra, including applications to networks, structures, and estimation, Lagrange multipliers. Also covered are: differential equations of equilibrium; Laplace's equation and potential flow; boundary-value problems; minimum principles and calculus of variations; Fourier series; discrete Fourier transform; convolution; and applications.
http://ocw.mit.edu/courses/mathematics/18-085-computational-science-and-engineering-i-fall-2008/index.htm


Statistical Aspects of Data Mining (Stats 202 - Google/Stanford)
Topics: decision trees, neural networks, association rules, clustering, case based methods, and data visualization.
http://www.youtube.com/playlist?list=PLA40054B49BA80084&feature=view_all
http://www.stats202.com/original_index.html


Added 2011:
Awesome, free, online courses from Stanford offered Oct 2011:

CS229, Machine Learning Course
Broad introduction to machine learning, datamining, and statistical pattern recognition
http://www.ml-class.org/
http://cs229.stanford.edu/
http://www.reddit.com/r/mlclass/

CS221, Artificial Intelligence Course
Covering basic elements of AI, such as knowledge representation, inference, machine learning, planning and game playing, information retrieval, and computer vision and robotics.
http://www.ai-class.com/
http://robots.stanford.edu/cs221/
http://www.reddit.com/r/aiclass

Unsupervised Feature Learning and Deep Learning
Video lectures by Andrew Ng (Stanford, also teaches CS229)
http://openclassroom.stanford.edu/MainFolder/CoursePage.php?course=ufldl


Added 2010:

Stanford - Programming Paradigms (CS107)
Online lectures http://www.youtube.com/view_play_list?p=9D558D49CA734A02
Course notes https://courseware.stanford.edu/info/course/CS107
Lecture summary https://courseware.stanford.edu/pg/courses/lectures/4838

Stanford - Machine Learning (CS229)
Online lectures http://www.youtube.com/view_play_list?p=A89DCFA6ADACE599
Course notes http://www.stanford.edu/class/cs229/
Lecture summary http://www.stanford.edu/class/cs229/schedule.html
Course Materials http://www.stanford.edu/class/cs229/materials.html
Notes
http://amitksaha.wordpress.com/ (229 search)

MIT - Introduction to Algorithms (6.046J / 18.410J)
Online lectures http://www.youtube.com/view_play_list?p=8B24C31197EC371C
Course notes
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/CourseHome/index.htm
Lecture summary
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/VideoLectures/
3rd party notes (very good)
http://www.catonmat.net/blog/category/introduction-to-algorithms/

Stanford - Introduction to Robotics (CS223A)

Online lectures http://www.youtube.com/view_play_list?p=65CC0384A1798ADF
Course notes 1 http://www.stanford.edu/class/cs223a/
Course notes 2
http://see.stanford.edu/see/courseInfo.aspx?coll=86cc8662-f6e4-43c3-a1be-b30d1d179743
Lecture summary
http://see.stanford.edu/see/lecturelist.aspx?coll=86cc8662-f6e4-43c3-a1be-b30d1d179743

MIT - Linear Algebra (18.06)
Online lectures http://www.youtube.com/view_play_list?p=E7DDD91010BC51F8
Course notes http://web.mit.edu/18.06/www/
Online lectures download
http://ocw.mit.edu/OcwWeb/Mathematics/18-06Spring-2005/VideoLectures/index.htm
Peteris Krumins' notes
http://www.catonmat.net/?s=MIT+Linear+Algebra&submit=Search

Stanford - Human-Computer Interaction Seminars (CS547)
Course notes http://hci.stanford.edu/courses/cs547/
Online lectures 2006/7 http://www.youtube.com/view_play_list?p=32A089D3E2DFB65D
Online lectures 2007/8 http://www.youtube.com/view_play_list?p=27C635EE182143CE
Online lectures 2008/9 http://www.youtube.com/view_play_list?p=CFE6199B78198411
Online lectures 2009/10 http://www.youtube.com/view_play_list?p=F4A01617834A0FB6


Other interesting lecture series:

Berkeley Computer Science 61A, 001 - Spring 2008:

Stanford Data Mining CS246/CS341 (formerly CS345A)

Friday, March 19, 2010

Open Data Sources, Web APIs and the Semantic Web

Links to various data sources that can be used in the push for a semantic web.

General reference
http://en.wikipedia.org/wiki/Linked_Data#Datasets (List of datasets)
http://www.programmableweb.com/ (Open APIs, mashups and the Web as platform)
http://esw.w3.org/TaskForces/CommunityProjects/LinkingOpenData/DataSets (RDF data sets that are part of the emerging Web of Linked Data)
http://blog.visual.ly/data-sources/ (a great list of useful resources for finding data, March 2012)

Dataset providers
Note: these 3 really take the cake and I'm going to start adding to these rather than update this post:
http://www.opendataday.org/wiki/Data (dataset listing page for #odhd)
http://datacatalogs.org/ (aims to be the most comprehensive list of open data catalogs in the world)
http://thedatahub.org/ (registry of open knowledge datasets and projects)


My old dataset providers list:
http://www.quora.com/Data/What-are-some-free-public-data-sets (quora.com free data set links)

http://wiki.dbpedia.org/Datasets (structured information from Wikipedia)
http://www.programmableweb.com/api/dbpedia/mashups

http://www.freebase.com/docs/data (developed by Metaweb)
http://www.programmableweb.com/api/freebase/mashups

http://www.mpi-inf.mpg.de/yago-naga/yago/ (YAGO2 is a huge semantic knowledge base, derived from Wikipedia, WordNet and GeoNames)

http://archive.ics.uci.edu/ml/ (UC Irvine Machine Learning Repository)

http://dbtune.org/ (Serving music-related RDF)

http://www.factual.com/  (evolving data on thousands of topics)

http://www.odata.org/producers (services that expose their data using OData)

http://openspending.org/datasets (government and corporate spending)
http://wiki.openspending.org/Main_Page

http://thedatahub.org/ (WOW, awesome site, thousands of shared datasets)

http://data.gov.uk/ (UK government data)

http://okfn.org/about/ (Good resource, projects using data and links to datasets)


Dataset indexing
http://www.sindice.com/ (Semantic web index)

Query languages/tools
http://en.wikipedia.org/wiki/SPARQL (QPARQL)
http://www.freebase.com/docs/mql/ (MQL for freebase)
http://en.wikipedia.org/wiki/Predictive_Model_Markup_Language (Sharing predictive analytics and data mining models)


People, blogs and groups
http://datavisualization.ch/ (premier news and knowledge resource for data visualization and infographics)
http://flowingdata.com/ (explores how designers, statisticians, and computer scientists are using data to understand ourselves better)
http://blog.kiwitobes.com/ (Toby Segaran, videos)
http://www.dataminingblog.com/list-of-blogs/ (yet another blog list)


Organisations and companies (semantic, bigdata)
http://linkeddata.org/home
http://www.metaweb.com/
http://www.google.com/publicdata/home
http://www.opencalais.com/
http://www.cloudera.com/
http://www.couchbase.com/
http://www.splunk.com/
http://timetric.com/
http://www.vertica.com/
http://www.asterdata.com/
http://www.quantcast.com/


Standards (yeah, need to add to this...)
RDF (Resource Description Framework)
XBRL (eXtensible Business Reporting Language)
SPARQL (SPARQL Protocol and RDF Query Language)
FOAF (Friend of a friend)
OWL (Web Ontology Language)
XFN (XHTML Friends Network)
hCard, hCalendar etc (Microformats in XHTML, see list)
PMML (Predictive Model Markup Language)
OData (Open Data Protocol by Microsoft)









Tuesday, March 2, 2010

Machine learning / AI links and libraries

Code libraries and frameworks

AForge
C# - extensive library for vision, AI, robotics etc
http://code.google.com/p/aforge/
http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=1181072

Emgu CV
.NET - wrapper to the Intel OpenCV image processing library
http://www.emgu.com/wiki/index.php/Main_Page
http://sourceforge.net/projects/emgucv/

Watchmaker Framework
Java - Evolutionary computation framework for evolutionary/genetic algorithms
http://watchmaker.uncommons.org/

ALGLIB
.NET - cross-platform numerical analysis and data processing library
http://www.alglib.net/

Infer.NET
.NET - Microsoft framework for running Bayesian inference in graphical models, used in a wide variety of domains including information retrieval, bioinformatics, epidemiology, vision
http://research.microsoft.com/en-us/um/cambridge/projects/infernet/default.aspx

Microsoft Solver Foundation
.NET - An extensible framework to model and solve complex problems by using constraints, goals, and data.
http://code.msdn.microsoft.com/solverfoundation


Weka Machine Learning Project
A collection of algorithms for solving real-world data mining problems



Software Tools

RapidMiner
Open-source system for data and text mining (Java based)
http://rapid-i.com/
http://sourceforge.net/projects/yale/

R Project
Free software environment for statistical computing and graphics


KNIME
The user-friendly and comprehensive open-source data integration, processing, analysis, and exploration platform.


Online books

A Field Guide to Genetic Programming (free pdf)
Poli, Langdon, McPhee (2009)
http://www.gp-field-guide.org.uk/

The Elements of Statistical Learning: Data Mining, Inference, and Prediction (free pdf)
Hastie, Tibshirani, Friedman (2009)
http://www-stat.stanford.edu/~tibs/ElemStatLearn/

Information Theory, Inference, and Learning Algorithms (free pdf)
David J.C. MacKay (2003)
http://www.inference.phy.cam.ac.uk/mackay/itila/book.html

Evolutionary Computation in Java - A Practical Guide to the Watchmaker Framework (html)
Daniel W. Dyer
http://watchmaker.uncommons.org/manual/index.html

Planning Algorithms (free pdf)
Steven M. LaVall (2006)
http://planning.cs.uiuc.edu/

Evolution of Parallel Cellular Machines: The Cellular Programming Approach (free pdf)
Moshe Sipper (1997)
http://www.moshesipper.com/pcm/


Links and feeds

Interesting information visualisation blog
http://abeautifulwww.com/

Jürgen Schmidhuber's home page
http://www.idsia.ch/~juergen/

Stanford course in machine learning
http://www.youtube.com/view_play_list?gl=AU&hl=en-GB&p=A89DCFA6ADACE599

Podcast
http://www.biota.org/

Library of AI resources
http://www.aaai.org/AITopics/pmwiki/pmwiki.php/AITopics/HomePage

Data Mining and Analytics Resources
http://www.kdnuggets.com/

Saturday, February 27, 2010

Setting up Subversion

REFERENCES
http://www.codinghorror.com/blog/archives/001093.html
http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91&expandFolder=91&folderID=8100

INSTALLATION

1.1 Download latest svn and tortoise files from link above
1.2 Install Setup-Subversion-1.6.6.msi
1.3 Install TortoiseSVN-1.6.5.16974-x64-svn-1.6.5.msi (choose either x86 or x64 version)


REPOSITORY SETUP

2.1 Create folder for the repository on the server e.g D:\SVN\Repository

2.2 Navigate to D:\SVN\Repository, right click and select
'Create Repository here'

2.3 Choose FSFS filesystem

2.4 Create skeleton project structure somewhere: (where trunk is for
the main code, tags and branches for advanced stuff if used in the
future)

svn://localhost
+---PROJECT1
|   +---branches
|   +---tags
|   \---trunk
\---PROJECT2
   +---branches
   +---tags
   \---trunk

2.5 Right click folder Root, select 'Import' and navigate to
file:///D:/SVN/Repository


CREATE SVN SERVICE

3.1 Setup svnserve as Windows service using the following command (note space before auto after start=):
sc create svnserve binpath= "C:\Program Files (x86)\Subversion\bin\svnserve.exe --service --root D:\SVN\Repository" DisplayName= "Subversion Repository" depend= Tcpip start= auto
(logon as Local System)

3.2 Start the service and set to auto start

3.3 Add users and passwords to D:\SVN\Repository\conf\passwd file
   e.g. [users]
        username1 = password

3.4 Set authorisation settings by editing D:\SVN\Repository\conf\authz
   e.g. anon-access = none
        auth-access = write
        password-db = passwd


FIREWALL
Create rules names Subversion for port 3690, inbound & outbound, private network to allow access from other machines on the network.


GET IT WORKING ON A CLIENT MACHINE

4.1 On your machine, create a working code folder for a project, say
D:\CODE\PROJECT1

4.2 Checkout the trunk for that project by right clicking, selecting
'SVN Checkout', then navigating to
svn:///machinename/PROJECT1/trunk

Thats about it.



Sunday, February 21, 2010

MEF Links

Building Composable Apps in .NET 4 with the Managed Extensibility Framework
http://msdn.microsoft.com/en-us/magazine/ee291628.aspx

Codeplex docs
http://mef.codeplex.com/documentation

Digging a bit deeper
http://www.codeproject.com/KB/library/mefpart1.aspx
http://www.codeproject.com/KB/library/mefpart2.aspx

Web casts on everything you wanted to know about using MEF in Silverlight 4
http://codebetter.com/blogs/glenn.block/archive/2010/02/16/learning-about-mef-in-sl4-from-mike-taulty.aspx

People
http://blogs.msdn.com/gblock/default.aspx

MVC-MVP-MVVM Pattern article links

General Articles

DataModel-View-ViewModel pattern series by Dan Crevier
http://blogs.msdn.com/dancre/archive/2006/10/11/datamodel-view-viewmodel-pattern-series.aspx

Excellent overview including comparisons
http://www.aspiringcraftsman.com/2007/08/interactive-application-architecture/

 - Jeremy Miller's summary
http://codebetter.com/blogs/jeremy.miller/archive/2007/10/31/development-trivial-pursuit-the-difference-between-mvc-and-the-different-flavors-of-mvp.aspx
 -  Jeremy Miller's "Build Your Own CAB" series on designing WinForms apps

http://codebetter.com/blogs/jeremy.miller/archive/2007/07/25/the-build-your-own-cab-series-table-of-contents.aspx
http://code.google.com/p/buildyourowncab/source/browse/#svn/trunk/src

Stackoverflow discussion
http://stackoverflow.com/questions/2056/what-are-mvp-and-mvc-and-what-is-the-difference/101561#101561

Rob Eisenberg's MVVM study:
http://devlicio.us/blogs/rob_eisenberg/archive/2009/07/07/mvvm-philosophy-and-case-studies-introduction.aspx
http://devlicio.us/blogs/rob_eisenberg/archive/2009/08/02/mvvm-study-part-2-view-of-the-model-or-model-of-the-view.aspx
http://devlicio.us/blogs/rob_eisenberg/archive/2009/09/01/mvvm-study-part-3-why.aspx
http://devlicio.us/blogs/rob_eisenberg/archive/2009/11/13/mvvm-study-part-4-naked-wpf.aspx
http://devlicio.us/blogs/rob_eisenberg/archive/2009/12/14/mvvm-study-part-5-convention-over-configuration.aspx



WPF/Silverlight Frameworks

Prism: Composite Application Guidance for WPF and Silverlight
http://compositewpf.codeplex.com/
http://msdn.microsoft.com/en-us/library/cc707819.aspx (CAG docs)

Caliburn: MVC, MVP, MVVM and Commands for WPF and Silverlight applications
http://caliburn.codeplex.com/
http://caliburn.codeplex.com/documentation

Wednesday, February 17, 2010

String Formatting in C#

See these great references:

Numbers

Basic number formatting specifiers:

Specifier

Type

Format

Output (Passed Double 1.42)

Output (Passed Int -12400)

c

Currency

{0:c}

$1.42

-$12,400

d

Decimal (Whole number)

{0:d}

System.FormatException

-12400

e

Scientific

{0:e}

1.420000e+000

-1.240000e+004

f

Fixed point

{0:f}

1.42

-12400.00

g

General

{0:g}

1.42

-12400

n

Number with commas for thousands

{0:n}

1.42

-12,400

r

Round trippable

{0:r}

1.42

System.FormatException

x

Hexadecimal

{0:x4}

System.FormatException

cf90

Custom number formatting:

Specifier

Type

Example

Output (Passed Double 1500.42)

Note

0

Zero placeholder

{0:00.0000}

1500.4200

Pads with zeroes.

#

Digit placeholder

{0:(#).##}

(1500).42

.

Decimal point

{0:0.0}

1500.4

,

Thousand separator

{0:0,0}

1,500

Must be between two zeroes.

,.

Number scaling

{0:0,.}

2

Comma adjacent to Period scales by 1000.

%

Percent

{0:0%}

150042%

Multiplies by 100, adds % sign.

e

Exponent placeholder

{0:00e+0}

15e+2

Many exponent formats available.

;

Group separator

see below

Dates

Note that date formatting is especially dependant on the system’s regional settings.

Specifier

Type

Example (Passed System.DateTime.Now)

d

Short date

10/12/2002

D

Long date

December 10, 2002

t

Short time

10:11 PM

T

Long time

10:11:29 PM

f

Full date & time

December 10, 2002 10:11 PM

F

Full date & time (long)

December 10, 2002 10:11:29 PM

g

Default date & time

10/12/2002 10:11 PM

G

Default date & time (long)

10/12/2002 10:11:29 PM

M

Month day pattern

December 10

r

RFC1123 date string

Tue, 10 Dec 2002 22:11:29 GMT

s

Sortable date string

2002-12-10T22:11:29

u

Universal sortable, local time

2002-12-10 22:13:50Z

U

Universal sortable, GMT

December 11, 2002 3:13:50 AM

Y

Year month pattern

December, 2002

The ‘U’ specifier seems broken; that string certainly isn’t sortable.

Custom date formatting:

Specifier

Type

Example

Example Output

dd

Day

{0:dd}

10

ddd

Day name

{0:ddd}

Tue

dddd

Full day name

{0:dddd}

Tuesday

f, ff, …

Second fractions

{0:fff}

932

gg, …

Era

{0:gg}

A.D.

hh

2 digit hour

{0:hh}

10

HH

2 digit hour, 24hr format

{0:HH}

22

mm

Minute 00-59

{0:mm}

38

MM

Month 01-12

{0:MM}

12

MMM

Month abbreviation

{0:MMM}

Dec

MMMM

Full month name

{0:MMMM}

December

ss

Seconds 00-59

{0:ss}

46

tt

AM or PM

{0:tt}

PM

yy

Year, 2 digits

{0:yy}

02

yyyy

Year

{0:yyyy}

2002

zz

Timezone offset, 2 digits

{0:zz}

-05

zzz

Full timezone offset

{0:zzz}

-05:00

:

Separator

{0:hh:mm:ss}

10:43:20

/

Separator

{0:dd/MM/yyyy}

10/12/2002