Skip to content

Instantly share code, notes, and snippets.

@q42jaap
q42jaap / gist:3905150
Created October 17, 2012 11:56
Login corrupted after database backup restore from different server
USE dbname;
SELECT s.name
FROM sys.schemas s
WHERE s.principal_id = USER_ID('username');
ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;
-- from http://blog.sqlauthority.com/2011/12/26/sql-server-fix-error-15138-the-database-principal-owns-a-schema-in-the-database-and-cannot-be-dropped/
@q42jaap
q42jaap / gist:2936304
Created June 15, 2012 12:45
GetGenericArgumentsForBaseType
static Type[] GetGenericArgumentsForBaseType(Type givenType, Type genericType)
{
if (genericType.IsInterface)
{
var interfaceTypes = givenType.GetInterfaces();
foreach (var it in interfaceTypes)
{
if (it.IsGenericType && it.GetGenericTypeDefinition() == genericType)
return it.GetGenericArguments();
}
@q42jaap
q42jaap / gist:2930885
Created June 14, 2012 15:05
Find dependencies in csproj files by name with find and grep
find -iname "*.csproj" -exec grep -n "MyCompany.Assembly" /dev/null {} \;
@q42jaap
q42jaap / HtmlTruncator.cs
Created April 18, 2012 13:36
HtmlTruncator
public static class HtmlTruncator
{
public static string LimitOnWordBoundary(string str, int maxLength, string ellipses = "...")
{
XmlDocument doc = new XmlDocument();
XmlParserContext context = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), null, XmlSpace.Preserve);
XmlTextReader reader = new XmlTextReader("<xml>" + str + "</xml>", XmlNodeType.Document, context);
bool shouldWriteEllipses;