Skip to content

Instantly share code, notes, and snippets.

@keithbloom
keithbloom / example1.cs
Created October 28, 2011 20:54
NullReferenceRhinoMocks
public void SetCookie(IHttpContextService context)
{
if (context == null)
return;
if (context.User == null)
return;
if (context.User.Identity == null)
return;
@keithbloom
keithbloom / example1.cs
Created October 27, 2011 20:44
MefToExtendAHttpModule
public interface ISetCookies
{
void SetCookie(HttpContext context);
}
@keithbloom
keithbloom / example1.sql
Created October 27, 2011 07:36
ExcelInSql
SELECT u.[region 1], s.full_name AS RegionalManager
FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', 'Data Source=c:\managers.xls;Extended Properties=Excel 8.0')...Updates$
JOIN staff s
on s.id = u.staff_id
@keithbloom
keithbloom / example1.sql
Created October 27, 2011 07:03
TopN Stored Procedure
SELECT TOP 5 description, hit_count
@keithbloom
keithbloom / Default.aspx.cs
Created October 7, 2011 14:34
WebFromsAndSRP
using System;
using WebFormsAndSRP.CookieManagement;
namespace WebFormsAndSRP
{
public partial class Default : System.Web.UI.Page
{
private IMarketingTracker _marketingTracker;
protected void Page_Load(object sender, EventArgs e)
{
@keithbloom
keithbloom / .gitignore
Created October 6, 2011 10:40
Remove files which should be ignored from a git repsoitory
ld/
*.suo
*.user
bin
Bin
obj
_ReSharper*
*.csproj.user
*.resharper.user
*.suo
@keithbloom
keithbloom / eilon-lipson-GetProperties
Created September 20, 2011 14:01
blog-post-using-iterators
private static IEnumerable<PropertyValue> GetProperties(object o)
{
if (o != null) {
var props = TypeDescriptor.GetProperties(o);
foreach (PropertyDescriptor prop in props) {
var val = prop.GetValue(o);
if (val != null) {
yield return new PropertyValue { Name = prop.Name, Value = val };
}
}
@keithbloom
keithbloom / gist:1048488
Created June 27, 2011 08:14
so_6469804
<html>
<head>
<script type="text/javascript" language="JavaScript">
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
public void ImportFiles()
{
var query = from f in files
where f.Extension.ToLower() == ".zip"
select new ImportContext
{
ZipFileName = f.FullName,
Path = UploadPath
};
@keithbloom
keithbloom / SelctWithIndexValue.cs
Created February 25, 2011 13:59
LINQ Select query which includes the iterator index in the projection
var lines = new[]
{
"Line1", "Line2", "Line3"
};
var query = lines.Select((line, index) => new
{
Prop = string.Format("Address{0}", index + 1),
Value = line
});