How is the Git hash calculated?

As described in “How is git commit sha1 formed “, the formula is: (printf “<type> %s\0” $(git cat-file <type> <ref> | wc -c); git cat-file <type> <ref>)|sha1sum In the case of the commit 9eabf5b536662000f79978c4d1b6e4eff5c8d785 (which is v2.4.2^{}, and which referenced a tree) : (printf “commit %s\0” $(git cat-file commit 9eabf5b536662000f79978c4d1b6e4eff5c8d785 | wc -c); git cat-file … Read more

How to reliably hash JavaScript objects?

You might be interested in npm package object-hash, which seems to have a rather good activity & reliability level. var hash = require(‘object-hash’); var testobj1 = {a: 1, b: 2}; var testobj2 = {b: 2, a: 1}; var testobj3 = {b: 2, a: “1”}; console.log(hash(testobj1)); // 214e9967a58b9eb94f4348d001233ab1b8b67a17 console.log(hash(testobj2)); // 214e9967a58b9eb94f4348d001233ab1b8b67a17 console.log(hash(testobj3)); // 4a575d3a96675c37ddcebabd8a1fea40bc19e862

how to check if a hash is empty in perl

if (%hash) Will work just fine. From perldoc perldata: If you evaluate a hash in scalar context, it returns false if the hash is empty. If there are any key/value pairs, it returns true; more precisely, the value returned is a string consisting of the number of used buckets and the number of allocated buckets, … Read more

Why and how are Python functions hashable?

It’s nothing special. As you can see if you examine the unbound __hash__ method of the function type: >>> def f(): pass … >>> type(f).__hash__ <slot wrapper ‘__hash__’ of ‘object’ objects> the of ‘object’ objects part means it just inherits the default identity-based __hash__ from object. Function == and hash work by identity. The difference … Read more

Asking “is hashable” about a Python value

Python 3.x Use collections.abc.Hashable or typing.Hashable. >>> import typing >>> isinstance({}, typing.Hashable) False >>> isinstance(0, typing.Hashable) True Note: both are the same one, the latter is simply an alias of the former. Also note that collections.Hashable was removed in Python 3.10+ (deprecated since 3.7). Python 2.6+ (an original answer) Since Python 2.6 you can use … Read more

How to send password securely via HTTP using Javascript in absence of HTTPS?

There is no way to send a password securely that the user can verify without SSL. Sure, you can write some JavaScript that will make a password secure for over-the-wire transmission through hashing or public-key-encryption. But how can the user be sure that the JavaScript itself has not been tampered with by a man-in-the-middle before … Read more

How can I SHA512 a string in C#?

Your code is correct, but you should dispose of the SHA512Managed instance: using (SHA512 shaM = new SHA512Managed()) { hash = shaM.ComputeHash(data); } 512 bits are 64 bytes. To convert a string to a byte array, you need to specify an encoding. UTF8 is okay if you want to create a hash code: var data … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)