How to build a Ruby hash out of two equally-sized arrays?
h = Hash[a.zip b] # => {:baz=>1, :bof=>2, :bar=>”world”, :foo=>”hello”} …damn, I love Ruby.
h = Hash[a.zip b] # => {:baz=>1, :bof=>2, :bar=>”world”, :foo=>”hello”} …damn, I love Ruby.
window.location.hash=”something”; That is just plain JavaScript. Your comment… Hi, what I really need is to add only the hash… something like this: window.location.hash=”#”; but in this way nothing is added. Try this… window.location = ‘#’; Also, don’t forget about the window.location.replace() method.
I think you are looking for the Dictionary object, found in the Microsoft Scripting Runtime library. (Add a reference to your project from the Tools…References menu in the VBE.) It pretty much works with any simple value that can fit in a variant (Keys can’t be arrays, and trying to make them objects doesn’t make … Read more
The input material can be an infinite length, where the output is always 128 bits long. This means that an infinite number of input strings will generate the same output. If you pick a random number and divide it by 2 but only write down the remainder, you’ll get either a 0 or 1 — … Read more
For a set of even billions of assets, the chances of random collisions are negligibly small — nothing that you should worry about. Considering the birthday paradox, given a set of 2^64 (or 18,446,744,073,709,551,616) assets, the probability of a single MD5 collision within this set is 50%. At this scale, you’d probably beat Google in … Read more
ages = { ‘Bruce’ => 32, ‘Clark’ => 28 } mappings = { ‘Bruce’ => ‘Bruce Wayne’, ‘Clark’ => ‘Clark Kent’ } ages.transform_keys(&mappings.method(:[])) #=> { ‘Bruce Wayne’ => 32, ‘Clark Kent’ => 28 }
For those who want a “standard” text formatting of the hash, you can use something like the following: static string Hash(string input) { using (SHA1Managed sha1 = new SHA1Managed()) { var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(input)); var sb = new StringBuilder(hash.Length * 2); foreach (byte b in hash) { // can be “x2” if you want lowercase … Read more
2305843009213693951 is 2^61 – 1. It’s the largest Mersenne prime that fits into 64 bits. If you have to make a hash just by taking the value mod some number, then a large Mersenne prime is a good choice — it’s easy to compute and ensures an even distribution of possibilities. (Although I personally would … Read more
I would personally avoid XOR – it means that any two equal values will result in 0 – so hash(1, 1) == hash(2, 2) == hash(3, 3) etc. Also hash(5, 0) == hash(0, 5) etc which may come up occasionally. I have deliberately used it for set hashing – if you want to hash a … Read more
OAuth says nothing about token except that it has a secret associated with it. So all the schemes you mentioned would work. Our token evolved as the sites get bigger. Here are the versions we used before, Our first token is an encrypted BLOB with username, token secret and expiration etc. The problem is that … Read more