Month: July 2017

How to insert data from Excel to MS SQL quickly

I have used this tool a few times and honestly, its a lot quicker than the “Import and Export Data” tool or the “Generate Scripts” option under Tasks. This is a tool built by Perceptus Consulting to import data from Excel into an existing SQL table quickly. It just gives you the import script and you can modify it as you like. You can modify the script to make the transaction explicit, or simple add more statements to the script. It’s simple and a lot safer than running unreliable wizards.

Here is the tool:

https://tools.perceptus.ca/text-wiz.php?ops=7

Filed under: Tools

Redirect to different sites based on subdomains

Before I get to the meat of this post, you should know that when you want to simply redirect a site from https to https and you are using IIS, you can use one of two solutions:

  1. Add the following to the head:
    <meta https-equiv="refresh" content="0;URL='https://sarfraz.pro/'" />
  2. Use HTTP redirect in the site settings.

But what do you do if it is getting more complex that this, and you are presented with a scenario where:

    • https://sub1.example.com needs to go to https://sub1.example.com
    • https://sub2.example.com needs to go to https://sub2.example.com
    • https://example.com needs to go to https://www.example.com

With a little javascript, you can easily take care of this on the client side. Here is what you do.

Add the following to the head:

<script type="text/javascript">
function codeRedirect() {
if (window.location.hostname == "sub1.example.com" &&
window.location.pathname== "/" ) {
ref = 'https://sub1.example.com';
}
if (window.location.hostname =="sub2.example.com" &&
window.location.pathname== "/" ) {
ref = 'https://sub2.example.com';
}
else if (window.location.hostname =="example.com" &&
window.location.pathname== "/" ) {
ref = 'https://www.example.com';
}
window.location.href = ref;
}
</script>

Modify the body tag as such:

<body onload="codeRedirect()">

That’s it.

If you want to add more redirects into the function, just copy one of the “if” statements and paste them before “else if”. Then modify the hostname and ref with the new addresses. The hostname is what you want to direct from, and the ref is where you want to redirect to.

Filed under: JSTagged with: , ,

Modifying the height and width of CSS pseudo element content

If you want to add an image before or after an html element, you most often use the pseudo-elements :after and :before. For example, when you want to add an image before a link, you can write it like this:

a:before {
url(image.png);
}

But you can’t control the width or height of this image this way. If it is absolutely necessary for you to control the dimensions of this pseudo element, the following is what you do:

  1. Move the image to the background image property.
  2. Define the height and width of the pseudo element. These are the dimensions of the image.
  3. Make the content an empty string.
  4. Give the background-size the same dimensions as the image.

This is how you would do it in CSS:

a:before {
background-image: url(image.png);
background-size: 40px 40px;
display: inline-block;
width: 40px;
height: 40px;
content: "";
}

Filed under: CSS