2015-05-11

MacOS - Show hidden files or hide them

defaults write com.apple.finder AppleShowAllFiles YES

defaults write com.apple.finder AppleShowAllFiles NO


2015-05-05

JavaScript - Return all addend combinations of a target value, from an array

Use this library (single .js file)... 
https://github.com/falconerandloillc/addends


(1) Run this...

console.log( getAddends( 12, [-2.3,-1,1,2.3,2.4] ) );



(2) Returns (to the browser's console):

Object
array: Array[10]
   0: -2.3
   1: -1
   2: 1
   3: 2.3
   4: 2.4
   length: 5
combinations: Array[3]
   0: "1,2,3,6"
   1: "1,2,4,5"
   2: "1,2,9"
   length: 3
dataType: "integer"
iterations: 66
precision: 2
target: 12
time: 3


Sublime Text Editor - Turn double spaces into single space (carriage returns)

(1) Find: ^\n

(2) Replace With: Nothing (leave this field/option blank)


2015-04-11

TSQL - Get dayID, a date in the format YYYYMMDD

/*

       -- Execution
       select dbo.getDayID( '1/31/2012' );
       select dbo.getDayID( cast('1/31/2012' as date) );


*/
ALTER function [dbo].[getDayID](
       @PeriodDate date
)
returns bigint
as
begin

       return(
              ( year( @PeriodDate ) * 10000 )
              + ( month( @PeriodDate ) * 100 )
              + day(@PeriodDate)
       );

end
;


TSQL - Get the lower of two given integer numbers

/*


       -- Execution
       select dbo.getLowestInt( '201201', '201112' );
       select dbo.getLowestInt( '201201', null );
       select dbo.getLowestInt( null, '201201' );
       select dbo.getLowestInt( null, null );




*/
ALTER function [dbo].[getLowestInt](
       @date1 int
       , @date2 int
)
returns int
as
begin
       return(
              case
                     when isnull(@date1,0) <= isnull(@date2,0)
                     then @date1
                     else @date2
              end
       );
end
;



TSQL - Get the earlier of two given dates

/*


       -- Execution
       select dbo.getLowestDate( '1/31/2012', '8/30/2012' );
       select dbo.getLowestDate( '1/31/2012', null );
       select dbo.getLowestDate( null, '8/30/2012' );
       select dbo.getLowestDate( null, null );




*/
ALTER function [dbo].[getLowestDate](
       @date1 date
       , @date2 date
)
returns date
as
begin
       return(
              case when isnull(@date1,'12/31/2099') <= isnull(@date2,'12/31/2099') then @date1 else @date2 end
       );
end
;




TSQL - Get the greater of two given integer numbers

/*

       -- Execution
       select dbo.getGreatestInt( '201201', '201112' );
       select dbo.getGreatestInt( '201201', null );
       select dbo.getGreatestInt( null, '201201' );
       select dbo.getGreatestInt( null, null );


*/
ALTER function [dbo].[getGreatestInt](
       @date1 int
       , @date2 int
)
returns int
as
begin
       return(
              case
                     when isnull(@date1,0) >= isnull(@date2,0)
                     then @date1
                     else @date2
              end
       );
end
;