Skip to content

Instantly share code, notes, and snippets.

@azcoov
azcoov / SparklineHtmlHelper.cs
Created January 21, 2011 22:21
Renders a Google Chart Sparkline
namespace Sparkline.Helpers
{
public static class ChartHelper
{
public static String DrawSparkline(this HtmlHelper helper, String display, List<Int32?> plotData)
{
int? max = plotData.Max();
int? min = plotData.Min();
string list = String.Join(",", plotData);
String spark = "<img src=\"http://chart.apis.google.com/chart?cht=lc&chf=bg,s,F5F5F5&cgh=0,50,1,0&chds={0},{1}&chs={2}&chd=t:{3}&chco=999999&chls=1,1,0&chm=o,990000,0,20,4&chxt=r,x,y&chxs=0,990000,11,0,_|1,990000,1,0,_|2,990000,1,0,_&chxl=0:|{4}|1:||2:||\">";
@azcoov
azcoov / MVC View for rendering sparklines.html
Created January 21, 2011 22:24
MVC View for rendering sparklines
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Sparkline.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Spark Line Example
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Hello Sparkline</h2>
<p>
@azcoov
azcoov / sqltagcloud.sql
Created January 23, 2011 02:12
SQL Tag Cloud
declare @MaxTagFrequency int
declare @tt_Tags table(
BlogCategory_ID int,
[Count] int
)
insert into
@tt_Tags
select top(@CountLimit)
bc.BlogCategory_ID,
@azcoov
azcoov / linq_tag_cloud.cs
Created January 23, 2011 02:13
Linq Tag Cloud
var categories = from c in data.GraphicCategories
join g in data.Graphics on c.GraphicCategory_ID equals g.GraphicCategory_ID
group c by c.LongDescription into categoryGroup
select new
{
Category = categoryGroup.Key,
CategoryFrequency = categoryGroup.Count()
};
Int32 maxCategoryFrequency = (from c in categories select c.CategoryFrequency).Max();
@azcoov
azcoov / tagcloud.js
Created January 23, 2011 02:15
Javascript for Flash tag cloud
<script type="text/javascript" src="/Content/swfobject.js"></script>
<script type="text/javascript">
var divRecentTags = document.getElementById("recent-tags");
if (divRecentTags) {
var cloud = new SWFObject("/Content/tagcloud.swf", "tagcloudflash", "275", "200", "9", "#ffffff");
cloud.addParam("allowScriptAccess", "always");
cloud.addVariable("tcolor", "0x6290B8");
cloud.addVariable("tcolor2", "0x000000");
cloud.addVariable("hicolor", "0xFE5655");
cloud.addVariable("tspeed", "100");
@azcoov
azcoov / tag_cloud_partial_view.html
Created January 23, 2011 02:19
Tag Cloud Partial View
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<div id="recent-tags">
<% foreach (var t in (IEnumerable<Models.BlogCategory>)ViewData["TagCloud"])
{%>
<a href="http://mysite/Blog/Listing/<%= Html.Encode(t.Category) %>" class="<%= BlogHelper.GetTagClass(t.BlogCategory_ID) %>" ><%= t.Category %></a>
<% }%>
</div>
@azcoov
azcoov / blog_helper.cs
Created January 23, 2011 02:20
Weighted Tag Class
public static class BlogHelper
{
public static string GetTagClass(int id)
{
if (id % 2 == 0)
{
return "post-tag pop1";
}
else
{
@azcoov
azcoov / FindAllBlogCategories.cs
Created January 23, 2011 02:24
Linq to find all tags for tag cloud
// Repository
public IEnumerable<BlogCategory> FindAllBlogCategories()
{
return db.BlogCategories.OrderBy(c => c.BlogCategory_ID);
}
@azcoov
azcoov / blog_routes.cs
Created January 23, 2011 02:26
routes for my blog
routes.MapRoute(
"BlogPost",
"Entries",
new { controller = "Blog", action = "BlogPost"}
); // outputs: mysite.com/Entries?id=0
routes.MapRoute(
"BlogPost1",
"Entries/{id}",
new { controller = "Blog", action = "BlogPost" }
@azcoov
azcoov / complex_route_link.cs
Created January 23, 2011 02:28
Complex Route Link