Skip to content

Instantly share code, notes, and snippets.

View stefanhendriks's full-sized avatar

Stefan Hendriks stefanhendriks

View GitHub Profile
@stefanhendriks
stefanhendriks / PostRequestHelper.cs
Last active May 11, 2016 18:43
Helper class to construct a HttpRequest message for easily POSTing data (Asp.net Core)
public class PostRequestHelper
{
public static HttpRequestMessage Create(String path, Dictionary<string, string> formPostBodyData)
{
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, path)
{
Content = new FormUrlEncodedContent(ToFormPostData(formPostBodyData))
};
return httpRequestMessage;
}
@stefanhendriks
stefanhendriks / AntiForgeryHelper.cs
Created May 11, 2016 18:32
AntiForgeryHelper class to read token from request (Asp.Net core)
public class AntiForgeryHelper
{
public static string ExtractAntiForgeryToken(string htmlResponseText)
{
if (htmlResponseText == null) throw new ArgumentNullException("htmlResponseText");
System.Text.RegularExpressions.Match match = Regex.Match(htmlResponseText, @"\<input name=""__RequestVerificationToken"" type=""hidden"" value=""([^""]+)"" \/\>");
return match.Success ? match.Groups[1].Captures[0].Value : null;
}
@stefanhendriks
stefanhendriks / cookieshelper.cs
Last active June 4, 2023 17:14
A cookies helper class to easily read and set cookies on HttpRequest (Asp.Net Core)
public class CookiesHelper
{
// Inspired from:
// https://github.com/aspnet/Mvc/blob/538cd9c19121f8d3171cbfddd5d842cbb756df3e/test/Microsoft.AspNet.Mvc.FunctionalTests/TempDataTest.cs#L201-L202
public static IDictionary<string, string> ExtractCookiesFromResponse(HttpResponseMessage response)
{
IDictionary<string, string> result = new Dictionary<string, string>();
IEnumerable<string> values;
@stefanhendriks
stefanhendriks / maven_and_java_home_checklist.md
Last active September 4, 2016 22:48
Maven and JAVA_HOME

When running maven you might see a different JAVA_HOME version than when you're running java -version

In general sense this means when you run mvn a new shell is opened and your JAVA_HOME is (re)set. This means, especially if you need to work with different Java versions, that you must be sure you don't override the version you're working on.

First thing you need to make sure is that you only set JAVA_HOME once.

In relation to Maven you might have something set in :

  • ~/.mavenrc
  • /etc/mavenrc
@stefanhendriks
stefanhendriks / git_current_branch_term
Created December 7, 2012 19:40
Show git branch in terminal (macOSX) of current directory
Add this to .profile (if not exist, create it):
# This shows the git branch of the current directory
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
@stefanhendriks
stefanhendriks / vimrc
Created November 16, 2012 20:33
.vimrc
call pathogen#infect()
syntax on
filetype plugin indent on
"Add mapping for opening NERDTree
nmap <silent> <C-D> :NERDTreeToggle<CR>
colorscheme distinguished
" set default height and width for gvim
@stefanhendriks
stefanhendriks / gist:3875680
Created October 11, 2012 21:41
Bowling game kata test - ultimate test for nasty bug
@Test
public void nastyBug() {
rollStrike();
game.roll(0);
game.roll(10); // spare
game.roll(0);
game.roll(2);
rollMany(14, 0);
Assert.assertEquals(32, game.score());
}
@stefanhendriks
stefanhendriks / gist:3696795
Created September 11, 2012 08:00
LEDDisplayKataJava thoughts
Possible improvements:
- put display numbers into one dimensional array
Possible additions:
- make it possible to use different character sets (your own numbers)