Skip to content

Instantly share code, notes, and snippets.

View litodam's full-sized avatar

Pablo "Lito" Damiani litodam

  • SOUTHWORKS
  • Buenos Aires, Argentina
  • X @litodam
View GitHub Profile
@litodam
litodam / HtmlHelper.cs
Created December 14, 2012 20:39
HTML Helper to Sanitize html strings
namespace Helpers
{
using System;
using System.Text.RegularExpressions;
public class HtmlHelper
{
private static Regex tags = new Regex("<[^>]*(>|$)", RegexOptions.Singleline | RegexOptions.ExplicitCapture | RegexOptions.Compiled);
private static Regex whitelist = new Regex(
@litodam
litodam / getSqlDbSize.sql
Created September 14, 2012 19:36
Get SQL DB Size in MB
SELECT SUM(reserved_page_count) * 8.0 / 1024 AS MB
FROM sys.dm_db_partition_stats
@litodam
litodam / .gitignore
Created August 7, 2012 19:45
My .gitignore file
# git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
*.o
*.sdf
*.lo
*.la
@litodam
litodam / QueryStats.sql
Created July 16, 2012 21:38
Retrieve "Query" Stats in SQL Server
-- select * from sys.dm_exec_query_stats
SELECT QS.execution_count,
SUBSTRING(QT.TEXT, QS.statement_start_offset/2 + 1,
(CASE WHEN QS.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.TEXT)) * 2
ELSE QS.statement_end_offset END - qs.statement_start_offset)/2) AS query_text,
QS.total_elapsed_time, QS.last_elapsed_time, QS.min_elapsed_time, QS.max_elapsed_time,
QS.total_rows, QS.last_rows, QS.min_rows, QS.max_rows,
QS.total_worker_time / QS.execution_count AS avg_cpu_time
FROM sys.dm_exec_query_stats AS QS
@litodam
litodam / mklink.cmd
Created July 16, 2012 21:37
Create a symbolic link
@litodam
litodam / EnableNuGetPackageRestore.txt
Created July 16, 2012 21:35
Enable NuGetPackageRestore (force consent) within the NuGet.targets file
<!-- Add the following line inside the Target Name='CheckPrerequisites' of the NuGet.targets -->
<SetEnvironmentVariable EnvKey="EnableNuGetPackageRestore" EnvValue="true" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
@litodam
litodam / SetupIIS.cmd
Created July 16, 2012 21:31
Easily setup an IIS Site (end to end: Build proj, setup IIS and AppPool, grant SQL permissions)
@ECHO OFF
setlocal
cd /D %~dp0
SET WebSiteProjectFilePath=%1
SET WebSiteProdPath=C:\inetpub\%2
SET IISAppPool=%2
SET IISBinding=%3
SET IISSiteName=%4
SET SqlServer=%5
@litodam
litodam / setIISExpressSSLPort.cmd
Created July 16, 2012 21:30
Configuring IIS Express site with a specific port for SSL binding
@echo off
setlocal
CD /d "%~dp0"
SET SiteName=%1
SET WebSitePath=%2
SET SSLPort=%3
"%ProgramFiles%\IIS Express\appcmd" add site /name:"%SiteName%" /physicalPath:"%WebSitePath%" /bindings:https/*:%SSLPort%:localhost
@litodam
litodam / runGitCommandRecursively.cmd
Created July 16, 2012 21:26
run git commands for all the repos
@echo off
REM Replace 'git pull –all' with your desired command and run this in the folder where you have all the TK repositories located.
for /f "delims=" %%d in ('dir /ad/b') do if exist %%d\.git (
cd %%d
git pull --all
cd..
)
pause
@litodam
litodam / cookiesHelper.js
Last active March 19, 2021 23:38
Cookies Helper in Javascript
function CookiesHelper() {}
// usage
// CookiesHelper.createCookie("myCookieUniqueName", value, 30);
// CookiesHelper.createCookie("myJsonCookieUniqueName", json, 30);
CookiesHelper.createCookie = function(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();