Click here to Skip to main content
15,168,695 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: RA8875 has ridiculous registers Pin
Fueled By Decaff16-Nov-21 5:18
MemberFueled By Decaff16-Nov-21 5:18 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 5:19
mvahoney the codewitch16-Nov-21 5:19 
GeneralRe: RA8875 has ridiculous registers Pin
Fueled By Decaff16-Nov-21 5:48
MemberFueled By Decaff16-Nov-21 5:48 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 6:07
mvahoney the codewitch16-Nov-21 6:07 
GeneralRe: RA8875 has ridiculous registers Pin
Peter Adam25-Nov-21 21:51
professionalPeter Adam25-Nov-21 21:51 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch25-Nov-21 23:19
mvahoney the codewitch25-Nov-21 23:19 
GeneralRe: RA8875 has ridiculous registers Pin
honey the codewitch16-Nov-21 7:30
mvahoney the codewitch16-Nov-21 7:30 
GeneralCode to determine whether the passed in string is a C style comment block - in T-SQL Pin
honey the codewitch8-Nov-21 16:11
mvahoney the codewitch8-Nov-21 16:11 
In my defense this code was generated by a tool. It's still some of the weirdest code to do string ops in SQL I've seen. Part of it is due to the fact that it converts everything to UTF32 as it goes, even though in this routine it really doesn't need to.

SQL
-- Matches the block end for CommentBlock
DROP PROCEDURE [dbo].[SqlCompiledChecker_IsCommentBlockBlockEnd]
GO
CREATE PROCEDURE [dbo].[SqlCompiledChecker_IsCommentBlockBlockEnd] @value NVARCHAR(MAX), @index INT, @ch INT
AS
BEGIN
    DECLARE @adv INT
    DECLARE @matched INT
    DECLARE @valueEnd INT = DATALENGTH(@value)/2+1
    DECLARE @tch BIGINT
    DECLARE @accept INT = -1
    DECLARE @result INT = 0
    WHILE @ch <> -1
    BEGIN
        SET @matched = 0
    -- q0
        IF @ch = 42
        BEGIN
            
            SET @index = @index + 1
            SET @adv = 1
            IF @index < @valueEnd
            BEGIN
            	SET @ch = UNICODE(SUBSTRING(@value, @index, 1))
            	SET @tch = @ch - 0xd800
            	IF @tch < 0 SET @tch = @tch + 2147483648
            	IF @tch < 2048
            	BEGIN
            		SET @ch = @ch * 1024
            		SET @index = @index + 1
            		SET @adv = 2
            		IF @index >= @valueEnd RETURN -1
            		SET @ch = @ch + UNICODE(SUBSTRING(@value, @index, 1)) - 0x35fdc00
            	END
            END
            ELSE
            BEGIN
            	SET @ch = -1
            END
            SET @matched = 1
            GOTO q1
        END -- IF {range match}
        GOTO next
    q1:
        IF @ch = 47
        BEGIN
            
            SET @index = @index + 1
            SET @adv = 1
            IF @index < @valueEnd
            BEGIN
            	SET @ch = UNICODE(SUBSTRING(@value, @index, 1))
            	SET @tch = @ch - 0xd800
            	IF @tch < 0 SET @tch = @tch + 2147483648
            	IF @tch < 2048
            	BEGIN
            		SET @ch = @ch * 1024
            		SET @index = @index + 1
            		SET @adv = 2
            		IF @index >= @valueEnd RETURN -1
            		SET @ch = @ch + UNICODE(SUBSTRING(@value, @index, 1)) - 0x35fdc00
            	END
            END
            ELSE
            BEGIN
            	SET @ch = -1
            END
            SET @matched = 1
            GOTO q2
        END -- IF {range match}
        GOTO next
    q2:
        RETURN CASE @ch WHEN -1 THEN 1 ELSE 0 END
    next:
        IF @matched = 0
        BEGIN
            SET @index = @index + 1
            SET @adv = 1
            IF @index < @valueEnd
            BEGIN
            	SET @ch = UNICODE(SUBSTRING(@value, @index, 1))
            	SET @tch = @ch - 0xd800
            	IF @tch < 0 SET @tch = @tch + 2147483648
            	IF @tch < 2048
            	BEGIN
            		SET @ch = @ch * 1024
            		SET @index = @index + 1
            		SET @adv = 2
            		IF @index >= @valueEnd RETURN -1
            		SET @ch = @ch + UNICODE(SUBSTRING(@value, @index, 1)) - 0x35fdc00
            	END
            END
            ELSE
            BEGIN
            	SET @ch = -1
            END
        END -- IF not matched
    END -- WHILE input loop
    RETURN 0
