What is the difference between ++i and i++

  • ++i will increment the value of i, and then return the incremented value.
     i = 1; j = ++i; (i is 2, j is 2)
  • i++ will increment the value of i, but return the pre-incremented value.
     i = 1; j = i++; (i is 2, j is 1)

For a for loop, either works. ++i seems more common, perhaps because that is what is used in K&R.

In any case, follow the guideline “prefer ++i over i++” and you won’t go wrong.

There’s a couple of comments regarding the efficiency of ++i and i++. In any non-student-project compiler, there will be no performance difference. You can verify this by looking at the generated code, which will be identical.

The efficiency question is interesting… here’s my attempt at an answer: Is there a performance difference between i++ and ++i in C?

http://stackoverflow.com/questions/24886/is-there-a-performance-difference-between-i-and-i

As On Freund notes, it’s different for a C++ object, since operator++() is a function and the compiler can’t know to optimize away the creation of a temporary object to hold the intermediate value.

What is the difference between ++i and i++

powershell arrays

they are able to hold different data types. For example, I can store numbers and strings in the same array as shown here.

PS C:\> $a = 1,2,3,”four”

PS C:\> $a

1

2

3

Four

 

 

If I need to change an element in array, I can index into the array by using the square bracket and the index number. To find the upper boundary, I use the GetUpperBound method, and when I have that value, I can easily find the element I need to modify. This technique is shown here.

PS C:\> $a.GetUpperBound(0)

3

PS C:\> $a[3] = 4

PS C:\> $a

1

2

3

4

 

 

 

The way to add a new element to an existing array is to use the += operator as shown here.

$a += 12

powershell arrays

Using PowerShell to disable Loopback check

Method is less secure and recommended for DEV environments

New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name “DisableLoopbackCheck” -Value “1” -PropertyType dword

 

Присвойте параметру реестра
DisableStrictNameChecking
значение 1. Дополнительные сведения о том, как это сделать, см. в следующей статье базы знаний Майкрософт:
281308 Подключение с общим доступом по протоколу SMB на компьютерах с операционной системой Windows 2000 или Windows Server 2003 не всегда работает с псевдонимом
Выберите в меню Пуск пункт Выполнить, введите команду regedit и нажмите кнопку ОК.
Найдите и выделите следующий раздел реестра:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
Щелкните правой кнопкой мыши раздел Lsa, выберите команду Создать, а затем — Параметр DWORD.
Введите DisableLoopbackCheck и нажмите клавишу ВВОД.
Щелкните правой кнопкой мыши параметр DisableLoopbackCheck и выберите команду Изменить.
В поле Значение введите 1 и нажмите кнопку ОК.
Закройте редактор реестра и перезагрузите компьютер.
Method is more secure and recommended for PROD environments

Specify the host names in the registry – BackConnectionHostNames

Refer to http://support.microsoft.com/kb/896861

Способ 2. Укажите имена узлов

Для указания имен узлов, поставленных в соответствие адресам замыкания и способных связаться с веб-узлами на вашем компьютере, выполните следующие действия:
Присвойте параметру реестра
DisableStrictNameChecking
значение 1. Дополнительные сведения о том, как это сделать, см. в следующей статье базы знаний Майкрософт:
281308 Подключение с общим доступом по протоколу SMB на компьютерах с операционной системой Windows 2000 или Windows Server 2003 не всегда работает с псевдонимом
Выберите в меню Пуск пункт Выполнить, введите команду regedit и нажмите кнопку ОК.

Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
Click MSV1_0

create multistring with name BackConnectionHostNames

click edit, enter hostname (http://servername)

iisreset

Using PowerShell to disable Loopback check

SQL alias for SharePoint 2010

One of Microsoft’s best practices for SharePoint is to create a SQL alias for your SharePoint farm. This can ease the transition from one SQL server to another, required in some instances to scale your farm out, as well as to aid in recovery from some disasters. Luckily this is one of the easiest best practices to implement!

To create a SQL alias, log in to your SharePoint server (note: needs to be completed on ALL of your SharePoint servers).

Open Windows Explorer, and browse to “C:\Windows\System32 folder”. Open the program “CliConfg.exe”.

Select the second tab “Alias” of the SQL Server Client Network Utility, and click “Add”.

In the “Add Network Library Configuration” dialog type in the desired alias for your SQL server. A good standard for this is A-[SharePoint Farm Name]. For example, if your farm name was “Intranet” your alias would be “A-Intranet”. Type the name of the actual SQL server you’re connecting to in the “Server name” field. The alias you create needs to be the same on ALL SharePoint servers in the farm.

Select “OK”, and your alias is created! You can now create a SharePoint farm using the Alias as the database server name. If you ever have to move your databases to a new server, you can change the alias to point to the new server name, and keep SharePoint pointing at the alias!

Note: another best-practice on 64-bit systems, is to configure the alias in “C:\Windows\System32\CliConfg.exe” and “C:\Windows\SysWOW64\CliConfg.exe”. You can then use this alias with both 64-bit and 32-bit processes, and is REQUIRED for Project Server 2007 to work properly with SQL aliases.

 

#http://habaneroconsulting.com/Insights/Creating-a-SQL-alias-for-SharePoint.aspx#.Uefeq43IZd0

 

Over the next few weeks I’ll be creating a dozen or so virtual machines (VM). To save time I’m trying to script as much of the installation and configuration as possible, and today the portion I wanted to script was the creation of a SQL Alias. I’m sure everyone has read my wonderful blog post onCreating a SQL Alias for SharePoint, but that’s a manual process ?

Enter PowerShell!

I found a few threads that discussed doing this, but none detailed the steps 100 percent. I did a little digging with the SQL Server Client Network Utility and the registry, and came up with the script below. Using this I’m able to create the same alias for both x86 and x64 SQL connections on every machine!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#This is the name of your SQL Alias
$AliasName = "Alias2"
#This is the name of your SQL server (the actual name!)
$ServerName = "ServerName2"
#These are the two Registry locations for the SQL Alias locations
$x86 = "HKLM:\Software\Microsoft\MSSQLServer\Client\ConnectTo"
$x64 = "HKLM:\Software\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo"
#We're going to see if the ConnectTo key already exists, and create it if it doesn't.
if ((test-path -path $x86) -ne $True)
{
    write-host "$x86 doesn't exist"
    New-Item $x86
}
if ((test-path -path $x64) -ne $True)
{
    write-host "$x64 doesn't exist"
    New-Item $x64
}
#Adding the extra "fluff" to tell the machine what type of alias it is
$TCPAlias = "DBMSSOCN," + $ServerName
$NamedPipesAlias = "DBNMPNTW,\\" + $ServerName + "\pipe\sql\query"
#Creating our TCP/IP Aliases
New-ItemProperty -Path $x86 -Name $AliasName -PropertyType String -Value $TCPAlias
New-ItemProperty -Path $x64 -Name $AliasName -PropertyType String -Value $TCPAlias
#Creating our Named Pipes Aliases
New-ItemProperty -Path $x86 –Name $AliasName -PropertyType String -Value $NamedPipesAlias
New-ItemProperty -Path $x64 –Name $AliasName -PropertyType String -Value $NamedPipesAlias

Enjoy!

 

#http://habaneroconsulting.com/Insights/Create-a-SQL-Alias-with-a-PowerShell-Script.aspx#.Uefeq43IZd0

SQL alias for SharePoint 2010