Skip to content

Instantly share code, notes, and snippets.

View akhansari's full-sized avatar
🦎

Amin Khansari akhansari

🦎
View GitHub Profile
@akhansari
akhansari / GetHashCode.md
Last active December 15, 2017 23:49
Guidelines and rules for GetHashCode

Guidelines and rules for GetHashCode

What is GetHashCode used for?

It is by design useful for only one thing: putting an object in a hash table. Hence the name.

Why do we have this method on Object in the first place?

It makes perfect sense that every object in the type system should provide a GetType method; data's ability to describe itself is a key feature of the CLR type system. And it makes sense that every object should have a ToString, so that it is able to print out a representation of itself as a string, for debugging purposes. It seems plausible that objects should be able to compare themselves to other objects for equality. But why should it be the case that every object should be able to hash itself for insertion into a hash table? Seems like an odd thing to require every object to be able to do.

// class
var Greeter = (function () {
// constructor
function Greeter(message) {
// public variable
this.greeting = message;
@akhansari
akhansari / XmlTools.iss
Last active February 24, 2022 08:12
Xml tools for InnoSetup
[Code]
function LoadValueFromXML(const AFileName, APath: string): string;
var
XMLNode: Variant;
XMLDocument: Variant;
begin
Log('Get Xml text node: ' + AFileName);
Result := '';
@akhansari
akhansari / Hash.cs
Last active July 27, 2023 09:52
Generating a Hash from a string.
public string Hash(string str)
{
return string.Join("", System.Security.Cryptography.SHA256.Create()
.ComputeHash(System.Text.Encoding.UTF8.GetBytes(str)).Select(s => s.ToString("x2")));
}
1078 af
1052 sq
14337 ar-ae
15361 ar-bh
5121 ar-dz
3073 ar-eg
2049 ar-iq
11265 ar-jo
13313 ar-kw