END -- CREATE PROCEDURE
GO
DROP PROCEDURE [dbo].[SqlCompiledChecker_IsCommentBlock]
GO
-- <summary>Indicates whether the <paramref name="text"/> matches the expression indicated by CommentBlock</summary>
-- <param name="text">The text to validate</param>
-- <returns>True if the entire contents match the expression, otherwise false</returns>
CREATE PROCEDURE [dbo].[SqlCompiledChecker_IsCommentBlock] @value NVARCHAR(MAX)
AS
BEGIN
    DECLARE @adv INT
    DECLARE @ch BIGINT
    DECLARE @tch BIGINT
    DECLARE @index INT = 0
    DECLARE @valueEnd INT = DATALENGTH(@value)/2+1
    DECLARE @result INT
    
    SET @index = @index + 1
    SET @adv = 1
    IF @index < @valueEnd
    BEGIN
    	SET @ch = UNICODE(SUBSTRING(@value, @index, 1))
    	SET @tch = @ch - 0xd800
    	IF @tch < 0 SET @tch = @tch + 2147483648
    	IF @tch < 2048
    	BEGIN
    		SET @ch = @ch * 1024
    		SET @index = @index + 1
    		SET @adv = 2
    		IF @index >= @valueEnd RETURN -1
    		SET @ch = @ch + UNICODE(SUBSTRING(@value, @index, 1)) - 0x35fdc00
    	END
    END
    ELSE
    BEGIN
    	SET @ch = -1
    END
    WHILE @ch <> -1
    BEGIN
    -- q0
        IF @ch = 47
        BEGIN
            
            SET @index = @index + 1
            SET @adv = 1
            IF @index < @valueEnd
            BEGIN
            	SET @ch = UNICODE(SUBSTRING(@value, @index, 1))
            	SET @tch = @ch - 0xd800
            	IF @tch < 0 SET @tch = @tch + 2147483648
            	IF @tch < 2048
            	BEGIN
            		SET @ch = @ch * 1024
            		SET @index = @index + 1
            		SET @adv = 2
            		IF @index >= @valueEnd RETURN -1
            		SET @ch = @ch + UNICODE(SUBSTRING(@value, @index, 1)) - 0x35fdc00
            	END
            END
            ELSE
            BEGIN
            	SET @ch = -1
            END
            GOTO q1
        END -- IF {range match}
        RETURN 0
    q1:
        IF @ch = 42
        BEGIN
            
            SET @index = @index + 1
            SET @adv = 1
            IF @index < @valueEnd
            BEGIN
            	SET @ch = UNICODE(SUBSTRING(@value, @index, 1))
            	SET @tch = @ch - 0xd800
            	IF @tch < 0 SET @tch = @tch + 2147483648
            	IF @tch < 2048
            	BEGIN
            		SET @ch = @ch * 1024
            		SET @index = @index + 1
            		SET @adv = 2
            		IF @index >= @valueEnd RETURN -1
            		SET @ch = @ch + UNICODE(SUBSTRING(@value, @index, 1)) - 0x35fdc00
            	END
            END
            ELSE
            BEGIN
            	SET @ch = -1
            END
            GOTO q2
        END -- IF {range match}
        RETURN 0
    q2:
        EXEC @result = SqlCompiledChecker_IsCommentBlockBlockEnd @value, @index, @ch
        RETURN @result
    END -- WHILE input loop
    RETURN 0
END -- CREATE PROCEDURE
GO

Real programmers use butterflies

GeneralRe: Code to determine whether the passed in string is a C style comment block - in T-SQL Pin
Jörgen Andersson8-Nov-21 23:36
professionalJörgen Andersson8-Nov-21 23:36 
GeneralRe: Code to determine whether the passed in string is a C style comment block - in T-SQL Pin
honey the codewitch9-Nov-21 2:46
mvahoney the codewitch9-Nov-21 2:46 
GeneralRe: Code to determine whether the passed in string is a C style comment block - in T-SQL Pin
Maximilien9-Nov-21 2:07
MemberMaximilien9-Nov-21 2:07 
GeneralRe: Code to determine whether the passed in string is a C style comment block - in T-SQL Pin
Brisingr Aerowing9-Nov-21 13:53
professionalBrisingr Aerowing9-Nov-21 13:53 
GeneralRe: Code to determine whether the passed in string is a C style comment block - in T-SQL Pin
James Curran26-Nov-21 7:21
MemberJames Curran26-Nov-21 7:21 
GeneralRe: Code to determine whether the passed in string is a C style comment block - in T-SQL Pin
honey the codewitch26-Nov-21 8:38
mvahoney the codewitch26-Nov-21 8:38 
GeneralCursed Project: WasmWinforms Pin
Brisingr Aerowing8-Nov-21 15:44
professionalBrisingr Aerowing8-Nov-21 15:44 
GeneralRe: Cursed Project: WasmWinforms Pin
Gary R. Wheeler22-Nov-21 14:53
MemberGary R. Wheeler22-Nov-21 14:53 
GeneralRe: Cursed Project: WasmWinforms Pin
den2k8822-Nov-21 22:46
professionalden2k8822-Nov-21 22:46 
GeneralRe: Cursed Project: WasmWinforms Pin
Eddy Vluggen23-Nov-21 14:52
professionalEddy Vluggen23-Nov-21 14:52 
GeneralOdd Behavior With gethostbyname Pin
Rick York4-Oct-21 20:57
mveRick York4-Oct-21 20:57 
GeneralRe: Odd Behavior With gethostbyname Pin
Peter_in_27804-Oct-21 21:08
professionalPeter_in_27804-Oct-21 21:08 
GeneralRe: Odd Behavior With gethostbyname Pin
YahiaEQ5-Oct-21 22:12
MemberYahiaEQ5-Oct-21 22:12 
GeneralReversing a logical ( OR ) Pin
albert_redditt2-Sep-21 12:31
Memberalbert_redditt2-Sep-21 12:31 
GeneralRe: Reversing a logical ( OR ) Pin
PIEBALDconsult2-Sep-21 13:13
professionalPIEBALDconsult2-Sep-21 13:13 
GeneralRe: Reversing a logical ( OR ) Pin
Jon McKee2-Sep-21 14:11
professionalJon McKee2-Sep-21 14:11 
GeneralRe: Reversing a logical ( OR ) Pin
Matias Lopez18-Oct-21 12:11
MemberMatias Lopez18-Oct-21 12:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.