Skip to content

Instantly share code, notes, and snippets.

View khalidabuhakmeh's full-sized avatar
👻
🚀🧠🥑

Khalid Abuhakmeh khalidabuhakmeh

👻
🚀🧠🥑
View GitHub Profile
@khalidabuhakmeh
khalidabuhakmeh / gist:1125350
Created August 4, 2011 14:54
Cascading Validation on children validators
public class OrderViewModel {
public bool UsingOldCard {get;set;}
public int OldCardId {get;set;}
public NewCardViewModel NewCard {get;set}
public int ItemId {get;set;}
}
public class NewCardViewModelValidator: AbstractValidator<NewCardViewModel> {
public class NewCardViewModelValidator() {
RuleFor(m => m.FirstName).NotEmpty();
@khalidabuhakmeh
khalidabuhakmeh / jquery.validate.unobtrusive.js
Created August 5, 2011 19:20
Fix to jquery.validate.unobtrusive.min.js (now works with password confirmation)
/// <reference path="jquery-1.5.1.js" />
/// <reference path="jquery.validate.js" />
/*!
** Unobtrusive validation support library for jQuery and jQuery Validate
** Copyright (C) Microsoft Corporation. All rights reserved.
*/
/*jslint white: true, browser: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, newcap: true, immed: true, strict: false */
/*global document: false, jQuery: false */
@khalidabuhakmeh
khalidabuhakmeh / gist:2660235
Created May 11, 2012 14:51
Git Prompt helper
# more helpful source control prompts
parse_git_branch () {
git name-rev HEAD 2> /dev/null | sed 's#HEAD\ \(.*\)# (git::\1)#'
}
parse_hg_branch() {
hg branch 2>/dev/null | sed 's#\(.*\)# (hg::\1)#'
}
parse_svn_branch() {
parse_svn_url | sed -e 's#^'"$(parse_svn_repository_root)"'##g' | awk '{print " (svn::"$1")" }'
}
@khalidabuhakmeh
khalidabuhakmeh / RavenDB.cs
Created November 6, 2012 15:15
RavenDB If extension method
// usage
_db.Query<Story, Stories_Search>()
.If(status.HasValue, q => q.Where(x => x.Status == status))
.If(!curatorId.IsEmpty(), q => q.Where(x => x.CuratorId == curatorId))
.If(publicationDate.HasValue, q => q.Where(x => x.ProposedPublicationDate == publicationDate.Value.Date))
.OrderByDescending(x => x.CreatedAt)
.ToPagedList(page, size);
@khalidabuhakmeh
khalidabuhakmeh / LoadAny<T> with partial Id
Last active December 11, 2015 06:08
Loading documents from RavenDB Sharding without knowing what shard it is currently in.
using System;
using System.Collections.Generic;
using Raven.Client;
using Raven.Client.Document;
using Raven.Client.Shard;
namespace ShardingExample
{
class Program
{
RavenDB Questions
=================================
1. When should you start thinking about Replication with RavenDB?
a. What factors affect whether you should be thinking about replication.
b. since we are on replication, How does Master/Slave work in RavenDB and can we see it?
2. When should you start thinking about Sharding with RavenDB (# of documents, app locations, etc.)?
a. What factors affect whether you should be thinking about replication.
// Had to modify the ScriptCs ScriptExecutor to include System.Configuration
// It works as expected to get the appSettings, but not the natural way
// most devs will be used to with ConfigurationManager.AppSettings, also
// not sure if things like SmtpClient will pickup on it.
using System;
using System.Configuration;
var path = Environment.CurrentDirectory + "\\app.config";
Console.WriteLine(path);
using System;
using System.Collections.Generic;
namespace RandomScheduler
{
class Program
{
public static Random R = new Random();
static void Main()
using System;
using EndToEnd.Core;
using FluentAssertions;
using ServiceStack.FluentValidation;
using ServiceStack.ServiceClient.Web;
using ServiceStack.ServiceInterface.Auth;
using Xunit;
namespace EndToEnd
{
using System;
using EndToEnd.Core;
using FluentAssertions;
using ServiceStack.FluentValidation;
using ServiceStack.ServiceClient.Web;
using ServiceStack.ServiceInterface.Auth;
using Xunit;
namespace EndToEnd
{