Creating a Table to Hold Dates for a Year in SQL Server and Maintaining That Table

The scenario:
We want a table that is a list of dates. We really only need the dates between today and one year from today at most, not much more and not much less.

So first, we are going take the current date (@CurrentDate), calculate up to the date we want (one year from today plus one more day so that our table will start at 5/16/2018 and end at 5/16/2019, naming it @YearLaterDate). Because of leap years, the difference might be 367 instead of 366, so we are going to make a variable (@DaysDiff) to help us know that. Once we have that difference, we can loop through up to that number and then insert into our example table.

Declare @CurrentDate date
Declare @YearLaterDate date
Declare @DaysDiff int
Declare @DayCounter int
Create Table tblDateExample (dtDate date)
Set @CurrentDate = getdate()
Set @YearLaterDate = DateAdd(year,1,@CurrentDate)
Set @YearLaterDate = DateAdd(day,1,@YearLaterDate)
Set @DaysDiff = DateDiff(day,@CurrentDate,@YearLaterDate)
Set @Daycounter = 0

while @DayCounter < @DaysDiff
begin
	Insert into tblDateExample
	(dtDate)
	VALUES
	(DateAdd(day,@DayCounter,@CurrentDate))
	Set @DayCounter = @DayCounter + 1
end

Select *
From tblDateExample
Where 1 = 1

Hurray! We've made our table! But wait. Once tomorrow comes along, we will not need 5/16/2018 anymore and will want to add in 5/17/2018. Use whatever means you have for a scheduled task and run the following query once a day. We are going to use many similar variables because we have similar uses. We know we want the table for, from today, to a year from today plus one more day, so use those same ones again. Instead of the difference between those though, we are going to get the maximum date in our example table. Why? To handle for mishaps where we might need to add two days, or thirty days, instead of one. So, now we get the difference between our current maximum and our desired maximum, loop through that difference instead and add any days accordingly. We'll make a quick delete of anything before the day before the current date as well and anything after in case extra dates were added somehow.

Our maintaining query:

Declare @CurrentDate date
Declare @YearLaterDate date
Declare @DayCounter int
Declare @CurrentMax date
Declare @MaxDiff int	
Set @CurrentDate = getdate()
Set @YearLaterDate = DateAdd(year,1,@CurrentDate)
Set @YearLaterDate = DateAdd(day,1,@YearLaterDate)
Set @DayCounter = 0
Set @CurrentMax = (select max(dtDate) from tblDateExample)
Set @MaxDiff = DateDiff(day,@CurrentMax,@YearLaterDate)	
	
delete from tblDateExample where dtDate < @CurrentDate;
delete from tblDateExample where dtDate > @YearLaterDate;

while @DayCounter < @MaxDiff
begin
	Update  tblDateExample
	Set dtDate = dtDate
	Where dtDate = DateAdd(day,@DayCounter,@CurrentMax)
		
	if @@rowcount = 0
	begin
	Insert into  tblDateExample
	(dtDate)
	VALUES
	(DateAdd(day,@DayCounter,@CurrentMax))	
	end
	Set @DayCounter = @DayCounter + 1
end

Now we have a table that keeps the dates for roughly up to a year from the current date to a year from that.

Kingdom Hearts Final Mix (PS4): Unknown Guide

Hi everyone, Cathy here. This video is going to show you my battle with Unknown in Kingdom Hearts Final Mix. Now this video makes it look a lot easier than it was because there’s a certain move that Unknown has, that he was only able to do against me once, and I got really lucky, and I picked the right thing. But all the same, here we go. I will also provide some general tips that I read and will share with you too.

The main guide that I used was a video guide provided by Soraalam1called Boss Busters. It had a lot of helpful tips: equip counter, and also gravity supposedly helps and I also, after I watched that video, I decided to take a much more aggressive approach to this battle than I had before. And I took the time to summon Tinkerbell and cast Aeroga, some good defensive stuff. Like my other boss guides, I was pretty leveled up at this point because I did the synthesis and leveling, and I saved a lot of these super bosses for the end. So, we’re about to go, and let’s go check it out.

[Cut scene start]

[Unknown’s words are communicated on screen and not spoken aloud]

Sora: Who are you?
Unknown : Ah, it seems you are special, too.
Goofy: Ansem?
Unknown: That name rings familiar. You remind me of him.
Sora: What’s that supposed to mean?
Unknown: It means you are not whole. You are incomplete. Allow me- to test your strength.

