2019-07-03

TSQL - Try and catch and raise error


-- Declarations
declare @error_message nvarchar(2000);
set @error_message = null;
declare @error_severity nvarchar(2000);
set @error_severity = null;
declare @error_state nvarchar(2000);
set @error_state = null;
declare @error_number int;
set @error_number = null;


-- Try
BEGIN TRY 
       -- Do something here
END TRY 


-- Catch
BEGIN CATCH 

       -- Available error variables
       /*SELECT
              ERROR_NUMBER() 
              , ERROR_SEVERITY() 
              , ERROR_STATE() 
              , ERROR_PROCEDURE() 
              , ERROR_LINE() 
              , ERROR_MESSAGE() 
       ; */

       -- Error number
       set @error_number = ERROR_NUMBER();                   

       -- Capture the error message, severity and state
       set @error_message = ERROR_MESSAGE();
       set @error_severity = ERROR_SEVERITY();
       set @error_state = ERROR_STATE();

       -- Debug
       print 'ERROR CAUGHT -> ' + @error_message;

       -- Raise error, so the job that will call this procedure launches a notification
       RAISERROR (
                     @error_message, -- Message text. 
                     @error_severity, -- Severity. 
                     @error_state -- State. 
              );

END CATCH



2019-07-02

TSQL - Pass the result of executed dynamic SQL to a variable

DECLARE @sql nvarchar(max);
declare @result int;
SET @sql = 'SELECT @x = COUNT(*) FROM SCHEMA_NAME.TABLE_NAME;';
EXECUTE sp_executesql @sql, N'@cnt int OUTPUT', @x=@result OUTPUT;
print @result;

2019-06-30

JavaScript - jQuery Filter

// Array of json objects
let json_array = [
{
"item_name": "United States"
, "item_property": "123"
},
{
"item_name": "United Arab Emirates"
, "item_property": "123"
},
{
"item_name": "Mexico"
, "item_property": "234"
}
];

// Filter
$(json_array).filter(function (index, value){
        return value.item_property === '123';
    });

JavaScript - jQuery Grep

// Arry of json objects
let json = [
{
"item_name": "United States"
, "item_property": "123"
},
{
"item_name": "United Arab Emirates"
, "item_property": "123"
},
{
"item_name": "Mexico"
, "item_property": "234"
}
];

// Grep to filter
$.grep( 
json
, function( item, index ) {
return item.item_property === '123';
}
);


2019-06-11

SCSS - Iconic Bootstrap implementation sampler

<span
    class="

        {{! Required class}}
        iconic

        {{! Icon name}}
        iconic-brush

        {{!3 versions for each, scaled depending on size}}
        iconic-sm {{!iconic-md}}{{!iconic-lg}}

        {{! Size }}
        iconic-size-sm {{!iconic-size-lg}}

        {{! Flip }}
        iconic-flip-horizontal-vertical {{!iconic-flip-horizontal}}{{!iconic-flip-vertical}}
       
        {{! Ignore the text in the span, if any }}
        iconic-text-replace
    "

    title="brush"

    aria-hidden="true"

>This text will be ignored</span>


PS. SCSS/SSAS.

SCSS - Basic inheritance example

.parent{
  background-color: red;
}
.child {
  @extend .parent;
}

MacOS - Terminal command history search

history | grep SEARCH_TERM_HERE