public class MySingleton { private static object myLock = new object(); private static volatile MySingleton mySingleton = null; // 'volatile' is unnecessary in .NET 2.0 and later private MySingleton() { } public static MySingleton GetInstance() { if (mySingleton == null) { // 1st check lock (myLock) { if (mySingleton == null) { // 2nd (double) check mySingleton = new MySingleton(); } } } return mySingleton; } }
Thursday, September 25, 2014
Double check singleton design pattern
Friday, May 16, 2014
Get SQL Server user's roles
SELECT
p.NAME, m.NAME
FROM sys.database_role_members rm
JOIN sys.database_principals p ON rm.role_principal_id = p.principal_id
JOIN sys.database_principals m ON rm.member_principal_id = m.principal_id
p.NAME, m.NAME
FROM sys.database_role_members rm
JOIN sys.database_principals p ON rm.role_principal_id = p.principal_id
JOIN sys.database_principals m ON rm.member_principal_id = m.principal_id
Tuesday, October 8, 2013
IIS Windows Authentification Web Site Keeps Asking for Credentials
Problem:
Although the provided credentials are valid, IIS keeps prompting for credentials.
Solution:
Disable the loopback check by setting the DisableLoopbackCheck registry key.
To set the DisableLoopbackCheck registry key, follow these steps:
Source: http://support.microsoft.com/kb/896861
Although the provided credentials are valid, IIS keeps prompting for credentials.
Solution:
Disable the loopback check by setting the DisableLoopbackCheck registry key.
To set the DisableLoopbackCheck registry key, follow these steps:
- Set the DisableStrictNameChecking registry entry to 1.
- Click Start, click Run, type regedit, and then click OK.
- In Registry Editor, locate and then click the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
- Right-click Lsa, point to New, and then click DWORD Value.
- Type DisableLoopbackCheck, and then press ENTER.
- Right-click DisableLoopbackCheck, and then click Modify.
- In the Value data box, type 1, and then click OK.
- Quit Registry Editor, and then restart your computer.
Source: http://support.microsoft.com/kb/896861
Tuesday, September 24, 2013
Convert a Generic List to DataTable
public static DataTable ToDataTable<T>(this IList<T> data)
{
PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));
DataTable table = new DataTable();
for(int i = 0 ; i < props.Count ; i++)
{
PropertyDescriptor prop = props[i];
table.Columns.Add(prop.Name, prop.PropertyType);
}
object[] values = new object[props.Count];
foreach (T item in data)
{
for (int i = 0; i < values.Length; i++)
{
values[i] = props[i].GetValue(item);
Thursday, August 15, 2013
Friday, June 21, 2013
test
apTRBF{i} = apTotRBF;
clfsTRBF{i} = clfsOutRBF;
accRBF{i} = accuracyRBF;
ccRBF{i} = confusionRBF;
end
meanTotal = zeros(1,25);
for i=1:25
meanTotal(i) = mean(accRBF{i});
end
mean(meanTotal)
savePath = sprintf('%ssave_HOF_baseline_4_pyr.mat',path);
save(savePath,'accRBF','ccRBF','apTRBF','clfsTRBF')
clfsTRBF{i} = clfsOutRBF;
accRBF{i} = accuracyRBF;
ccRBF{i} = confusionRBF;
end
meanTotal = zeros(1,25);
for i=1:25
meanTotal(i) = mean(accRBF{i});
end
mean(meanTotal)
savePath = sprintf('%ssave_HOF_baseline_4_pyr.mat',path);
save(savePath,'accRBF','ccRBF','apTRBF','clfsTRBF')
Monday, June 17, 2013
test
image1 = image(1:80,1:100,:);
image2 = image(1:80,100:200,:);
image3 = image(1:80,200:300,:);
image4 = image(1:80,300:400,:);
image5 = image(80:160,1:100,:);
image6 = image(80:160,100:200,:);
image7 = image(80:160,200:300,:);
image8 = image(80:160,300:400,:);
image9 = image(160:240,1:100,:);
image10 = image(160:240,100:200,:);
image11 = image(160:240,200:300,:);
image12 = image(160:240,300:400,:);
image13 = image(240:320,1:100,:);
image14 = image(240:320,100:200,:);
image15 = image(240:320,200:300,:);
image16 = image(240:320,300:400,:);
%320x400
descriptorsCN1 = extractColorNamingHist(image1,y,w2c)';
descriptorsCN2 = extractColorNamingHist(image2,y,w2c)';
descriptorsCN3 = extractColorNamingHist(image3,y,w2c)';
descriptorsCN4 = extractColorNamingHist(image4,y,w2c)';
descriptorsCN5 = extractColorNamingHist(image5,y,w2c)';
descriptorsCN6 = extractColorNamingHist(image6,y,w2c)';
descriptorsCN7 = extractColorNamingHist(image7,y,w2c)';
descriptorsCN8 = extractColorNamingHist(image8,y,w2c)';
descriptorsCN9 = extractColorNamingHist(image9,y,w2c)';
descriptorsCN10 = extractColorNamingHist(image10,y,w2c)';
descriptorsCN11 = extractColorNamingHist(image11,y,w2c)';
descriptorsCN12 = extractColorNamingHist(image12,y,w2c)';
descriptorsCN13 = extractColorNamingHist(image13,y,w2c)';
descriptorsCN14 = extractColorNamingHist(image14,y,w2c)';
descriptorsCN15 = extractColorNamingHist(image15,y,w2c)';
descriptorsCN16 = extractColorNamingHist(image16,y,w2c)';
descriptorsCN = [descriptorsCN1 descriptorsCN2 descriptorsCN3 descriptorsCN4 descriptorsCN5 descriptorsCN6 descriptorsCN7 descriptorsCN8 descriptorsCN9 descriptorsCN10 descriptorsCN11 descriptorsCN12 descriptorsCN13 descriptorsCN14 descriptorsCN15 descriptorsCN16];
descriptorsAllCN(j,:) = descriptorsCN;
Subscribe to:
Posts (Atom)