hash

How to split a hash based on values in Ruby?

I have a hash in Ruby that is storing the word frequency of a string, with the word as the key and the frequency as the value. words = a_string.split(/ /) freqs = Hash.new(0) words.each { |word| freqs[word] += 1 } freqs = freqs.sort_by {|x,y| y } freqs.reverse! freqs.each do |word, freq| puts word+' '+freq.to_s end I've read that...

How can I get name of an object in Perl?

Say I make an object as follows: $object22=new somepackage("stuff"); and later I want to run a subroutine like this: $object22->somesubroutine(); I would like to capture the string "object22" in the subroutine "somesubroutine." I tried: $self=@_; print $self; but that just gave me somepackage=HASH(somehexnumber) Please let me k...

Get hash code for an int and a Nullable<int> pair

Currently I'm using the following class as my key for a Dictionary collection of objects that are unique by ColumnID and a nullable SubGroupID: public class ColumnDataKey { public int ColumnID { get; private set; } public int? SubGroupID { get; private set; } // ... public override int GetHashCode() { var h...

How to generate hash or use encryption to secure the keys in an asp.net mvc application?

EDIT 1 : I think I was not clear myself before and hence could not word it better. So, I am creating a system where I am providing page content to another system via IFRAMEs. A user will login to the other system and that system will set their apiKey and userKey in a cookie on my system so that access will be granted i...

How to make a hash of objects in perl

I would like to be able to store objects in a hash structure so I can work with the name of the object as a variable. Could someone help me make a sub new{ ... } routine that creates a new object as member of a hash? I am not exactly sure how to go about doing this or how to refer to and/or use the object when it is stored like this. I ...

In Perl how do you create and use an array of hashes?

How to do a Perl program that contains an array and that array points a hash? It is like this pictorially, (M1) (M2) ...it goes on |--k1=>v1 |--K1=>v1 |--k2=>v2 |--k2=>v2 I should access that array M1, then the hash it contains inside. (and so on)... ...

Prototype cannot read its own Objects?

I need to parse a URL and be sure there are no duplicate keys in the query string. I've converted the query string to an object using String#toQueryParams() var queryString = this.parseUri(uri).query.toQueryParams(); On an alert, this comes up as [Object object], but... queryString.each(function(e) {... }); I get the error that que...

Compute a hash from a stream of unknown length in C#

What is the best solution in C# for computing an "on the fly" md5 like hash of a stream of unknown length? Specifically, I want to compute a hash from data received over the network. I know I am done receiving data when the sender terminates the connection, so I don't know the length in advance. [EDIT] - Right now I am using md5, but th...

How to visualize Hash data structure in ruby?

I have hash object, that structure looks similar to this: {:category1 => {:subcategory1 => [ {:article => "some article", :date => "2010-04-04"}, ... ], :subc2 => [...] }, :category2 => {...}, ... } How can I visualize it with graph in ruby? Is there a simple method/gem/lib that convert this Hash to DOT? ...

Internationalization for constants-hashes in rails 3

Could you tell me whats the best practice for storing constants with internationalization in rails3? f.e. i want to have a constant-hash for haircolours for my user model: # btw: how can I store such hashes in the locales.yml-files? # en.yml HAIR_COLOURS = { "brown" => 0, "white" => 1, "red" => 2, "dark-brown" => 3...} # de.yml HAIR_C...

Fast hash for std::set<int> of two values?

I am using a std::set<int> for the key of a std map (std::unordered_map<std::Set<int>,float>). I need a hash for this set. The set will always be only two integers, whose values could be up to 2 million. Any ideas on a good and fast hash for such a key as performance is critical? ...

How can I get a key => value out of this foursquare hash?

Here is what it looks like: { "groups" => [ { "venues" => [ { "city" => "Madrid", "address" => "Camino de Perales, s/n", "name" => "Caja Mágica", "stats" => {"herenow"=>"0"}, "geolong" => -3.6894333, "primarycategory" => { "iconurl" => "http://foursquare.com...

What is the correct syntax to use perl array of hashes with regex? example gets hyperlinks from page

@urls= $field =~ /<a.*?href="(.*?)".*?>.*?<\/a>/mgo; #multi-line, global, compile-once @text= $field =~ /<a.*?href=".*?".*?>(.*?)<\/a>/mgo; for ($count=0; $count<(scalar @urls); $count++){ print "\"".$text[$count]."\" goes to ->\"".$url[$count]."\"\n";} What is the correct syntax to make this the same as the previous lines? (@arra...

Iterating hash based on the insertion order?

Don't want to sort the entries. using this does not preserve the order as well foreach my $val (keys %hash) { ... } ...

Java MessageDigest and .NET SHA1Managed - hashes not matching

I have some .net code that generates a SHA1 hash on an xml document and need it to match a SHA1 hash generated on the same xml document in java code. The xml doc is sent to the java system and they generate a hash and match against the one i send to verify they are getting the document I intended them to. Below are the snippets in use ...

Can someone explain how salts help when storing hashed passwords?

I am having difficulty understanding how a salt which is appended to a hash helps improve the security when a database of passwords or other important information is compromised. If the salt is, for example, "hello", and is appended to the password "password" then the salt and password are stored together, "hellopassword" and hashed to ...

Creating a fast hash function for fixed-length input

Hi, Currently I working on a project where some information have to be hashed. As the dataset is huge (millions of records created every day) the algorithm for data transformation has to be fast. The pieces of data that have to be hashed are fixed length (11 decimal numbers - example: 05018144298). So what I would like to know is wheth...

any SHA-3 news?

The NIST 2nd SHA-3 Candidate Conference was held in late August. Has there been any news on the SHA-3 competition entrants that came to light at the conference? ...

Quickly filter a perl hash of hashes

I have a perl hash of hashes like the following: $VAR1 = { 'ID_1' => { 'FILE_B' => '/path/to/file/file1', 'FILE_C' => '/path/to/file/file2', 'FILE_A' => '/path/to/file/file3' }, 'ID_2' => { ...

How do I convert a set of String Hashes into a number evenly distributed from 1 to 5?

I have a set of strings that need to be load-balanced into 1 of 5 positions of a collection containing List<string>. How can I take the string.Hash() and convert that into an Int that is somewhat evenly distributed? I'm asking so I can figure out a solution for this ASP.NET issue. ...