I’ve recently put up my first MVC project online: CodePaste.NET, which is a public code pasting site that allows you to paste and link code from social network sites like Twitter and Facebook or chat and IM applications like Skype or Messenger. The idea is that these social network or chat clients work well for interactive discussion but they don’t allow enough space to post even the shortest snippets of code for all participants to see. As a developer a lot of my Twitter traffic deals with discussions around code or code concepts so a place to share and view code is very useful.
So rather than squeezing code snippets into these clients you can post it on the the CodePaste.NET site and then link to the snippet.
To be clear this isn’t an original idea. The conceptual credit for this idea goes to pastie.org and several other sites that provide similar basic services. In fact, I’d been using pastie.org for some time for posting and linking code snippets and most of the ideas of the CodePaste site are directly derived from the base concept of pastie.org. However, CodePaste.NET is a little more specific to .NET developers, providing syntax highlighting and the ability to apply comments on snippets and few other features planned for later releases.
How does it work?
In case you haven’t used any of the code pasting sites, lets take a look and see how the process works.
- You create a new Code Snippet by entering your code and giving it a title
- You ‘paste’ it
- You capture the link from the Address Bar
- You reference the link in a Social Network client
- Other people can click the link and view your pasted code
- Discussion ensues! (hopefully)
To create a new code snippet just takes a few seconds using a simple input form:
Ok maybe it doesn’t look quite so simple, but only the title and code fields are required if you’re in a hurry. The rest of the fields are optional. Selecting a language is useful for syntax highlighting and you can apply a comma delimited list of tag strings so the code can be cross referenced (at some point when there’s better search support ;-}).
Common left margins are automatically cleared from the code you paste so the code will left align properly even if you cut out of the middle of a nested code file which I find very helpful (not surprisingly, eh?). You can optionally specify that your snippet should show line numbers by default although you you can also manually toggle those on and off on the actual code display page.
Once you’ve ‘pasted’ your code you end up with a linkable page that looks something like this:
The link looks something like this:
which can pick out of the Address bad and then easily embed into social network clients as a URL link. Codepaste URLs are short so they take up minimal space in tweets even without URL truncation.
Below you can see a code link to CodePaste.NET linked from a Twitter tweet and a Skype chat:
The links point at the snippet page which displays code in a number of syntax color highlighting formats. From this page you can paste code to the clipboard and toggle line numbers via the toolbar options just above the code or you can manually select and grab the code from the HTML.
If you are signed in and on your own snippet you can also edit/update the snippet, language, tags and original code comment entered inline of the page. Signed in users can also create comments on their own or other user’s code snippets. Sign in is totally optional – you can paste code without being signed to make it as quick and easy as possible to get code posted and linked. Signing in allows for seeing your snippets in context as well as the ability to update your snippets and posting comments to other snippets.
The viewing options available currently are pretty slim with only a Recent and My Snippet list views. The following is the Recent View:
that lets you see 30 or so of the most recent snippets. In the future there will be additional list views for searching and friend views.
The individual snippet view and any of the list views can also return data in JSON, XML, RSS or ATOM formats by following any of the urls with ?format=json (or xml,rss,atom). Here are a few examples:
You can append the ?format= to most URLs and get an API result of the data. Rss and Atom only work on list data not on individual snippets. Eventually there will also be a more formal API to retrieve code snippets with an API controller (only stubbed at this point).
The main RSS feed can be accessed via Feedburner and links to the recent snippet view:
The feed doesn’t include syntax highlighting at the moment as the highlighting relies on a stylesheet not accessible in the feed.
This project has been a side project I used for taking ASP.NET MVC for a spin. It’s been a learning experience and while it took a bit of adjustment the learning process and implementation was easier than I would have thought. The site is a work in process and I’ll be talking more about my experience with MVC from the perspective of the WebForms mindset.
The site is a work in process and I’ve put the code for this project into a public Subversion repository at:
so if you want to have a look or play with this yourself have a look. Be gentle with your criticism though – it’s my first MVC app and I’m sure the MVC diehards will have lots of issues with my implementation or even overall philosophy. But I welcome some discussion and ideas. If you are interested in contributing or providing feedback you can do so on our message board:
Primarily though I built this as a tool to post and discuss code myself, so if nothing else it’s useful to me. I hope some of you will find it useful as well and the site is available for you to use as you see fit. I’m hoping to evolve this site a bit – I think there are lots of cool things that can be done with this as a code snippet repository.
Anyway, stop by the site and check it out…