[Cut scene end]

That cut scene had the Kingdom Key because I had to go and use the Theater to play it since I skipped it when I initially did this battle. Okay, first thing, summon Tinkerbell. Oh and if you heard that little noise right there, that was my daughter. She’s watching me as I make this video. Alright, so here comes Tinkerbell. She’s gonna help us out by healing Sora, and Ronnie’s gonna just be there making noise. Hopefully not too much noise.

Alright, so I cast Aeroga on myself, and now I’m just going to aggressively attack the boss, over and over and over again. He has very strong attacks. He’s just gonna go at me. He’s going to be really aggressive, so my team’s going to stay on top of him as much as we can. I’m just gonna try and cut through that, hack through that blue wall . Alright, that move that you would have just seen there, that’s his Catch move, that’s extremely dangerous move, I got very lucky because I picked the right one. And I also got lucky because that was the only time he cast it the entire fight, so I was very, very fortunate with that, that’s what makes this fight look easier than it was. Alright, there I tried to cast Gravity. I’ve lost my Aeroga but I’m going to still keep attacking very aggressively as much as I can since this boss is very fast and very strong.

So, here we go. We’re all attacking as much as we can, except for Tinkerbell, who’s on support, and she’s doing a great job. Sora has plenty of health. Alright. And we’re just gonna keep attacking. We are getting this done pretty fast, considering how much health this boss has.

Alright, so there’s a very strong attack that I’m trying to run from, I Dodge Roll, I tried to fly and Glide, still got hit. I’ve lost a lot of health, so I’m going to heal. I went ahead and healed myself even though I’ve got Tinkerbell helping me out here. And I know that a couple of times, alright, sorry, someone got very inquisitive there.

Okay, we’re almost done. We are almost done. We gonna just keep attacking, low health, low-ish health, gonna heal, attack. Alright, oh yeah, here we go, here’s my attempt at Gravity that did not go well, but we’re still going to do pretty well. We’ve almost got this boss. That’s probably why I’m trying. I’m like, “Can I do it?” and no, I can’t. I mean, so, in fact, looking back, that’s probably not a good idea to do that to a boss when the boss is almost defeated because of how the Gravity spell works. Alright, Donald healed me right there at the end, and we managed to get our last hits in, so go team, woo-hoo!

[Cut scene start]

Unknown: Impressive. This will be enjoyable.
Sora: What are you talking about?
Unknown: It is beyond your comprehension, for now. Until we meet again.
Sora: Wait, what’re you-?
Unknown: I am- but a mere shell.

[Cut scene end]

Obtained Experience Necklace, Ansem’s Report 13. So, that’s a wrap. The End.

A Bid For Host is Not the Same as Allowing Free Speech

Much of this blog post is in reference to the article, Citing Costs and ‘Disruptions,’ Nirenberg Says San Antonio Will Not Pursue 2020 GOP Convention.

The San Antonio city council has decided NOT to bid on the Republican National Convention. Since the Republican party, led by the likes of a man who’s last name rhymes with “rump,” Paul Ryan, and Mitch McConnell, that allows Steve King to stay in Congress, and tried to bring in Roy Moore, is a bunch of fascists out to destroy everything I love, I consider this good news because I was furious at the prospect when I first learned of it in an article titled, San Antonio City Council Warned Not to Talk Politics of GOP Convention Bid in Closed Session. This is the party that put a disgusting racist in the White House because they agree with his bigotry. He’s called Mexicans, my neighbors and ancestors, rapists, to start off his campaign along with plenty of racist history before that (questioning President Obama’s birth certificate, calling for the execution of the Central Park Five, denying rent to Black people and so on). Another more recent item that sticks out in my mind is his calling Haiti a “shithole” (or possibly “shithouse”).

I live in District 9 and met John Courage in person some months before he was elected. We talked for maybe 30 minutes about several topics (it could have been longer, my point is that it was to me a significant amount of time). We agreed on many points, and he listened to my frustrations and fears. My district electing a person who leans more on the liberal or progressive side of things than conservative was a pleasant surprise. I call or email him from time to time though not sure if he or his staff ever remember me by name. After Hurricane Harvey hit, I stopped by his office to make a donation. I was disheartened to read the following comment on his take on, “whether [he] thought the city should submit a bid to host the Republican National Convention.”

