Skip to content

Instantly share code, notes, and snippets.

@mamapi
mamapi / my-pattern.service.js
Created February 6, 2016 18:40
Angular service
(function () {
'use strict';
angular
.module('app.services')
.factory('myPatternService', myPatternService);
myPatternService.$inject = ['$http'];
@mamapi
mamapi / clariondate.sql
Created April 3, 2017 20:19 — forked from fushnisoft/clariondate.sql
Convert a Clarion Date (INT) to SQL DateTime
DECLARE @ClarionDate INT = 47563
DECLARE @SqlDateTime DATETIME
-- Convert the clarion DATE into and SQL DateTime
SET @SqlDateTime = DateAdd(day, @ClarionDate - 4, '1801-01-01')
SELECT @SqlDateTime AS 'SQL Date Time'
-- Now convert it back from and SQL DateTime to a Clarion Date
SET @ClarionDate = DateDiff(day, DateAdd(day, -4, '1801-01-01'), @SqlDateTime)
@mamapi
mamapi / RemoveDiacritics.ps1
Created May 16, 2017 10:14
Remove diacritics in PowerShell
function Remove-DiacriticChars {
param ([String]$srcString = [String]::Empty)
$normalized = $srcString.Normalize( [Text.NormalizationForm]::FormD )
$sb = new-object Text.StringBuilder
$normalized.ToCharArray() | % {
if( [Globalization.CharUnicodeInfo]::GetUnicodeCategory($_) -ne [Globalization.UnicodeCategory]::NonSpacingMark) {
[void]$sb.Append($_)
}
}
$sb.ToString()
@mamapi
mamapi / ServiceBrokerEmptyQueue.sql
Last active October 11, 2017 14:27
SQL script to clear empty a SQL Server Service Broker queue
declare @handle uniqueidentifier
while(1=1)
begin
select top 1 @handle = conversation_handle from queueName
if (@@ROWCOUNT = 0) break
end conversation @handle with cleanup
end
@mamapi
mamapi / SqlServerBrokerEnable.sql
Created October 11, 2017 09:44
Script to enable SQL Server Service Broker for specified database
USE master
SET NOEXEC OFF;
GO
:setvar DatabaseName "YourDatabaseName"
GO
:on error exit
GO
:setvar __IsSqlCmdEnabled "True"
GO
IF N'$(__IsSqlCmdEnabled)' NOT LIKE N'True'
@mamapi
mamapi / SqlGenarateRandom6DigitNumbers.sql
Last active October 26, 2017 08:17
SQL script to generating random 6 digit numers
select convert(varchar(12), convert(int, rand() * 1000000))
@mamapi
mamapi / ServiceBrokerCheckQueueEnable.sql
Created October 26, 2017 08:16
Script to check if queue (Service Broker) is enable or not
select is_receive_enabled
from sys.service_queues q inner join sys.schemas s on q.schema_id=s.schema_id
where q.name = N'queueName' and s.name='schemaName'
SELECT * FROM sys.dm_broker_activated_tasks
@mamapi
mamapi / SqlServerHistoryExecutionsCount.sql
Created November 21, 2017 15:32
SQL script to find number of rows in job history
SELECT j.name, COUNT(1) as Executions
FROM msdb.dbo.sysjobs j INNER JOIN msdb.dbo.sysjobhistory h ON j.job_id = h.job_id
GROUP BY j.name
ORDER BY Executions DESC
@mamapi
mamapi / convert_int_to_array_of_digits.cs
Last active December 28, 2017 22:25
Converting integer into array of single digits
int inputNumber = 1234;
int[] result = inputNumber.ToString().Select(digit=> (int)Char.GetNumericValue(digit)).ToArray();