Skip to content

Instantly share code, notes, and snippets.

@terjetyl
terjetyl / HttpPostedFileBaseExtensions.cs
Created January 14, 2012 21:45
Extension method for creating a byte array from a HttpPostedFileBase
public static class HttpPostedFileBaseExtensions
{
public static Byte[] ToByteArray(this HttpPostedFileBase value)
{
if (value == null)
return null;
var array = new Byte[value.ContentLength];
value.InputStream.Position = 0;
value.InputStream.Read(array, 0, value.ContentLength);
@terjetyl
terjetyl / Global.asax.cs
Created January 15, 2012 16:59
Route webforms aspx url to mvc route
routes.MapRoute(
"",
"bilopphuggere/biler.aspx/{param}",
new { controller = "Huggere", action = "BilerRedirect", param = UrlParameter.Optional }
);
@terjetyl
terjetyl / AppConfig.Transformation.targets
Created January 15, 2012 17:55 — forked from jmangelo/AppConfig.Transformation.targets
VS 2010 RTM - MSBuild Project file for App.config XML transformations.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- 20110224 : Ryan Milligan : Created OverrideAppConfigWithTargetPath target to fix ClickOnce deploy bug -->
<!-- 20100827 : João Angelo : Fixed bug when using Publish command within Visual Studio -->
<PropertyGroup>
<!-- Prevent circular dependency on Build target -->
<PipelineDependsOnBuild>false</PipelineDependsOnBuild>
<!-- Override project config file name (By default is set to Web.config) -->
<ProjectConfigFileName>App.Config</ProjectConfigFileName>
</PropertyGroup>
@terjetyl
terjetyl / HomeController.cs
Created January 15, 2012 21:52
Make dll downloadable
public FileStreamResult Download()
{
var fullQualifiedPathToDll = Path.Combine(Server.MapPath("~/"), "bin/ImageResizer.dll");
var fileInfo = new FileInfo(fullQualifiedPathToDll);
var myFileStream = new FileStream(fullQualifiedPathToDll, FileMode.Open);
return File(myFileStream, "application/octet-stream", fileInfo.Name);
}
@terjetyl
terjetyl / QueryStringHelper.cs
Created January 28, 2012 19:02
QueryString helper class
/// <summary>
/// A chainable query string helper class.
/// Example usage :
/// string strQuery = QueryString.Current.Add("id", "179").ToString();
/// string strQuery = new QueryString().Add("id", "179").ToString();
/// </summary>
public class QueryString : NameValueCollection
{
public QueryString()
{
@terjetyl
terjetyl / gist:2029188
Created March 13, 2012 14:42
Get executing assembly path
static public string AssemblyLoadDirectory
{
get
{
string codeBase = Assembly.GetCallingAssembly().CodeBase;
var uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
#r @"\\psf\Home\Desktop\GitHub\eulersfsharp\src\Euler\bin\Debug\FSharp.Data.dll"
#r @"\\psf\Home\Desktop\GitHub\eulersfsharp\src\packages\MSDN.FSharpChart.dll.0.60\lib\MSDN.FSharpChart.dll"
#r "System.Windows.Forms.DataVisualization.dll"
open FSharp.Data
open MSDN.FSharp.Charting
open System.Windows.Forms
open System.Drawing
open System.Windows.Forms.DataVisualization.Charting
#r "../packages/HtmlAgilityPack.1.4.6/lib/Net45/HtmlAgilityPack.dll"
#r "../packages/FSharp.Data.1.1.10/lib/net40/FSharp.Data.dll"
#load "HtmlAgilityPack.FSharp.fs"
open System
open System.Linq
open System.Net
open System.Text.RegularExpressions
open FSharp.Net
@terjetyl
terjetyl / OcrFileParser.fs
Created April 18, 2014 11:39
Parse OCR files from nets.no
namespace NetsOcrParser
module OcrFileParser =
open System
open System.IO
open System.Globalization
type StartRecordForsendelse =
{ FormatKode : string; TjenesteKode : string; ForsendelsesType : string; RecordType : string; DataAvsender : string; ForsendelsesNummer : string; DataMottaker : string; Filler : string; }
open System
open System.IO
type File =
{ Size: Int64; Name: String; Path: String; }
member x.IsLargerThan minSize = x.Size > minSize
type DuplicateFile =
{ Size: Int64; Name: String; Paths: String list; }