Skip to content

Instantly share code, notes, and snippets.

View tormodfj's full-sized avatar
💡
Inventing code

Tormod Fjeldskår tormodfj

💡
Inventing code
View GitHub Profile
@tormodfj
tormodfj / gist:464380
Created July 5, 2010 14:08
Calculate Roman numerals with F#
module RomanNumerals
// Define function
let convertToRoman n =
let steps = [
(1, 3, "I")
(4, 4, "IV")
(5, 8, "V")
(9, 9, "IX")
@tormodfj
tormodfj / gist:493845
Created July 28, 2010 09:19
Creates a sorted merge between an arbitrary amount of sorted sequences.
public static IEnumerable<T> SortMerge<T, TKey>(Func<T, TKey> orderBy, params IEnumerable<T>[] sortedEnumerables)
{
var enumerators = sortedEnumerables
.Select(e => e.GetEnumerator())
.Where(e => e.MoveNext())
.ToList();
while (enumerators.Any())
{
var next = enumerators
@tormodfj
tormodfj / gist:1075744
Created July 11, 2011 12:27
Binding log4net's ILog using Ninject
Bind<ILog>().ToMethod(context => LogManager.GetLogger(context.Request.Target.Member.DeclaringType));
@tormodfj
tormodfj / gist:2835130
Created May 30, 2012 09:39
Configuring Git with P4Merge
git config --global merge.tool p4merge
git config --global mergetool.p4merge.cmd 'p4merge.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'
git config --global diff.tool p4merge
git config --global difftool.p4merge.cmd 'p4merge.exe \"$LOCAL\" \"$REMOTE\"'
@tormodfj
tormodfj / gist:2864327
Created June 3, 2012 17:38
Setting up LAME in EAC
-V2 --add-id3v2 --pad-id3v2 --ta "%artist%" --tt "%title%" --tg "%genre%" --tl "%albumtitle%" --ty "%year%" --tn "%tracknr2%" %source% %dest%
@tormodfj
tormodfj / gist:3525505
Created August 30, 2012 10:13
P/Invoke for hiding the Close button of a WPF Window
internal static class Win32
{
private const int GWL_STYLE = -16;
private const int WS_SYSMENU = 0x80000;
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\15.0\Lync]
"DisableServerCheck"=dword:00000001
@tormodfj
tormodfj / gist:4123585
Created November 21, 2012 07:27
WS_EX_COMPOSITED in Windows Forms
protected override CreateParams CreateParams
{
get
{
var @params = base.CreateParams;
// WS_EX_COMPOSITED (0x02000000L)
// Paints all descendants of a window in bottom-to-top painting order using double-buffering.
// Ref.: http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543.aspx
@params.ExStyle |= 0x02000000;
@tormodfj
tormodfj / #1 - Exceptions.tt
Last active June 24, 2016 18:26
Using T4 to make redundant code more maintainable
<#@ template language="C#" #>
<#@ output extension=".cs" #>
<#
var exceptions = new []
{
DefineException("Message"),
DefineException("BadResponse").DerivedFrom("Message"),
DefineException("InvalidState")
};
//----------------------------------------------------------------------------------
function Convert-Currency {
param($from = "eur", $to = "nok")
$url = "https://www.google.com/finance/converter?a=1&from=$from&to=$to"
$result = Invoke-WebRequest $url
$result.AllElements | Where id -eq 'currency_converter_result' | Select -ExpandProperty innerText
}