Saturday, April 2, 2016

Setting Up API Request with HMAC SHA256 hashing

// Set up request
            var publicKey = "123";
            var privateKey = "123";
            var domain = "portal.example.com";
            var scheme = "https";
            var uri = "/api/stuff/v1/asd/1234/visitors?from=20160301&to=20160303";
            var contentType = "application/json";
            var postContent = ""; // always empty string for Company API
            var date = DateTime.UtcNow;
            var dateString = date.ToString("r");
            

            // Build request signature
            var message = contentType + "\n" + domain + "\n" + uri + "\n" + dateString + "\n" + postContent + "\n";

            // Encode request signature
            var hmc = "";
            var encoding = new ASCIIEncoding();
            byte[] keyByte = encoding.GetBytes(privateKey);
            using (var hmacsha256 = new HMACSHA256(keyByte))
            {
                byte[] messageBytes = encoding.GetBytes(message);
                byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
                hmc = BitConverter.ToString(hashmessage).Replace("-", "").ToLower();
            }

Monday, February 22, 2016

White-listing IP Addresses to Azure SQL DB

Sometimes if you want to work from home and you use Azure for your databases, you will have to white-list your home IP address.






And if you scroll down on this final page, you can add an IP address to white-list and a name for it.

Wednesday, January 13, 2016

Shaky Fixed Backgrounds on IE 11

Sometimes on IE 11, there will be a shaky scroll on backgrounds / images that only appears in IE.

If a user were to go to Internet Options > Advanced > and UNCHECK Smooth Scrolling, this would fix the problem. However, assuming most users have it checked by default.. here is how to fix the issue using JavaScript. I am using Angular JS so I put it in the controller loaded on the page that needs the function and put it in the init function. If you are not using Angular, then just take the if statement part out, ignore the init() and place it as needed.

I also added a .1 * wd in there in case you need to adjust the speed the page gets scrolled when the user uses the mousewheel. Since ours was moving way, way too fast.. we had to multiply it by .1 to make it slower. Multiply by a whole number to make it faster.


Credit to here: http://stackoverflow.com/questions/21775234/ie-11-smooth-scrolling-not-firing-intermediate-scroll-events

Tuesday, January 5, 2016

Algorithms: Merge Sort


I have decided to take an online Algorithms course for fun / for my own good / for my curiosity in my spare time on Coursera. I am going to post some of my notes here based on what I can find on the internet with my own notes on it. I find a lot of times it is harder to come from a non-traditional background and learn very comp-sciey type of classes as I don't have a background in all the vocab / theories / concepts, so I will basically be breaking down tech sounding concepts into plain English I can understand and sharing my notes :). I don't honestly think this will help me in my day to day work but perhaps down in the future it will be a foundation for something or extremely helpful in some rare case.

Starting off.. the study of algorithms appears to me to be the study of how long things take, making more efficient code, estimating the worst case scenario for how long your code will run, and the actual set of functions / processes / calculations to be measured. Merge sort is one of many ways to take a bunch of scrambled numbers and get them sorted. Merge sort specifically takes say 8 blocks, divides it into two sets of 4, then each of those two sets into four sets of 2, and stops there.. then merges them back one at a time into a new set of numbers in order (by comparing each number to see if it is higher/lower than the numbers in the set). Watch THIS little animated snipped on Wiki and all will be clear.

Very, very specific estimated times for a calculation with constants in them aren't terribly useful.. except on a very small scale calculation.. but seem good for the sake of understanding how to calculate it at all. Below is a merge sort in C language I found on a website (referenced below image) with some annotations on it.

The number of operations it takes to run this algorithm is: 6n*log(base 2)n + 6n The easiest way to prove it is to understand that each level does the same amount of work. And to multiply the amount of work by the number of levels. And that is the total work done.

Here is how to prove each level does the same amount of work: Number sub-problems doubles with each level (larger quanity of arrays). But amount of work to do halves (arrays get smaller). Doubling # of arrays and halve the size of each array.. will have constant amount of work. See notes on code below:
Original image and C code from http://faculty.cse.tamu.edu/djimenez/ut/utsa/cs3343/lecture2.html.

The number of levels will be:
So.. if we know there are (log(base 2)*n + 1) levels and 6n work per level, if we multiple those two things we can say merge sort will take this amount of operations for a n input array of n numbers: 6n*log(base 2)n + 6n

Monday, December 28, 2015

Testing on BrowserStack locally



If you login with a BrowserStack account, you can test your local work on emulators. Note for Safari on a Mac, you have to use specific ports.

"For now, Safari 8 on Yosemite allows Local testing via a limited number of ports. The ports that are most easy to remember are 80,3000, 4000, 5000, 8000 and 8080." - StackOverFlow post

So this for example works:
https://localhost:8080

Wednesday, December 2, 2015

Clear Location Settings Cross-Browser


Let's say you are either developing or testing a website you are building that saves your location, and you already told it to save some day in the past. Interestingly every browser has its own way to clear location settings. Here's a quick reference of the big 4 Windows browsers (Chrome, IE, Edge, and Firefox).

On Chrome: Go to the settings from the hamburger menu. Click Content Settings.


On Microsoft Edge: Open the menu labeled with the 3 dots (...), hit Show More, and you will see the dropdown has the Location permissions.


On Internet Explorer: Click the gear and go to Internet Options, then Privacy tab.


On Firefox: First right click anywhere inside of the page, then select View Page Info. Then select the tab for Permissions.

Thursday, November 12, 2015

SQL Server: Save Database Locally

If you have a database up in the cloud or elsewhere and want to make a local copy, you start by opening up SQL Server Management Studio (this is 2014 but should be the same/similar for other versions).

Login to your local server. I used SQL Express, so my login is Windows Authentication and the server name is localhost/SQLEXPRESS. Also make sure this is running if you check in your Services on your machine.

Login to your online server. You need those credentials from your company or whatnot.

Now, start by right clicking on Datbases on your online server and hitting Export Data-tier application.

Hit Next.
Save locally somewhere. I just made a Db folder under my C drive to make it easy to find. It will save a BACPAC file.

Now, right click on Databases on your local server and hit Import Data-tier application. Find your BACPAC file you just made.

Find the BACPAC file you saved.

Hit Next and finish up with this dialog and you should have a local copy imported into your local server.

Add your local DB to your connection string config file.