Skip to content

Instantly share code, notes, and snippets.

View StefanBilliet's full-sized avatar

Stefan Billiet StefanBilliet

View GitHub Profile
@StefanBilliet
StefanBilliet / csharp.json
Created February 21, 2017 09:29
VS Code C# snippets modified to have braces starting on same line
{
"Attribute using recommended pattern": {
"prefix": "attribute",
"body": [
"[System.AttributeUsage(System.AttributeTargets.${All}, Inherited = ${false}, AllowMultiple = ${true})]",
"sealed class ${My}Attribute : System.Attribute",
"{",
" // See the attribute guidelines at",
" // http://go.microsoft.com/fwlink/?LinkId=85236",
@StefanBilliet
StefanBilliet / gist:6fb3215ea8309564d3d6
Created February 25, 2016 08:36
AppleScript to add service to launch iTerm2 by right clicking on folder
on run {input, parameters}
tell application "Finder"
set dir_path to "\"" & (POSIX path of (input as string)) & "\""
-- display dialog dir_path
end tell
CD_to(dir_path)
end run
on CD_to(theDir)
tell application "iTerm"
@StefanBilliet
StefanBilliet / gist:982ef274c4303235ecd7
Created March 18, 2015 08:29
xUnit2/FakeItEasy issue
public class TestFixture1 {
[Fact]
public async Task FactMethodName1() {
var sut = A.Fake<IAsyncClass>();
await sut.GetAsync(new Input{Test = "test"});
A.CallTo(() => sut.GetAsync(A<Input>.That.Matches(_ => _.Test == "test"))).MustHaveHappened();
}
@StefanBilliet
StefanBilliet / MessageTypeScanner.cs
Last active August 29, 2015 14:13
MessageTypeScanner
public static class MessageTypeScanner {
public static IEnumerable<Type> ScanAllEventHandlers(Assembly assembly) {
var handlers = from type in assembly.GetTypes()
where type.GetInterfaces().Any(IsEventHandler)
select type;
return handlers.
SelectMany(handler => handler.GetInterfaces().Where(IsEventHandler).Select(@interface => @interface.GetGenericArguments()[0])).
Distinct();
}
@StefanBilliet
StefanBilliet / gist:02bc7422c24f7cea4e93
Created September 18, 2014 13:25
Array filtering with promise filter function
var allowedItemPromises = items.map(function (item) {
return $.Deferred(function (dfd) {
promiseThatChecksSomethingServerside.done(function (filterPasses) {
dfd.resolve(filterPasses ? [item] : []);
});
}).promise();
});
$.when.apply($, allowedItemPromises).then(function () {
var result = [].slice.call(arguments);
@StefanBilliet
StefanBilliet / prepare-commit-msg
Last active August 29, 2015 14:02
A git prepare-commit-msg hook to prepend the commit message with the issue number, based on the branch name
#!/bin/sh
branchName=$(git branch | grep '*' | sed 's/* //')
if [ $(echo "$branchName" | grep -E "^[a-z]{3}[0-9]*$") ]; then
uppercaseBranchName=`echo $branchName | awk '{print toupper($0)}'`;
length=${#uppercaseBranchName};
issueNumber=${uppercaseBranchName:0:3}-${uppercaseBranchName:3:length};
sed -i.bak -e "1s/^/$issueNumber /" $1
else