[TestMethod]
public void Test() => Assert.IsTrue(FindDifference(new[]{ 1, 2, 3 }, new []{2,4,6}) is [[1,3], [4,6]]);
public IList<ILis<int>> FindDifference(int[] nums1, int[] nums2)
{
var s1 = new HashSet<int>();
var s2 = new HashSet<int>();
var set1 = new HashSet<int>(nums1);
var set2 = new HashSet<int>(nums2);
foreach (var n2 in nums2)
if(!set1.Contains(n2)) s2.Add(n2);
foreach (var n1 in nums1)
if(!set2.Contains(n1)) s1.Add(n1);
return new List<IList<int>> { s1.ToList(), s2.ToList() };
}
Wednesday, May 3, 2023
Is expression pattern matching for list of lists
Tuesday, March 28, 2023
Friday, January 13, 2023
Saturday, December 31, 2022
Saturday, September 25, 2021
alias for git commands
To combine add and commit it is easy to create an alias:
now in command line instead of running
you can run
git config --global alias.ac "commit am"
now in command line instead of running
git commit -am "this is my commit"
you can run
git ac "this is my commit"
Monday, July 19, 2021
Generating pfx file with multiple certificates.
One pfx file can have multiple certificates inside it. In order to create such file, the easiest way is to copy paste all the *.crt files into one file so the file content will be similar to this one:
This is just an example, the certificate section for each certificate will be larger. Let's call such file bundle.crt<\i>. In order to sign it we need a key - key is just a file with a content similar to the *.crt file - some people call it pem files. Generally speaking *.crt, *.pem, *.cert are files that have this same content in this same format, the only difference is just a file extension. To create a pfx file we need an openssl application. You can get the windows binaries from here: ssl binaries. I used the openssl-1.0.2r-x64_86-win64.zip.
To generate pfx I run:
You will need to provide a password for this key and retype it.
If you want to see what is inside pfx you can run:
certutil is a tool that is by default installed on Windows machine. If you have openssl installed you can run:
You need the password in order to run these commands.
-----BEGIN CERTIFICATE----- MA0GCSqGSIb3DQEBCwUAA4IBAQAIfmyTEMg4uJapkEv/oV9PBO9sPpyIBslQj6Zz 91cxG7685C/b+LrTW+C05+Z5Yg4MotdqY3MxtfWoSKQ7CC2iXZDXtHwlTxFWMMS2 RJ17LJ3lXubvDGGqv+QqG+6EnriDfcFDzkSnE3ANkR/0yBOtg2DZ2HKocyQetawi DsoXiWJYRBuriSUBAA/NxBti21G00w9RKpv0vHP8ds42pM3Z2Czqrpv1KrKQ0U11 GIo/ikGQI31bS/6kA1ibRrLDYGCD+H1QQc7CoZDDu+8CL9IVVO5EFdkKrqeKM+2x LXY2JtwE65/3YR8V3Idv7kaWKK2hJn0KCacuBKONvPi8BDDD -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- GGGEfTCCA2WgAwIBAgIDG+cVMA0GCSqGSIb3DQEBCwUAMGMxCzAJBgNVBAYTAlVT MSEwHwYDVQQKExhUaGUgR28gRGFkZHkgR3JvdXAsIEluYy4xMTAvBgNVBAsTKEdv IERhZGR5IENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQwMTAx MDcwMDAwWhcNMzEwNTMwMDcwMDAwWjCBgzELMAkGA1UEBhMCVVMxEDAOBgNVBAgT -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- AAAEfTCCA2WgAwIBAgIDG+cVMA0GCSqGSIb3DQEBCwUAMGMxCzAJBgNVBAYTAlVT MSEwHwYDVQQKExhUaGUgR28gRGFkZHkgR3JvdXAsIEluYy4xMTAvBgNVBAsTKEdv IERhZGR5IENsYXNzIDIgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTQwMTAx MDcwMDAwWhcNMzEwNTMwMDcwMDAwWjCBgzELMAkGA1UEBhMCVVMxEDAOBgNVBZZZ -----END CERTIFICATE-----
This is just an example, the certificate section for each certificate will be larger. Let's call such file bundle.crt<\i>. In order to sign it we need a key - key is just a file with a content similar to the *.crt file - some people call it pem files. Generally speaking *.crt, *.pem, *.cert are files that have this same content in this same format, the only difference is just a file extension. To create a pfx file we need an openssl application. You can get the windows binaries from here: ssl binaries. I used the openssl-1.0.2r-x64_86-win64.zip.
To generate pfx I run:
openssl pkcs12 -export -out Private.pfx -inkey C:\cert.key -in C:\bundle.crt
You will need to provide a password for this key and retype it.
If you want to see what is inside pfx you can run:
certutil -dump Private.pfx
certutil is a tool that is by default installed on Windows machine. If you have openssl installed you can run:
openssl pkcs12 -info -in Private.pfx
You need the password in order to run these commands.
Tuesday, November 17, 2020
Check password policy in AD
You need to install first Active Directory Powershell cmdlets on Windows 10. This cmdlets alloweds a user to check the policy.
With a cmdlets you can call
Get-WindowsCapability -Online | Where-Object {$_.Name -like "*ActiveDirectory.DS-LDS*"} | Add-WindowsCapability -Online
With a cmdlets you can call
get-addomain | get-adobject -properties * | select *pwd*
Saturday, August 22, 2020
Block npm from running postinstall scripts
Every npm package when it install is capable of executing an arbitrary code (running on node) on you machine.
package.json
This is a potential backdoor. I bet that sooner or later someone is going to take adventage of it. In order to block npm packages from doing it you can run this command on your machine.
package.json
"scripts": {
"postinstall: "virtus.js"
}
This is a potential backdoor. I bet that sooner or later someone is going to take adventage of it. In order to block npm packages from doing it you can run this command on your machine.
npm config set ignore-scripts true
Thursday, August 20, 2020
Conda virtual environment management
To list all env:
To create:
To create with a specific version of python
To activate:
To go back to base env:
conda env list
To create:
conda create --name myenv
To create with a specific version of python
conda create -n myenv python=3.6
To activate:
conda activate myenv
To go back to base env:
conda deactivate
Thursday, May 28, 2020
Running chrome with CORS disabled
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --disable-web-security --disable-gpu --user-data-dir=~/chromeTemp
Thursday, May 14, 2020
Example of dockerfile and how to bake in locally.
FROM mcr.microsoft.com/dotnet/core/sdk:3.1
Add bin/Debug/netcoreapp3.1/publish /var/foo/bin
WORKDIR /var/foo/bin
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000
ENTRYPOINT ["dotnet", "Company.Project.dll"]
To bake in solution file folder run
dotnet publish
In *.csproj folder run
docker build -t testingdocker .
docker run -lt testingdocker --entrypoint bin/bash
Notice that there is a dot (.)
Monday, May 11, 2020
AZ and kubectl commands to save a day
kubectl commands run in a context of Azure account. On a fresh machine, one needs to first install az command line and login to azure, with an azure username (in many companies it is a sys account).
when you run
You should see something similar to:
name property is important because it is an active subscription against which kubectl commands will run. You can change it by running:
you can pull resource group to be able to manage it, by running:
now you are able to manage all pods, by running:
or
where foo-dev is a namespace. To get all events you can run
az login
when you run
az account show
You should see something similar to:
{
"environmentName": "AzureCloud",
"homeTenantId": "ced47777-d73a-4514-a74d-63af7885ff7d",
"id": "a75c7777-66c1-4373-a0f3-859abaefcccc",
"isDefault": true,
"managedByTenants": [],
"name": "Company - Development - DEV",
"state": "Enabled",
"tenantId": "ccc47db0-d73a-4514-a74d-63af7885ff7d",
"user": {
"name": "ME@mycompany.com",
"type": "user"
}
}
name property is important because it is an active subscription against which kubectl commands will run. You can change it by running:
az account set --subscription "Company - Production - LIVE"
you can pull resource group to be able to manage it, by running:
az aks get-credentials --name platform-aks-dev-ne --resource-group platform-aks-dev-rg-ne
now you are able to manage all pods, by running:
kubectl get pods
or
kubectl get pods -n foo-dev
where foo-dev is a namespace. To get all events you can run
kubectl get events --namespace foo-dev
Tuesday, January 15, 2019
Deleting old records in large table in SQL Server
Let's face it DELETE command is really slow. It is often quite a challenge to delete multiple records. If there is no WHERE clause then it is much better to use TRUNCATE, but if you have to use WHERE you are back to square one :). This is my approach how to use DELETE command on a large set of data:
DECLARE @rows INT = 1
SET @rows = 1
WHILE @rows > 0
BEGIN
DELETE TOP (5000) [dbo].[MyLog]
WHERE CreationDateTime <= DATEADD(MONTH, - 6, GETDATE())
SET @rows = @@ROWCOUNT;
END
Tuesday, April 3, 2018
ORA-01795: maximum number of expressions in a list is 1000
ORA-01795: maximum number of expressions in a list is 1000
01795. 00000 - "maximum number of expressions in a list is 1000"
*Cause: Number of expressions in the query exceeded than 1000.
Note that unused column/expressions are also counted
Maximum number of expressions that are allowed is 1000.
*Action: Reduce the number of expressions in the list and resubmit.
Error at Line: 1,002 Column: 1
This is one of the differences between SQL server (management studio) and Oracle (Oracle SQL developer). It is especially problematic when I have a list of values in where statement. Use SQL server whenever possible.
Friday, March 9, 2018
github user set localy for the project
Often git user that I use on my machine is related with the company that I am working for. Sometimes I need to access my personal repositories to get some useful code, snipped or component that I can use. Sometimes during this process I modify something in that component and I want to push it to github as me and not as a different git user. Important part is to set local git preferences for the project; following commands are useful:
Edit local config, set github username and email address to the one that is used in github.
Set following fields:
git config -llist all the config for gitgit config -l --locallist config that is specific for given projectgit config -l --globallist global configurationEdit local config, set github username and email address to the one that is used in github.
git config -e --localSet following fields:
[user] email = foobar@gmail.com name = FirstName LastName
Not being able to login to npm -- npm adduser not working
In various organisations it is common to code in environment that requires you to connect to a organisation specific repository or to use a specific user. Sometimes you want to push your package to a global npm (https://registry.npmjs.org/) repository and the process doesn't work. What I enjoy doing is to setup a local .npmrc file inside a project structure. Inside it I specify the registry configuration like:
adduser command runs in a scope of a registry. Often when you try to use it it tells you that your username doesn't exist, or user was incorrect because you were verifying against a server that is specified by registry parameter. Without running adduser command often your environment will pickup user credentials that are specified by your systeadmins and are related to a registry that is specific for the organization. That's why when you run following command w/o running ever adduser it often displays username:

If you run adduser command in a directory that has registry set to a different location your result will be different:

It is worth noticing that adduser command doesn't add any lines to local .npmrc file. File will only contain registry entry.
registry = "https://registry.npmjs.org/"adduser command runs in a scope of a registry. Often when you try to use it it tells you that your username doesn't exist, or user was incorrect because you were verifying against a server that is specified by registry parameter. Without running adduser command often your environment will pickup user credentials that are specified by your systeadmins and are related to a registry that is specific for the organization. That's why when you run following command w/o running ever adduser it often displays username:
If you run adduser command in a directory that has registry set to a different location your result will be different:
It is worth noticing that adduser command doesn't add any lines to local .npmrc file. File will only contain registry entry.
Wednesday, October 25, 2017
Windows Cannot Install Required Files. Make sure all the files required for installation are available, and restart the installation. Error code: 0x8007025D
Windows Cannot Install Required Files. Make sure all the files required for installation are available and restart the installation. Error code: 0x8007025D
Usually, people connect this problem with media error - your installation source is corrupted. Microsoft and various guids recommend creating new installation CD or USB. In my case, it was my hard drive. I had to delete the partition and experiment with splitting original partition into smaller ones. The goal is to have one as big partition as possible that is healthy - because Program Files folder grows exponentialy :) It took me some time (in days) to finally get it right.
Friday, September 8, 2017
Floating point arithmetic in 21 century
I really hope that entire concept will be dropped one day. Current approach was useful 30 years ago, now we have much more memory and we can do it in a much better way. And yet when I look at JavaScript:
It is all beacause of 0.1 representation in IEEE standard.
The exponent is 64+32+16+8+2+1 = 123 - 127 bias = -4, so the multiplier is 2-4 or 1/16.
The mantissa is chunky. It consists of 1 (the implicit base) plus (for all those bits with each being worth 1/(2n) as n starts at 1 and increases to the right), {1/2, 1/16, 1/32, 1/256, 1/512, 1/4096, 1/8192, 1/65536, 1/131072, 1/1048576, 1/2097152, 1/8388608}.
When you add all these up, you get 1.60000002384185791015625.
When you multiply that by the multiplier, you get 0.100000001490116119384765625, which is why they say you cannot represent 0.1 exactly as an IEEE754 float.
0.1 + 0.2 === 0.3 //false
(0.1 + 0.2) + 0.3 === 0.1 + (0.2 + 0.3) //false
It is all beacause of 0.1 representation in IEEE standard.
s eeeeeeee mmmmmmmmmmmmmmmmmmmmmmm 1/n
0 01111011 10011001100110011001101
| || || || || || +- 8388608
| || || || || |+--- 2097152
| || || || || +---- 1048576
| || || || |+------- 131072
| || || || +-------- 65536
| || || |+----------- 8192
| || || +------------ 4096
| || |+--------------- 512
| || +---------------- 256
| |+------------------- 32
| +-------------------- 16
+----------------------- 2
The sign is positive, that's pretty easy.The exponent is 64+32+16+8+2+1 = 123 - 127 bias = -4, so the multiplier is 2-4 or 1/16.
The mantissa is chunky. It consists of 1 (the implicit base) plus (for all those bits with each being worth 1/(2n) as n starts at 1 and increases to the right), {1/2, 1/16, 1/32, 1/256, 1/512, 1/4096, 1/8192, 1/65536, 1/131072, 1/1048576, 1/2097152, 1/8388608}.
When you add all these up, you get 1.60000002384185791015625.
When you multiply that by the multiplier, you get 0.100000001490116119384765625, which is why they say you cannot represent 0.1 exactly as an IEEE754 float.
Wednesday, September 6, 2017
choreography vs orchestration
I see in more and more articles that authors are using both terms interchangeably. As far as I can tell there is no formal definition, just like with terms agile, microservices, SOA, but... in ancient days when I was studding computer science on a university there was a difference:
- choreography: distributed decision making
- orchestration: centralised decision making
Monday, September 4, 2017
JavaScript Exceptions vs. Errors
A JavaScript exception is a value that is thrown as a result of an invalid operation or as the target of a throw statement. While it is not required that these values are instances of Error or classes which inherit from Error, all exceptions thrown by Node.js or the JavaScript runtime will be instances of Error.
Some exceptions are unrecoverable at the JavaScript layer. Such exceptions will always cause the Node.js process to crash.
This is why you can write:
Some exceptions are unrecoverable at the JavaScript layer. Such exceptions will always cause the Node.js process to crash.
This is why you can write:
throw new Exception("foo bar");
throw "foo bar";
Subscribe to:
Posts (Atom)


