Monday, December 12, 2011

Change url and title with Javascript ShareThis

addthis.update('share''url', url);
addthis.update('share''title', $("title").text());

Friday, November 25, 2011

Kill all connections to a Microsoft SQL Server DB

-- Create the sql to kill the active database connections
declare @execSql varchar(1000), @databaseName varchar(100)
-- Set the database name for which to kill the connections
set @databaseName = ''

set @execSql = ''
select  @execSql = @execSql + 'kill ' + convert(char(10), spid) + ' '
from    master.dbo.sysprocesses
where   db_name(dbid) = @databaseName
     DBID <> 0
     spid <> @@spid


Wednesday, October 26, 2011

Change Upload limit web.config

To change the upload limit in web.config

<!-- maxRequestLength is in KB -->
<httpRuntime maxRequestLength="204800" executionTimeout="99999"/>

If the server is iis 7 or above, also put this:
<!-- maxAllowedContentLength is in Bytes! -->
<requestLimits maxAllowedContentLength="524288000"/>

Thursday, October 20, 2011

Thumbnails from Youtube

Para sacar ou apresentar um thumbnail (120x90) de um video do youtube

VIDEO_ID = Ao id do video de onde querem sacar o thumbnail
# = ao nº do thumbnail que o youtube gera, que vai do 1 ao 4, sendo que o youtube apresenta por default o 2. O thumbnail 0 (Zero) é a imagem em tamanho grande (480×360)


Reload AddThis Script Ajax

Quando se faz replace do html do AddThis, temos de fazer reload do script, aqui fica uma maneira de fazer (Precisa de jquery).

var script = '';
if (window.addthis){
    window.addthis = null;
$.getScript( script );


Add facebook tab to page

Maneira simples de adicionar uma facebook tab ou app a uma página do facebook
1) Ter o id da tab ou app
2) ir até e fazer replace do YOUR_APP_ID com o id da tab/app
3) fazer add to my page (algures no canto infeior esquerdo)

Wednesday, October 19, 2011

Validate Portuguese NIF

 private static bool IsValidNIF(string nif)
            if (string.IsNullOrWhiteSpace(nif) || !Regex.IsMatch(nif, "^[0-9]+$") || nif.Length != 9)
                return false;
            char c = nif[0];
            //Check first number is (5) apenas empresas
            //if (!c.Equals('5'))
            //    return false;
            //Perform CheckDigit calculations
            int checkDigit = (Convert.ToInt32(c.ToString()) * 9);
            for (int i = 2; i <= 8; i++)
                checkDigit += Convert.ToInt32(nif[i - 1].ToString()) * (10 - i);
            checkDigit = 11 - (checkDigit % 11);
            //if checkDigit is higher than ten set it to zero
            if (checkDigit >= 10)
                checkDigit = 0;
            //Compare checkDigit with the last number of NIF
            //If equal the NIF is Valid.
            if (checkDigit.ToString() != nif[8].ToString())
                return false;
            return true;

Inline cshtml Macro Umbraco

<umbraco:Macro ID="Macro1" runat="server" language="cshtml">

Monday, October 17, 2011

Thursday, October 13, 2011

Get image from Media in Umbraco Template

<img src="<umbraco:Item field='imagemCrop' runat='server' 
xsltDisableEscaping='true'></umbraco:Item>" />

Get image from media umbraco razor


Render Macro Umbraco example

@( Html.Raw(umbraco.library.RenderMacroContent("<?UMBRACO_MACRO macroAlias=\"share\" ></?UMBRACO_MACRO>", Model.Id)))

Friday, September 30, 2011

Crop Image ImageGen