Adam's Blog
Popular Posts
-
Rules of Coding The most important language you will ever code in: English (or the common spoken language used in your company). -- So...
-
Here is how to parse a date that is in the format of mm/dd/yyyy: // Parse string with date but no time component. string dateStr...
-
The object of copying code is to save time. However, I have discovered by sad and repeated experience that copying code more often than not...
-
This blog is to let you know how to use the SQL import wizard. It is very interesting. The most important thing to remember is that you ca...
-
Tonight I attended a conference hosted by The Church of Jesus Christ of Latter-day Saints. It's topic was the protection of the institu...
-
Here's how you create a CSV file that will open in Excel. It is a csv (Comma spaced Value) file with double quotes " as identifier...
Sunday, December 8, 2019
Revelations Sunday 8 December 2019
Adam, Adam, thou art perfect before me. Thou shalt not lose thy children nor shalt thou see the bars of prison, jail, or cell ever again. These words are true and faithful; therefore, be bold and not pretentious, but obedient to them. Do not contend with any man, neither judge nor layman, but speak the words which I shall put into your mouth in the moment thereof, and it shall be filled. Veril, verily I say into you, thou art like unto Nephi of old and I will be with thee forever. And I will save thy seed and establish all thy words even forever. Amen
Sunday, November 17, 2019
Revelations at church after escorting Geri to class
Dear Heavenly father, thank you for the impressions though hast given me this day.
I am grateful for Jesus Christ who died for me. Not the death of this world which is final and fruitless, but a death he knew would lead to new life. I am grateful that he suffered for me so much so that I could live. His death was not in vain his death was one he knew he could call back his life yet he knew he had to give up His precious life in this world and suffer all that this body can feel and go through the entire process of the shut down and lifelessness of a body that is my mortal and the rest of those in this world feel.
I am grateful for the soldiers who have given their lives and the other soldiers who carry the heavier burden of carrying on their memory and justifying in their minds and hearts the cause for which they died 💔.
Which reminds me of the weight. The weight we must carry in remembering the death of our Lord Jesus Christ.
Sunday, November 10, 2019
Sunday, November 10, 2019
Agency is the most beautiful part of the gospel of Jesus Christ. Because of it, as Joseph Smith said we are free. Parents of children want to take away agency when they know they will not make the right guy choice. But it is curious that the same parents who want to harbor their children from the burden of choosing wrong also are the ones who shy away and seek to protect their children from the effects of those choices. Heavenly Father knows we cannot become perfect unless we are free. His plan works because he dies not hide us from the effects of our choices, that is, unless and to the degree which we repent.
Saturday, November 9, 2019
Journal Saturday, November 9 2019
Last night I thought about how stable God is. He plants his promises in our hearts and watches them grow. As men, we foolishly think that God will not come through. We think he has forgotten about us. We think that the creator of heaven and Earth will somehow not able to come through on the things he has promised us. How foolish we are? God does not forget he does not sorrow or sleep he always keeps his word. Last night was really nice I had peace in my heart as I walked to my children's room. I looked out the window at the top of the stairs and saw a star. I knew that the man who put that star in the sky would surely keep his promises he made to me. Joey was very cute last night she made a train set that went through the small dollhouse. She got upset when Lily was playing with him and tried to change the layout of the track. But I told him he would have to take a bench if he could not play with Lily. He immediately improved.
We watched avengers and then Joey went up to his bed. I came upstairs and prayed for him that he would have all that he needs and that his life would be filled with love. I prayed for Lily for the special girl that she is and the light that I see in her heart that I would be able to Foster that light and help her grow. I prayed for Maylee for the wonderful girl that she is and that her dreams would come true and that the tooth fairy would visit her.
The tooth fairy did come last night. Jerry also called me last night as I was falling asleep. I knew it was late so I did not answer. Jerry was out with Brianne last night at the Irvine spectrum she and Jerry had a good time eating and being with friends. I just texted Jerry if she wanted to do lunch. She has not responded.
I am here on the temple grounds. After I drop the children off for their visit I thought I might go and get Jeff to to learn c programming some more. I also thought to go pick up breakfast and bring it to Jerry. But I knew that I am not allowed to go to Jerry's house. It is a good rule. As I drove home listening to general conference, I felt prompted to drive down the 55 freeway. I thought about learning to fly. I thought about going to my work. But then I thought I need to go to the temple and feast on the words of Christ for they will tell me as the promise says all things that I should do.
Saturday, November 7, 2015
SQL Rules of Coding
If you ever google sql for loop, just stop right there.
SQL is by definition a for loop.
A SELECT statement does nothing more than iterate over the rows in the database that satisfy the conditions of the query.
Therefore, if you want a for loop that sets a variable and then does some operation on one row at a time, JUST STOP. What you really want is a join somehow, and you can get it all done much simpler in terms of code and processing power. It will be easier to debug and to understand, and you won't have to worry about setting up the attendant variables to process a true for loop. SQL is a for loop, use it that way!
SQL is by definition a for loop.
A SELECT statement does nothing more than iterate over the rows in the database that satisfy the conditions of the query.
Therefore, if you want a for loop that sets a variable and then does some operation on one row at a time, JUST STOP. What you really want is a join somehow, and you can get it all done much simpler in terms of code and processing power. It will be easier to debug and to understand, and you won't have to worry about setting up the attendant variables to process a true for loop. SQL is a for loop, use it that way!
Friday, June 12, 2015
Rules of Coding
Rules of Coding
- The most important language you will ever code in: English (or the common spoken language used in your company). -- So that everyone understands what you wrote and why.
- Never use a regular expression without saying in plain English what it is doing. Regex is so hard to understand!!! Example: what the heck is this doing. Found in the gruntfile.js of bootstrap at https://github.com/twbs/bootstrap/blob/master/Gruntfile.js return string.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
- If you are going to modify something extensively, you are better off writing a new one and swapping it in when it is ready to go live. For example, if you are extensivley modifying an email template that is currently being used in production, just make a new template with a creative name and use that, so you don't possibly mess up code that is still using the old template. --This way you can also keep a clean backup of the old template and be able to rollback quickly.
- No one cares. No matter how much you think a given coding principle is important, there is nothing worse than alienating your fellow co-workers by sticking to a principle. It may still be important, but no one cares in the end. Try living without it for a day and you'll find you are still alive.
- Don't bother committing code if you haven't tested it. There are runtime errors and compile time errors. So even if your code builds, it doesn't mean it's even going to work. This will save you time in the end, believe me. You will end up having to change your code that doesn't work, or rollback a feature that you comitted and later find out will never work (e.g. I added logic to update the CreatedDate of some table in the database, and come to find out you can't update a database autopopulated field. So I get to rollback the "addition" I made across 5 files).
Friday, June 5, 2015
Using XML to pass dynamic paramters to SQL stored procedure.
You can use an XML string to pass any number of options to a SQL stored procedure like so
Use a scalar valued function to get one value at a time, which is still very fast unless you have hundreds of key-value pairs with XML likeMyValue
Use like this
Use a scalar valued function to get one value at a time, which is still very fast unless you have hundreds of key-value pairs with XML like
Use like this
USE [SaveOn]
GO
/****** Object: StoredProcedure [dbo].[sp_GetClubUserRenewals] Script Date: 5/6/2015 12:37:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Adam Alt
-- Create date: 2015-4-30
-- Description: Gets count of users and total dollar value from user renewals per club.
-- =============================================
ALTER PROCEDURE [dbo].[sp_GetClubUserRenewals]
@Filters NVARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON;
--Declare variables
DECLARE @BeginDate DATETIME
--Parse out values from xml object
SELECT @BeginDate = dbo.GetFilterValue(@Filters,'BeginDate');
--Select statement
SELECT * FROM SOMETABLE WHERE(@BeginDate IS NULL OR DateField >= @BeginDate)
END
And here is the scalar valued function.
GO
/****** Object: UserDefinedFunction [dbo].[GetFilterValue] Script Date: 5/6/2015 12:35:35 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Adam Alt
-- Create date: 2015-4-30
-- Description: Gets the value of a single node in a Filters xml object defined like Value
-- =============================================
ALTER FUNCTION [dbo].[GetFilterValue](
@Filters XML,
@FilterName NVARCHAR(MAX))
RETURNS NVARCHAR(MAX)
AS
BEGIN
-- Declare the return variable here
DECLARE @RetVal NVARCHAR(MAX);
-- Add the T-SQL statements to compute the return value here
SELECT @RetVal = NULLIF(LTRIM(RTRIM(node.value('.','nvarchar(max)'))),'')
FROM @Filters.nodes('/Filters/*') AS Nodes(node)
WHERE node.value('local-name(.)','nvarchar(max)') = @FilterName;
-- Return the result of the function
RETURN @RetVal;
END;
Or get them all at once with a table valued function:
USE [SaveOn]
GO
/****** Object: UserDefinedFunction [dbo].[ParseFilters] Script Date: 5/4/2015 3:18:07 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Adam Alt
-- Create date: 2015-4-30
-- Description: Takes xml like MyValue and returns all name-value pairs in a table, removing empty entries.
-- =============================================
ALTER FUNCTION [dbo].[ParseFilters](
@XML XML)
RETURNS @RtnTable TABLE(ID INT IDENTITY(1,1),
Name NVARCHAR(MAX),
Value NVARCHAR(MAX))
AS
BEGIN
INSERT INTO @RtnTable(Name,
[Value])
SELECT node.value('local-name(.)','nvarchar(max)') AS Name,
NULLIF(LTRIM(RTRIM(node.value('.','nvarchar(max)'))),'') AS Value
FROM @XML.nodes('/Filters/*') AS Nodes(node);
RETURN;
END;
Subscribe to:
Posts (Atom)