Skip to content

Instantly share code, notes, and snippets.

Stefan Hendriks stefanhendriks

View GitHub Profile
@stefanhendriks
stefanhendriks / cookieshelper.cs
Last active Feb 22, 2019
A cookies helper class to easily read and set cookies on HttpRequest (Asp.Net Core)
View cookieshelper.cs
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;
View maven_and_java_home_checklist.md

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 / PostRequestHelper.cs
Last active May 11, 2016
Helper class to construct a HttpRequest message for easily POSTing data (Asp.net Core)
View PostRequestHelper.cs
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
AntiForgeryHelper class to read token from request (Asp.Net core)
View AntiForgeryHelper.cs
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 / git_current_branch_term
Created Dec 7, 2012
Show git branch in terminal (macOSX) of current directory
View git_current_branch_term
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\]"
View 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 Oct 11, 2012
Bowling game kata test - ultimate test for nasty bug
View gist:3875680
@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 Sep 11, 2012
LEDDisplayKataJava thoughts
View gist:3696795
Possible improvements:
- put display numbers into one dimensional array
Possible additions:
- make it possible to use different character sets (your own numbers)
You can’t perform that action at this time.