Skip to content

Instantly share code, notes, and snippets.

View hjerpbakk's full-sized avatar
🌝
Full-stack TypeScript 

Runar Ovesen Hjerpbakk hjerpbakk

🌝
Full-stack TypeScript 
View GitHub Profile
@hjerpbakk
hjerpbakk / TextWrapping.cs
Created May 15, 2013 17:12
Simple text wrapping using MonoGame / XNA.
private string WrapText(string text) {
if(font.MeasureString(text).X < MaxLineWidth) {
return text;
}
string[] words = text.Split(' ');
StringBuilder wrappedText = new StringBuilder();
float linewidth = 0f;
float spaceWidth = font.MeasureString(" ").X;
for(int i = 0; i < words.Length; ++i) {
@hjerpbakk
hjerpbakk / MoqExample.cs
Last active December 16, 2015 06:19
Example showing how to mock a method from an interface using Moq. From http://hjerpbakk.com/blog/2013/4/15/moq-mock-a-method-from-an-interface.html
public class MyClass {
private readonly ComplexClass complexClass;
public MyClass(ComplexClass complexClass) {
this.complexClass = complexClass;
}
public void Verify() {
((IVerifiable)complexClass).Verify();
}
@hjerpbakk
hjerpbakk / TestTimer.cs
Created April 3, 2013 13:03
Shows a message box containing the duration of all tests in an MSTest test class.
private static Stopwatch testTimer;
[ClassInitialize]
public static void ClassInit(TestContext testContext)
{
testTimer = new Stopwatch();
testTimer.Start();
}
[ClassCleanup]
@hjerpbakk
hjerpbakk / AsyncMethodCaller.cs
Last active December 11, 2015 13:08
C# classes for calling methods asynchronously and continue with with other methods after execution completes. Very useful in View Models.
/// <summary>
/// Used to call methods asynchronously and continue with with other methods
/// after execution completes. Very useful in View Models.
/// </summary>
public class AsyncMethodCaller : IAsyncMethodCaller
{
/// <summary>
/// The final <see cref="Task"/> to be executed, can be awaited.
/// </summary>
protected Task CurrentTask;
@hjerpbakk
hjerpbakk / Open parent folder.applescript
Created November 19, 2012 18:15
Opens the parent folder of the front Finder window
on run {input, parameters}
tell application "Finder"
tell front Finder window to set target to parent of target
end tell
return input
end run
@hjerpbakk
hjerpbakk / Kohesjon.java
Created October 15, 2012 14:42
Dersom man har for mye kobling og for lite kohesjon...
/*
* Created on 22.apr.2005
*/
package sys;
import nett.*;
/**
* @author Uno, hjerpbak
*/
@hjerpbakk
hjerpbakk / remove duplicates.sh
Created October 8, 2012 20:38
Remove duplicated entries for same application in Finder context menu
/System/Library/Frameworks/CoreServices.framework//Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain user
#!/usr/bin/python
import smtplib
import string
def send_email(to_address, subject, body):
from_address = ''
username = from_address
password = ''
email = string.join((
for f in "$@"
do
if [ ${f: -4} == ".svg" -o ${f: -4} == ".SVG" ]
then
python /Applications/Utilities/scour/scour.py --enable-comment-stripping --create-groups --enable-id-stripping --shorten-ids --set-precision=5 --quiet --indent=none -i "$f" -o "$f 2"
mv "$f 2" "$f"
fi
done
@hjerpbakk
hjerpbakk / WiX remove old product.xml
Created August 19, 2012 11:37
WiX remove old installed product
<InstallExecuteSequence>
<RemoveExistingProducts After="InstallFinalize"></RemoveExistingProducts>
</InstallExecuteSequence>