Councilman John Courage (D9): Maybe. “I believe in the freedom of speech and the freedom of assembly,” he said. “Whatever they decide to do is up to them.” Asked whether the same level of scrutiny would be applied to a bid for a Democratic National Convention, Courage said, “Absolutely, I would think so.”

Freedom of speech and freedom of assembly? What does that have to do with a bid to get the RNC here? Nothing. The “Whatever they decide to do is up to them,” sounds more like a response to a question like, “What do you think if the Republican party decided to have their convention here?”

I am exhausted of anyone making the argument that bigotry is free speech, and that is what I feel a Republican convention is based on the leaders of that party and their actions, votes, and so on toward myself and the people I love. As my Twitter mutual Amadi has said in one tweet of this worthwhile full thread, “There’s no such thing as just speech. Speech is an act. Opinions matter because they motivate people to action. We know it.” That is all true, and I feel it when I see the current party in power do everything they can to take away my family’s health care or to hurt my career by working to destroy Net Neutrality, or to threaten my family’s right to exist because they hate our Mexican heritage.

Please take a look at the following from one of the other councilmen, Rey Saldaña:

“One week of economic boost two years from now does not [override] all of the feelings that my constituents have,” he said. “The fact that our president has gone out of his way to personally offend so many residents who I represent and personally offend …. folks who are transexual or Dreamers or disabled – the list goes on – it’s been very difficult to say yes to this and controversial because the president has made it so.”

Another councilman, Roberto Treviño, referred to our “cultural heritage.” and it hurts that they are the only two on the council willing to specify to that degree the harm caused by this alleged “president” because so many want to give the appearance of concern for financial and economic benefit and not opposing the party of bullies.

Even if I personally felt it were acceptable for the Republicans to have their big hate convention here, and I don’t, the obligation of the government for freedom of speech is to not prevent the gathering itself. They have no obligation to bid, so the answer simply ignores the question and relates it to something that is not really the question at hand.

I am disappointed because all too often I see people arguing with the words “free speech” about things that are most certainly not a debate about “free speech,” that those arguments are harmful, and now I can count my representative that municipal level in that group.

slither.io Review

Slither.io is a video game you can play on iOS, Android, or on a browser online. I first played it on an iPad after my daughter expressed interest because she saw Ryan, from Ryan’s Family Review, playing it. After awhile, I paid to get the ads removed and one day, curious about the purpose of the game, I played it myself.

I liked it.

You play as a Slither, a snake with two eyes and a body. You can build your Slither, if you so choose, from a select set of colors or you can choose from a pre-made set. At first, I made my own but eventually settled on a pre-made black and yellow. The more pellets you eat, the longer your snake. The snake’s length is essentially its score so the goal is to grow your snake as big as possible. If your head hits into another snake’s body, you die. While the pellets one can eat on the map increase your length, the dead snakes give even more, adding a competitive edge to exploring and slithering around on the map, though it doesn’t have to be that way.

To my relief, a lot of other snakes are actually happy to simply eat and try not to kill each other. Some do, some don’t. I find it more relaxing when we’re all happy to just eat to get big and go on our merry way. Lately, I’ve been playing on my phone more since that has the option to play against the A.I. The game-play is faster and to me, maybe the most noticeably different thing, is the A.I. snakes are maybe not quite as aggressive or coordinated as some snakes online. By coordinated, I mean both that at least once online, I did feel two snakes were actively working together to kill mine, and they succeeded, and also that the other players know the exact right way at the exact right moment to destroy me with ease. They have good coordination in their own timing.

In any case, both experiences give me a little snake to make into a big snake, and I think I’m so cute when I’m little and so proud when I get big. I’m generally content to get over 1,000 though lately, I’ve even managed to get on the leader-board against the AI. In fact, as I type this review, my latest and best score from tonight (4/12/2018), is 18,501.

My approach is to mostly just work on eating whatever I can get to with as little danger as possible. I tend to play with caution though the more willing you are to risk, the faster you can get big. One strategy I saw on YouTube was to get on the leader-board and then make your snake into a big circle and go in and out of your coil to eat whatever is nearby in or out of it. I sometimes use that even when I’m not on the leader-board. It does put me at risk of being wrapped, but it’s a risk I take. I mean, playing the game itself and being near other snakes is a risk too. Sometimes instead of a circle, I just go up and down and hope maybe another snake ran into my tail.

