Skip to content

Instantly share code, notes, and snippets.

View MichalGrzegorzak's full-sized avatar

Michal Grzegorzak MichalGrzegorzak

  • UK
View GitHub Profile
@johnathan-sewell
johnathan-sewell / Simple System.Net.WebRequest.cs
Created December 13, 2010 14:37
HttpWebRequest - read page into string
public static string GetPageAsString(Uri address)
{
var result = "";
var request = WebRequest.Create(address) as HttpWebRequest;
using (var response = request.GetResponse() as HttpWebResponse)
{
var reader = new StreamReader(response.GetResponseStream());
result = reader.ReadToEnd();
@johnathan-sewell
johnathan-sewell / TestModule.cs
Created December 15, 2010 07:30
HttpModule for EPiServer
public class TestModule: IHttpModule
{
public void Init(HttpApplication context)
{
DataFactory.Instance.LoadingPage += LoadingPage;
}
public void LoadingPage(object sender, PageEventArgs e)
{
}
@johnathan-sewell
johnathan-sewell / Paragraph.hbm.xml
Created December 16, 2010 13:24
Basic NHibernate Mapping File
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true">
<class name="My.Application.Paragraph, My.Application" lazy="false">
<id name="Id" access="field" column="Id" >
<generator class="identity" />
</id>
<property name="Text" access="field" column="Text"/>
<property name="DateCreated" access="field" column="DateCreated"/>
</class>
</hibernate-mapping>
@johnathan-sewell
johnathan-sewell / VirtualPathProviderExtensions.cs
Created January 13, 2011 22:03
Enables you to use relative paths with EPiServer VirtualPathVersioningProvider
using System;
using System.Collections.Specialized;
using System.IO;
using System.Web.Hosting;
namespace EPiServer.Extensions
{
internal static class VirtualPathProviderExtensions
{
public static NameValueCollection FixPhysicalPath(this NameValueCollection configParameters)
@johnathan-sewell
johnathan-sewell / table-space.sql
Created March 28, 2011 11:22
Find out how much space each table in a SQL Server database is using
EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"
@Munawwar
Munawwar / ExcelDataReader.cs
Last active January 14, 2020 12:19
C# - Excel Data Reader Library - Convert Excel (XLSX or XLS) to CSV
/*
* Dependency : Excel Data Reader from http://exceldatareader.codeplex.com/
* You must add the references to the Dlls (downloaded from the link above) with Visual Studio.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel;
@johnathan-sewell
johnathan-sewell / ClearPersistentCookies.cs
Created June 2, 2011 09:33
Clear persistent login tickets in ASP.NET
private void ClearAnyPersistentCookies() {
var cookie = Request.Cookies.Get(FormsAuthentication.FormsCookieName);
if (cookie == null) return;
var ticket = FormsAuthentication.Decrypt(cookie.Value);
if (ticket == null) return;
if (ticket.IsPersistent)
FormsAuthentication.SignOut();
}
@slovely
slovely / Enumeration.cs
Created July 11, 2011 17:47
Type-safe Enumerations in c#
public class MyType : Enumeration
{
//don't allow type to be constructed
private MyType(int value, string displayName) : base(value, displayName) { }
public static readonly MyType Type1 = new MyType(1, "Type One");
public static readonly MyType Type2 = new MyType(2, "Type Two");
public static readonly MyType DerivedType3 = new DerivedMyType(3, "Type Three");
public virtual int GetSomethingAboutThisType()
@johnathan-sewell
johnathan-sewell / wordpress tag lists.php
Created July 25, 2011 21:38
Wordpress tag cloud as multiple HTML lists
<?php
$mytags = get_tags() ;
if ($mytags) {
echo '<ul>';
for ($x = 0; $x <= count($mytags); $x++) {
if (($x > 0) && ($x % 3 == 0)) echo '</ul><ul>';
echo '<li>';
echo '<a href="' . get_tag_link($mytags[$x]->term_id) . '">' . $mytags[$x]->name . '</a>';
echo '</li>';
}
@johnathan-sewell
johnathan-sewell / hibernate.cfg.xml
Created July 28, 2011 21:30
Bare bones NHibernate configuration for Lexikon app
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string_name">db</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>