hash

How Can I Convert Nested YAML to nested Arrays and OpenStructs in Ruby

拈花ヽ惹草 提交于 2020-01-05 09:46:09
问题 How should I convert a series of nested hashes (nested to arbitrary depth) to a series of nested OpenStructs? I'm loading in a big YAML file and I'm not enjoying accessing['everything']['like']['this'] . I have found a few partial solutions using Google, but I thought this would make a nice question here. Here is one of the solutions I found from http://andreapavoni.com/blog/2013/4/create-recursive-openstruct-from-a-ruby-hash: # deep_struct.rb require 'ostruct' class DeepStruct < OpenStruct

Ruby - keys of one hash into values of another hash

二次信任 提交于 2020-01-05 09:36:28
问题 I have to hashes like so: hash1 = { "a" => 1, "b" => 1, "c" => 1, "d" => 1 } hash2 = { "1" => 1, "2" => 1, "3" => 1, "4" => 1 } And I need to merge them so I end up with this: hash1 = { "a" => "1", "b" => "2", "c" => "3", "d" => "4" } But I don't know where to begin. Help appreciated. 回答1: You can try the following: Hash[hash1.keys.zip(hash2.keys)] At first , you get array of keys for each hash with hash1.keys and hash2.keys : ["a", "b", "c", "d"] ["1", "2", "3", "4"] Secondly , you create an

Unordered map for unique keys and hashing

╄→尐↘猪︶ㄣ 提交于 2020-01-05 09:15:21
问题 I am working in a library in which some elements, that do not matter here, must be identified with a name (i.e. values are associated to names). Names are strings for the user, whatever their internal representation is, and should behave transparently. Names are constant and initialized with strings literals. They are known at compile-time. Two names that were initialized with different strings must compare different , whatever their internal representation is. Names may be of arbitrary

Unordered map for unique keys and hashing

北慕城南 提交于 2020-01-05 09:15:12
问题 I am working in a library in which some elements, that do not matter here, must be identified with a name (i.e. values are associated to names). Names are strings for the user, whatever their internal representation is, and should behave transparently. Names are constant and initialized with strings literals. They are known at compile-time. Two names that were initialized with different strings must compare different , whatever their internal representation is. Names may be of arbitrary

Hashing a string vs Hashing a UInt8Array

别来无恙 提交于 2020-01-05 08:27:43
问题 I'm comparing the performance of two MD5 libraries. When I send them both a string, they return the same hash: Hashing data with 'md5' library... Hash: d8b1e68f2f36743cdf302ed36f9347dc Duration: 0.003s Hashing data with 'create-hash' library... Hash: d8b1e68f2f36743cdf302ed36f9347dc Duration: 0.003s However, when I send them the same UInt8Array, they give me different hashes: Hashing data with 'md5' library... Hash: 77fcf76d3f8c6a0f685f784d7ca6c642 Duration: 0.001s Hashing data with 'create

Find hash algorithm?

不羁的心 提交于 2020-01-05 08:15:17
问题 I'm trying to find out which method of hashing was used to generate certain strings. It's 32 bits (4 Bytes). Found out it was DBJ v1. Any idea how to implement in C#? Thanks :) Example Hashes: 00 02 B5 D5 - hash 30 - string 35 A0 FD 6A - hash 6F 66 66 65 6E 73 69 76 - string 05 7B DC 6C - hash 70 6C 61 79 65 72 20 75 73 65 64 20 6F 66 66 65 6E 73 69 76 65 20 6C 61 6E 67 75 61 67 65 - string This is important so thank you! 来源: https://stackoverflow.com/questions/15726046/find-hash-algorithm

How to securely store a password without hashes?

你。 提交于 2020-01-05 06:37:20
问题 I want to have a way of authenticating an user (which introduces his password) without having that password stored in plain text or even a hash of it. How should I do it? Is it secure to have a control string that the user key can cipher and compare it with the ciphered string that I have stored? 回答1: Per NIST (National Institute of Standards and Technology): Use a hash function, iterate over an HMAC with a random salt for about a 100ms duration and save the salt with the hash. Use functions

How to #include hash with ext, tr1, or __gnu_cxx in XCode, C++

╄→尐↘猪︶ㄣ 提交于 2020-01-05 05:53:28
问题 I'm trying to work with the google-sparsehash library and I'd like to include the hash library described in the link, using ext::hash; // or __gnu_cxx::hash, or maybe tr1::hash, depending on your OS and I've tried one of each: #include <ext/hash> #include <ext> #include <__gnu_cxx> #include <tr1> which none worked with XCode. I've also "using", where I was told that __gnu_cxx does not contain "hash". How do I describe this library to XCode (3.2.6) on OS X (10.6.8)? Or more generally, where is

Ruby: Extract elements from deeply nested JSON structure based on criteria

﹥>﹥吖頭↗ 提交于 2020-01-05 05:38:05
问题 Want to extract every marketID from every market that has a marketName == 'Moneyline' . Tried a few combinations of .map s, .reject s, and/or .select s but can't narrow it down as the complicated structure is confusing me. There are many markets in events , and there are many events as well. A sample of the structure (tried to edit it for brevity): {"currencyCode"=>"GBP", "eventTypes"=>[ {"eventTypeId"=>6423, "eventNodes"=>[ {"eventId"=>28017227, "event"=> {"eventName"=>"Philadelphia @

Which value for a duplicate key is ignored in a Ruby hash?

♀尐吖头ヾ 提交于 2020-01-05 02:52:08
问题 If a hash has more than one occurrences of identical keys pointing to different values, then how does Ruby determine which value is assigned to that key? In other words, hash = {keyone: 'value1', keytwo: 'value2', keyone: 'value3'} results in warning: duplicated key at line 1 ignored: :keyone but how do I know which value is assigned to :keyone ? 回答1: The last one overwrites the previous values. In this case, "value3" becomes the value for :keyone . This works just as the same with merge .