Skip to content

Instantly share code, notes, and snippets.

public static Boolean IsDirtyEntity(this ISession session, Object entity)
{
return (DirtyPropertiesOf(session, entity).Any());
}
public static IEnumerable<string> DirtyPropertiesOf(this ISession session, Object entity)
{
String className = NHibernateProxyHelper.GuessClass(entity).FullName;
ISessionImplementor sessionImpl = session.GetSessionImplementation();
bool mystery(uint num){
uint other = num - 1;
bool result = ((num & other) == 0);
return result;
}
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ConsoleApplication1" namespace="ConsoleApplication1">
<sql-query name="CatById">
<return class="Category"></return>
EXEC CatById :id
</sql-query>
</hibernate-mapping>
public static Expression<Func<TEntity, TReturn>> GetFieldExpression<TEntity, TReturn>(string fieldName)
{
var type = typeof(TEntity);
var member = type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)
.FirstOrDefault(x => x.Name == fieldName);
if (member == null)
throw new UnknownPropertyException(type, fieldName);
var param = Expression.Parameter(member.DeclaringType, "x");
var handleException = new Action<Exception>(e =>
{
Console.WriteLine("Handle Exception: " + e);
});
var someCodeThatThrowsAnException = new Action(() =>
{
try
{
throw new Exception("I threw an Exception!");
@jdaigle
jdaigle / gist:767876
Created January 6, 2011 13:23
get information from a service broker queue for monitoring purposes
SELECT
COUNT([QUEUENAME].[conversation_handle])
FROM [QUEUENAME]
INNER JOIN sys.service_message_types
ON [QUEUENAME].[message_type_id] = sys.service_message_types.[message_type_id]
INNER JOIN sys.conversation_endpoints
ON [QUEUENAME].[conversation_handle] = sys.conversation_endpoints.[conversation_handle]
WHERE sys.service_message_types.name = 'NServiceBusTransportMessage'
AND sys.conversation_endpoints.security_timestamp > @minDate
public static TimeZoneInfo ToTimeZoneInfo(this TimeZones zone) {
switch (zone) {
case TimeZones.Central:
return TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
case TimeZones.Mountain:
return TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time");
case TimeZones.Pacific:
return TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
case TimeZones.Arizona:
return TimeZoneInfo.FindSystemTimeZoneById("US Mountain Standard Time");
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SplitGuids]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[SplitGuids]
GO
CREATE FUNCTION [dbo].[SplitGuids]
(
@List varchar(2000)
)
RETURNS
@ParsedList table
@jdaigle
jdaigle / gist:1083608
Created July 14, 2011 22:20
No Frills JQuery/HTML5 Validation
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
if (typeof (nfvalidate) == "undefined") nfvalidate = {};
// An array of validators to push your validators to
nfvalidate.validators = new Array();
nfvalidate.validators.push({
<UserSettings>
<ApplicationIdentity version="9.0"/>
<ToolsOptions>
<ToolsOptionsCategory name="Environment" RegisteredName="Environment">
<ToolsOptionsSubCategory name="Documents" RegisteredName="Documents" PackageName="Visual Studio Environment Package">
<PropertyValue name="ShowMiscFilesProject">false</PropertyValue>
<PropertyValue name="AutoloadExternalChanges">false</PropertyValue>
<PropertyValue name="CheckForConsistentLineEndings">false</PropertyValue>
<PropertyValue name="SaveDocsAsUnicodeWhenDataLoss">false</PropertyValue>
<PropertyValue name="InitializeOpenFileFromCurrentDocument">true</PropertyValue>