If you’re developing a snippets or pastie-type system or another form of CMS where source code might be stored, it’d be incredibly useful to automatically detect what language a provided source is in so that you can style it appropriately.
Chris Lowis’ SourceClassifier (or Github repo) library does just that, using a Bayesian classifier trained on source code from the Alioth Shootouts. Out of the box it has support for C, Java, JavaScript, Perl, Python and Ruby, but you can train it to recognize others (CSS and HTML seem like notable omissions to me). Read More