Skip to content

Instantly share code, notes, and snippets.

@hyrmn
hyrmn / IndexModule.cs
Created October 4, 2013 22:14
Showing cats with Dapper and PostgreSQL and NancyFX
using System.Data;
using Npgsql;
using Nancy;
using Dapper;
namespace NancyApplication1
{
public class IndexModule : NancyModule
{
private const string ConnectionString = "Server=localhost;User Id=postgres;password=Postgres1234;database=demo";
@hyrmn
hyrmn / textbox.js
Created October 5, 2013 20:16
Wire-up validation
angular.module('ui.textbox', [])
.directive('textbox', [function () {
return {
restrict: 'E',
replace: true,
require: '^form',
scope: {
model: '=',
name: '=',
uiName: '@',
@hyrmn
hyrmn / pwdValidate.js
Created October 5, 2013 20:19
Custom validation with popover
angular.module('profile.changePwd.pwdValidate', [])
.directive('pwdValidate', function () {
return {
require: 'ngModel',
restrict: 'A',
template: '<input data-placement="right" bs-popover="passwordRules" data-hide="hidePopup" data-trigger="focus">',
replace: true,
transclude: 'element',
link: function (scope, element, attrs, ctrl) {
ctrl.$parsers.unshift(function (viewValue) {
@hyrmn
hyrmn / 0_IndexDefinition.cs
Last active December 25, 2015 04:39
Patching in RavenDB
public class PosItemProjection_ByCategoryId : AbstractIndexCreationTask<PosItemProjection>
{
public PosItemProjection_ByCategoryId()
{
Map = items => from item in items select new { item.CategoryId };
Index(x => x.CategoryId, FieldIndexing.NotAnalyzed);
}
}
@hyrmn
hyrmn / somebaseclass.cs
Created November 14, 2013 16:00
wireup for ravendb + indexes in unit tests
static using_a_wired_environment()
{
DocumentStore = new EmbeddableDocumentStore
{
RunInMemory = true,
Conventions = { JsonContractResolver = new RavenContractResolver(true), MaxNumberOfRequestsPerSession = int.MaxValue, }
};
DocumentStore.Conventions.CustomizeJsonSerializer = jsonSerializer => { jsonSerializer.ConfigureForNodaTime(DateTimeZoneProviders.Bcl); };
DocumentStore.RegisterListener(new NoStaleQueriesAllowed());
@hyrmn
hyrmn / EnumerationJsonConverter.cs
Created November 26, 2013 05:33
Json serializer / deserializer for Headspring Lab's Enumeration
public class EnumerationJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return IsEnumeration(objectType);
}
public bool IsEnumeration(Type type)
{
if (type == null || type.BaseType == null || !type.BaseType.IsGenericType) return false;
function prompt
{
$(get-location) + "> "
}
function Get-Batchfile ($file) {
$cmd = "`"$file`" & set"
cmd /c $cmd | Foreach-Object {
$p, $v = $_.split('=')
Set-Item -path env:$p -value $v
var bus = BusSetup.StartWith<Conservative>()
.Apply<IoCSupport>(s => s.SetAdapter(new StructureMapAdapter())
.SetHandlerInterface(typeof(IHandleMessage<>)))
.Construct();
public class StructureMapAdapter : IocAdapter
{
public IEnumerable<object> GetAllInstances(Type desiredType)
{
using System;
using System.Collections.Generic;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
namespace Infrastructure.Azure
{
public class ServiceBus
{
public class PersonSummaryIndex : AbstractIndexCreationTask<PersonProjection>
{
public PersonSummaryIndex()
{
Map = people => from person in people
select new
{
person.Id,
Query = new object[]
{