Once I do get bigger, I might try wrapping the smaller snakes. Some do their best to spin and hope and work to getting out, and they do, because I might move on, and others outright give up and kill themselves. Another video I watched suggested a lot of good, aggressive tips, but I prefer to play at a calmer, passive pace. Slither.io helps me unwind, literally and figuratively.

You can play on a browser for free and see ads. The iOS version is also free with ads though for that one, you can pay to have them removed. It cost $4.32, and I do feel I have received my money’s worth from both my daughter’s and my own enjoyment. Since I paid for it on the iPad for her, the ads were removed when I put the game on my own iPhone as well.

If you appreciate any of the work that went into making this post, please consider giving a tip to my PayPal account:
https://www.paypal.me/sonkitty

Using SQL to Determine the Sunday and Saturday of the Calendar Week Based on a Given Date

Recently at work, a manager asked that I show some records but restrict them based on the calendar Sunday through Saturday week of a given date.

I did my usual Google search for this particular request, which gave me some ideas though none really gave exactly what I wanted because for some reason, Sundays throw certain expected calculations off.

With that in mind, I decided to write some extra lines just to make it more clear to me what I was accomplishing to get the dates and figured it might be useful to other visitors to this blog.

So, here it is, this is written specifically for SQL Server 2008.

Declare @DateToCheck datetime
Declare @SubtractForSunday int
Declare @AddForSaturday int
Declare @SundayDate datetime
Declare @SaturdayDate datetime
Set @DateToCheck =  DATEADD(d, 0, DATEDIFF(d, 0, GETDATE()))
Set @SubtractForSunday = DATEPART(dw,@DateToCheck) - 1
Set @AddForSaturday = 7 - DATEPART(dw,@DateToCheck)
Set @SundayDate = DateAdd(day,-@SubtractForSunday,@DateToCheck)
Set @SaturdayDate = DateAdd(day,@AddForSaturday,@DateToCheck)	

Select idThing
From tblThing
Where 1 = 1
and dtSomeDate between @SundayDate and @SaturdayDate

To break it down a little so you know what I am doing:

The DATEADD(d, 0, DATEDIFF(d, 0, GETDATE())) portion is to set the current date/time to midnight. You can get around this by making the @DateToCheck variable a date variable, instead of datetime, or making sure the datetime variables you are working with already set to midnight, which was the case for my own particular situation. I’m showing the midnight here because that is not always the case and is useful for my own reference.

Sunday is always day 1 and Saturday is always day 7. Those are known quantities. Once we have a date to check, we can get that date’s day of the week number that is 1 through 7 using algebra. If the day we are checking is 1 (Sunday) and we are aiming to get to 1 (Sunday) , we will want to subtract nothing, 1 – 0 = 1. If the day is 2 (Monday), we will want to subtract only 1, so 2 – 1 = 1. If the day is Saturday we will want that number to be 6, 7 – 6 = 1. We are starting to see a pattern where y is the day of the week are checking and x is the number that will give us the necessary subtraction for reaching 1: yx = 1. We take that same logic to give us Saturday: v + w = 7. The @SubtractForSunday variable is determined by re-working this equation to look like x = y – 1 and the @AddForSaturday variable is determined by re-working it to w = 7 – v.

Because once we have that number, we can proceed to the original form of the equation and use the DateAdd function, making sure to have our minus sign in front of our @SubtractForSunday variable.

If you wanted to condense it instead of lay out all like that, you could do:

Set @SundayDate = DateAdd(day,-(DATEPART(dw,@DateToCheck) - 1),@DateToCheck)
Set @SaturdayDate = DateAdd(day,(7 - DATEPART(dw,@DateToCheck)),@DateToCheck)	

If you appreciate any of the work that went into making this post, please consider giving a tip to my PayPal account:
https://www.paypal.me/sonkitty

How to Use the Elementor and Simple Lightbox WordPress Plugins to Create a Tumblr-Like Photoset or Masonry Gallery

I wanted to make a WordPress post that showed a drawing’s progression log like I have done in the past on my Tumblr. For Tumblr, the web application interface lets you re-arrange the images in size and order and makes the photoset a slideshow. You can also put captions in that will appear under the photos in the slideshow, and that slideshow lets you navigate using the right and left arrow keys. This is not specific to only Tumblr but uses the Javascript library, Lightbox, which I have little experience with. However, I do have plenty of experience making Tumblr photosets.

