Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / 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: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:3905824
Created October 17, 2012 14:30
Shrink database
DBCC SHRINKDATABASE (UserDB, 10);
GO
@q42jaap
q42jaap / gist:3922846
Created October 20, 2012 10:08
Run CMS as NETWORK SERVICE
PsExec.exe -i -u "NT AUTHORITY\NETWORK SERVICE" cmd.exe
@q42jaap
q42jaap / create-index.sh
Created June 4, 2013 14:50
Reproduction of faceting of has_child query
#!/bin/sh
# assume the index products doesn't exist
# otherwise uncomment the following line
# curl -XDELETE localhost:9200/products
curl -XPUT localhost:9200/products/product/1 -d'{
"property1": "value1"
}'
@q42jaap
q42jaap / create-index.sh
Last active December 18, 2015 02:39
Reproduction of sorting on child property (Note that you need 0.90.1)
#!/bin/sh
# assume the index products doesn't exist
# otherwise uncomment the following line
# curl -XDELETE localhost:9200/products
curl -XPUT localhost:9200/products/product/1 -d'{
"property1": "value1"
}'
@q42jaap
q42jaap / index.js
Last active January 27, 2016 15:31
'use strict';
var i = 0;
console.log('starting app');
setInterval(function() {
i++;
console.log('simulate activity');
if (i > 5) {
doesNotExist = 0; // this will throw ReferenceError: doesNotExist is not defined
}
@q42jaap
q42jaap / JsonMacros.scala
Last active January 9, 2018 07:09
This Gist shows one way to create a macro that can read/write Json for a trait with implementations.
package util
import play.api.libs.json.Format
import util.macroimpl.MacrosImpl
import language.experimental.macros
object JsonMacros {
// We did not reuse \/ from scalaz, to avoid a dependency on scalaz in the macros module
trait \/[A, B]