Skip to content

Instantly share code, notes, and snippets.

View khalidabuhakmeh's full-sized avatar
🎯
Focusing

Khalid Abuhakmeh khalidabuhakmeh

🎯
Focusing
View GitHub Profile
@khalidabuhakmeh
khalidabuhakmeh / gist:376337ec06701b314f15
Created March 3, 2015 14:43
FluentValidation working with WebAPI
FluentValidationModelValidatorProvider.Configure(GlobalConfiguration.Configuration, config =>
{
config.ValidatorFactory = new WebApiValidatorFactory(GlobalConfiguration.Configuration);
});
public class WebApiValidatorFactory : ValidatorFactoryBase
{
private readonly HttpConfiguration _configuration;
public WebApiValidatorFactory(HttpConfiguration configuration)
### Keybase proof
I hereby claim:
* I am khalidabuhakmeh on github.
* I am khalidabuhakmeh (https://keybase.io/khalidabuhakmeh) on keybase.
* I have a public key whose fingerprint is 4292 F2BE 8F4F 22A3 7EB3 313C EE64 C1F6 9463 EB97
To claim this, I am signing this object:
public class StructureMapDependencyResolver : ServiceLocatorImplBase
{
private const string StructuremapNestedContainerKey = "Structuremap.Nested.Container";
public IContainer Container { get; set; }
private HttpContextBase HttpContext
{
get
{
// All the user to register where the context comes from
PerfMatter.TitleResolver = DependencyResolver.Current.GetService<ITitleResolver>();
public class MyTitleResolver : ITitleResolver {
// pass in whatever values you need
// The FlushHead() method automatically copies over any ViewData/ViewBag state, accepts an optional title parameter as well an optional model parameter, if required. Pass it in here
public string Resolve(IDictionary<string,object> values) {
var title = "";
// Figure out the title based on the context
return title;
public class BusinessMappingTests
{
public BusinessMappingTests()
{
Mapper.Initialize(cfg => cfg.AddProfile<BusinessMappingProfile>());
Mapper.AssertConfigurationIsValid();
}
[Fact]
public void Can_map_editmodel_to_business()
@khalidabuhakmeh
khalidabuhakmeh / gist:9412344
Created March 7, 2014 14:22
Refresh Claims for AuthenticationManager OWIN
public async Task Refresh(ClaimsIdentity claim, bool? rememberMe)
{
var current = _authenticationManager.User;
var remember = current.Claims.FirstOrDefault(x => x.Type == ClaimTypes.IsPersistent);
if (rememberMe.HasValue) {
// remember the "remember me" :)
claim.AddClaim(new Claim(ClaimTypes.IsPersistent, rememberMe.ToString()));
}
else if (claim != null) {
public ActionResult Index() {
return ProgressFlushResult(x => {
x.PartialView("First");
x.PartialView("Second");
x.PartialView("Third");
});
}
@khalidabuhakmeh
khalidabuhakmeh / gist:9057639
Last active August 29, 2015 13:56
How Read a File From A Line
var username = **YOUR USERNAME**;
var password = **YOUR PASSWORD**;
var url = "http://hackers-endpoint.com?username={0}&password={1}";
var client = new HttpClient();
var response = await client.GetAsync(string.Format(url, username, password));
response.EnsureSuccessStatusCode();
@khalidabuhakmeh
khalidabuhakmeh / gist:8115759
Created December 24, 2013 17:06
Searching Jekyll directory for results
// put this in your browser
https://api.github.com/search/code?q=kotlin+repo:hhariri/hhariri.github.io
// Get a list of JSON results back :)
// Potentially do some JSON / JavaScript magic to show the results and links.
@khalidabuhakmeh
khalidabuhakmeh / documentation.cs
Created November 22, 2013 14:10
Documentation Framework that turns your unit tests into documentation. While there are explicit settings below, you would most likely have sensible defaults for titles, section names, and documentation files external to your unit tests.
[Documentation(Section = "Math",
Intro = "addition_intro.md",
Conclusion = "addition_conclusion.md",
Order = 1 )]
public class Addition
{
[Fact]
[Documentation(Title = "Adding Two Numbers", Intro = "adding_two_numbers.md", Order = 1)]
public void Adding_two_numbers()
{