This post will break down the steps I took to accomplish that goal should I need to find it again or if any readers find the information useful. Before I start, I will say that Tumblr Photoset Grid/Masonry Gallery for WordPress by sike is a $12 plugin I found that, by its description at least, would have done exactly what I wanted. Most of the information you would need for what I ended up doing instead are in this video, How to create masonry style gallery in Elementor Page Builder for WordPress.

As I made this post, I noticed the Simple Lightbox alone would also work for my main goal of a series of images in a single column and through regular WordPress posts, without Elementor so long as the images link to the media file. Still, this information is useful for if I ever want to do more columns in masonry gallery format.

1. Use the Elementor Plugin

Install and activate the Elementor plugin if you are not already using it in your WordPress site. Elementor alone can let you put in an image gallery that can be a single column and act as a slideshow, but I ran into an issue where the captions would not show, not even on the actual post as described that it should in the documentation. For some users, showing the captions below the images within the gallery is actually unwanted. In any case, I wanted to put text somewhere, it didn’t have to be image captions per se though it was preferable at first, and Elementor alone was not going to be enough.

2. Update the Elementor Plugin’s Global Setting to Turn Lightbox OFF.

To prevent double opening of a lightbox, we are turning off the Lightbox setting, which is on by default, in Elementor.

3. Use the Simple Lightbox Plugin

Install and activate the Simple Lightbox plugin. If you need to update any of the settings, you can do so through the Plugins page or under Appearance from the WordPress dashboard, then choosing Lightbox.

4. Create Post Using Elementor

For the type of post I was trying to do this for, I created a single-column post where I show a starting progression at the top and finished image at the bottom. You can do the actual columns and sizes however you want, that is the benefit of this masonry gallery approach. The next step is the really key one.

5. Create Image Widgets and Link Each One to Media File

Because we are using individual image widgets instead of an overall image gallery, we have more freedom with the content between the images so instead of putting the captions with the image properties and showing in the Lightbox, I’m actually placing them above each image as I explain my process. With our Elementor plugin already set to have Lightbox OFF by default, we can now leave it to the Simple Lightbox plugin to create the slideshow and group the images together automatically. Preview or update the page too see the Lightbox single-column in action.

6. Adjust CSS

This step can be skipped if you are happy with the Simple Lightbox default look. I updated some of the CSS to my own preference because of past familiarity with Tumblr photosets.

The following was added through Appearance, Additional CSS:

/* Removes 16px border made through padding within this container */
#slb_viewer_wrap .slb_theme_slb_baseline .slb_container { 
     padding: 0 !important; 
}
/* Changes box shadow to black and new radius, more closely matches a Tumblr photoset */
#slb_viewer_wrap .slb_theme_slb_default .slb_container {
     border-radius: 3px !important;
     box-shadow: 0 4px 30px #000 !important;
}

Within the post I was working on, I also hid the details in case I end up using captions more often in the future and the post being worked on turned out to be an exception rather than a rule for how I want the text describing images to look.

<style>
.slb_details { display: none;}
</style>

DONE!

You can see the final results of my efforts in my Chaos with Claws Progression Log.

Further Notes

Another option I considered was to have a slideshow at the top and then show the progression log as individual images below it. I also tried out a plugin called Smart Slider 3 that looked really good for slideshows in general but then realized I still wanted my single column of each image in the set to be visible on the page. I even thought of having 7 different slideshows and putting them all on the same page but that was too much work for something that could be done better another way.

If you appreciate any of the work that went into making this post, please consider giving a tip to my PayPal account or supporting me on Patreon.

Chaos with Claws Progression Log

The header image above is the final image I will be working toward. The idea is based on the Greek mythological character Chaos, sometimes personified as a woman, and the inspiration for the look is drawn from Sailor Chaos in the Sailor Moon Sailor Star series, the digital artwork by GENZOMAN titled Chaos, the digital artwork by sandara titled Black Angel, and the Succubus persona from the Persona video game series, mainly Persona 5. Also, I very much wanted to do a picture of someone or something with claws. Click on any image below to see the progression log as a slideshow.

Original photo. I did not take it with the idea of drawing myself in mind, but it looked like a good reference while I was brainstorming ideas.

Initial lineart, 1px thickness, lower resolution.

Re-worked lineart, 7px thickness, higher resolution.

Initial grays to get a feel for shading.

Added some colors but wanted more variance in the colors so kept going.

Re-worked the shading based on playing around with colors.

Finished image after deciding on final color scheme.