Skip to content

Instantly share code, notes, and snippets.

View nberardi's full-sized avatar
😀

Nick Berardi nberardi

😀
View GitHub Profile
public class MefControllerFactory : IControllerFactory
{
private readonly WebScopedContainerManager _containerManager;
public MefControllerFactory(WebScopedContainerManager containerManager)
{
_containerManager = containerManager;
}
#region IControllerFactory Members
@nberardi
nberardi / IObjectContext.cs
Created November 17, 2010 23:25
Code for my post on Repository Pattern for Entity Framework: http://coderjournal.com/2010/11/entity-framework-repository-pattern/
public interface IObjectContext : IDisposable
{
ObjectContextOptions ContextOptions { get; }
TEntity CreateObject<TEntity>() where TEntity : class;
IObjectSet<TEntity> CreateObjectSet<TEntity>() where TEntity : class;
int SaveChanges();
}
@TextSearchField("test", "test", true)
@helper TextSearchField(string name, string label, bool autocomplete)
{
<div class="searchCrit">
<label for="@name">@label</label>
@if(autocomplete) {
<input type="text" name="@name" class="autocompleteField" />
}
@nberardi
nberardi / cassandra_test-01.cs
Created November 15, 2011 08:49 — forked from kellabyte/cassandra_test-01.cs
Cassandra Performance Test
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using FluentCassandra;
using FluentCassandra.Types;
namespace CassandraTest1
{
class Program
{
@nberardi
nberardi / SequentialNumberGenerator.cs
Created January 19, 2012 17:39
Sequential Number Generator for RavenDB
private static readonly object GeneratorLock = new object();
///<summary>
/// Create the next id (numeric)
///</summary>
private int NextAccountNumber()
{
lock (GeneratorLock)
{
using (new TransactionScope(TransactionScopeOption.Suppress))
@nberardi
nberardi / Microsoft.PowerShell_profile.ps1
Created May 2, 2012 14:01
Nick Berardi's PowerShell Profile
###############################################################################
# global variables
###############################################################################
$profileDir = [System.IO.Path]::GetDirectoryName($profile)
###############################################################################
# Set up a simple prompt, adding the git prompt parts inside git repos
###############################################################################
function prompt {
$realLASTEXITCODE = $LASTEXITCODE
@nberardi
nberardi / zlip.cs
Created May 12, 2012 15:03
ZLIB compression in .NET
public static byte[] ZlibCompress(byte[] data)
{
using (MemoryStream outStream = new MemoryStream())
{
// zlib header
outStream.WriteByte(0x58);
outStream.WriteByte(0x85);
// zlib body
using (var compressor = new DeflateStream(outStream, CompressionMode.Compress, true))
@nberardi
nberardi / BigDecimal.cs
Created May 12, 2012 15:17
BigDecimal type in .NET
using System;
using System.Linq;
namespace System.Numerics
{
public struct BigDecimal : IConvertible, IFormattable, IComparable, IComparable<BigDecimal>, IEquatable<BigDecimal>
{
public static readonly BigDecimal MinusOne = new BigDecimal(BigInteger.MinusOne, 0);
public static readonly BigDecimal Zero = new BigDecimal(BigInteger.Zero, 0);
public static readonly BigDecimal One = new BigDecimal(BigInteger.One, 0);
@nberardi
nberardi / GuidGenerator.cs
Created September 21, 2012 04:21
TimeUUID Generator for .NET
using System;
namespace FluentCassandra
{
/// <summary>
/// Used for generating UUID based on RFC 4122.
/// </summary>
/// <seealso href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122 - A Universally Unique IDentifier (UUID) URN Namespace</seealso>
public static partial class GuidGenerator
{
@nberardi
nberardi / DateTimePrecise.cs
Created September 21, 2012 04:46
A more precise DateTime in .NET
using System;
using System.Diagnostics;
using System.Linq;
namespace System
{
public class DateTimePrecise
{
private static readonly DateTimePrecise Instance = new DateTimePrecise(10);