Skip to content

Remove Duplicates from JavaScript Array

Here is a very useful and quick way to remove duplicates from a Javascript Array which I found from StackOverflow and it proves to be very useful for what I do.

var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"];
var uniqueNames = [];
$.each(names, function(i, el){
    if($.inArray(el, uniqueNames) === -1) uniqueNames.push(el);
});

Glad I bought my Chromebook from John Lewis

Originally posted on Chris Swan's Weblog:

I’m a bit behind on writing this up, but just as I sometimes call out bad customer service it’s also worth highlighting good experiences.

TL;DR

John Lewis gave me a two year warranty on my Chromebook, which meant that when the battery died I was able to get it fixed.

Background

When I bought my Chromebook back in December 2012 I got it from John Lewis. Partly this was because I had a ton of John Lewis vouchers (that I generally use for online grocery shopping at Waitrose), and partly getting it delivered to my local Waitrose was going to be more convenient that hanging around at home for postal delivery.

Since I got my Lenovo X230 the Chromebook has been mostly languishing under my bed, occasionally being pulled out when I need something with a keyboard. Around November last year I noticed that the battery was flat, which I…

View original 424 more words

How to parse a date in M/yyyy in C#

A little quick tip for parsing the DateFormat of MM/yyyy is to use ParseExact method on “M/yyyy” written below

DateTime dt = new DateTime();             

dt = DateTime.ParseExact(Months[i-1], “M/yyyy”, System.Globalization.CultureInfo.InvariantCulture);

dt = dt.AddMonths(1);

Note that this allows you to make adding months easier when using the method .AddMonths(1) which is why I have used “M/yyyy”. I have noticed that “MM/yyyy” will throw an error if the data being parsed is “6/2015″ for example.

Hope that helps!

Could not load file or assembly ‘CrystalDecisions.WIndows.Forms.Version=10.2.3600′

If you receive the following error Could not load file or assembly ‘CrystalDecisions.WIndows.Forms.Version=10.2.3600, Culture=neutral,PublicKeyToken=692fbea5521e1304 which is a common problem where I work where users see this error message on stand alone windows applications. The reason why this error is showing up is related to the incorrect version or no crystal reports being installed on their machibne (yes a pain!).

crystalreport

To get around this, you may need to scour the internet to find the correct version of Crystal Reports which is for Visual Studio 2005, and specifically for version 10.2.3600 which it seems on the official SAP no longer has this file.

So after much research, the latest link which provides this is http://tcsoftware.net/blog/2011/05/crystal-reports-redistributable-download-net-2005/

Select Crystal Reports Redistributable for x86 systems for 32 bit &
Crystal Reports Redistributable for x64 systems for 64 bit.

Then the error message should no longer show up!

Hope that helps!!!!!!!

How to clear the cache in Internet Explorer

I often get asked this question on how to get the latest update of iamges or documents on the Intranet, and the first point of call is to clear up the old cache from Internet Explorer which solves 90% of the problem. Here’s how: –

If you click on Internet Options in settings from the cog icon.

This should show up this box below: –

1

Click Delete

This should show the window: –

2

Select Temporary Internet files as checked. Then hit Delete.

You should see the updated image.

If you still are unable to see the window, here is a url https://kb.wisc.edu/page.php?id=15141 to guide you based on the version of IE you are using.

How to set up a password to protect data on an Excel spreadsheet

In the 2013 version of Excel, to password protect the spreadsheet if you don’t already know is by the following: -
Set a password to modify an Excel spreadsheet
  1. Click the Microsoft Office Button , click Save As, and on the bottom of the Save As dialog, click Tools.
  2. On the Tools menu, click General Options. …
  3. Under File sharing, in the Password to modify box, type a password.
  4. In the Confirm Password dialog, re-type the password.

I think they make it really hard to allow this option!

How to create a text underline function in Canvas

I had found a recent post, a useful function that allows you to write text with underline in HTML5 canvas which apparently is not a one liner to write in Javascript. Here is the Javascript code: –

var textUnderline = function(context, text, x, y, color, textSize, align){

  //Get the width of the text
  var textWidth =context.measureText(text).width;

  //var to store the starting position of text (X-axis)
  var startX;

  //var to store the starting position of text (Y-axis)
  // I have tried to set the position of the underline according 
  // to size of text. You can change as per your need
  var startY = y+(parseInt(textSize)/15);

  //var to store the end position of text (X-axis)
  var endX;

  //var to store the end position of text (Y-axis)
  //It should be the same as start position vertically. 
  var endY = startY;

  //To set the size line which is to be drawn as underline.
  //Its set as per the size of the text. Feel free to change as per need.
  var underlineHeight = parseInt(textSize)/15;

  //Because of the above calculation we might get the value less 
  //than 1 and then the underline will not be rendered. this is to make sure 
  //there is some value for line width.
  if(underlineHeight < 1){
    underlineHeight = 1;
  }

  context.beginPath();
  if(align == "center"){
    startX = x - (textWidth/2);
    endX = x + (textWidth/2);
  }else if(align == "right"){
    startX = x-textWidth;
    endX = x;
  }else{
    startX = x;
    endX = x + textWidth;
  }

  context.strokeStyle = color;
  context.lineWidth = underlineHeight;
  context.moveTo(startX,startY);
  context.lineTo(endX,endY);
  context.stroke();
}

Here is the sample code utilising the function: –

var canvas = document.getElementById("myCanvas");//get canvas element as js object
var context = canvas.getContext("2d");//get canvas context to play with it

//initialize the variables with the required data
var text = "ScriptStock";
var textAlign = "center";
var textColor = "blue";
var fontSize = "60pt";
var fontFamily = "Calibri";

//Set the position of the text on canvas
//I am setting it as center of the canvas. You can set as per your need.
var x = canvas.width / 2;
var y = canvas.height / 2;

//Set the canvas context properties
context.font = fontSize + " " + fontFamily;
context.textAlign = textAlign;
context.fillStyle = textColor;

//Display the text on canvas
context.fillText(text, x, y);

//Call the function to underline the text
//We need to pass some values to our function so that it can perform the necessary calculations.
textUnderline(context,text,x,y,textColor,fontSize,textAlign);
Follow

Get every new post delivered to your Inbox.

Join 523 other followers