hash

Using ruby 'or equals' ||= on methods that return a hash or nil

I have a method that returns a hash, or nil: def person_of_age(age) some_hash = @array_of_hashes.select { |h| h.age == age }.last return some_hash end I want to use this hash like so: my_height = 170 my_age = 30 if my_height < self.person_of_age(my_age)['height'] puts "You are shorter than another person I know of the same age!"...

Do i need to modify all links in order to ajaxify this website ?

I built this website using ajax (via jquery) instead of full page refresh. Right now, it does not support the browser's back/next buttons, nor deeplink bookmarking. I'd like to implement these functionalities, using for instance the jquery bbq plugin but i'm not sure i understand completely the concept. The main point i'm missing is thi...

Convert Object to Hash Object in Mootools?

Hello! Is it possible to convert/reassemble the Object to Hash Object? For example and firstly, i have two arrays: ... var animals=[]; //... "cat","dog","cow" var sounds=[]; //.. "meow!","woof!","moo!" var u = animals.associate(sounds); // now "u" is an Object with associative values: "cat" : "meow!" "dog" : "woof!" "cow" : "moo!";...

Recursively merge multidimensional arrays, hashes and symbols

I need a chunk of Ruby code to combine an array of contents like such: [{:dim_location=>[{:dim_city=>:dim_state}]}, :dim_marital_status, {:dim_location=>[:dim_zip, :dim_business]}] into: [{:dim_location => [:dim_business, {:dim_city=>:dim_state}, :dim_zip]}, :dim_marital_status] It needs to support an arbitrary level of depth, ...

Searching in a subhash with Ruby on Rails

I have a hash of hashes like so: Parameters: {"order"=>{"items_attributes"=>{"0"=>{"product_name"=>"FOOBAR"}}}} Given that the depth and names of the keys may change, I need to be able to extract the value of 'product_name' (in this example "FOOBAR") with some sort of search or select method, but I cannot seem to figure it out. An ad...

How do I dereference a Perl hash reference that's been passed to a subroutine?

I'm still trying to sort out my hash dereferencing. My current problem is I am now passing a hashref to a sub, and I want to dereference it within that sub. But I'm not finding the correct method/syntax to do it. Within the sub, I want to iterate the hash keys, but the syntax for a hashref is not the same as a hash, which I know how t...

C++, what is a good way to hash array data?

hello I have a curious problem and I am brainstorming possible solutions. The problem is such: I have a number of inputs (up to several thousand different ones), which basically differ in two-three arrays (arrays are a different size generaly, from size one up to couple thousand elements long). the functions which process arrays take s...

can I do hash.has_key?('video' or 'video2') (ruby)

or even better can I do hash.has_key?('videox') where x is '' nothing or a digit? so 'video', 'video1', 'video2' would pass the condition? of course I can have two conditions but in case I need to use video3 in the future things would get more complicated... ...

Facebook page serving, bookmark ajax hashes, but no redirection when JS disabled

Hi, I would be grateful to find out some really weird things I have seen on facebook URLs If I bookmark this URL (found when JS is enabled) http://www.facebook.com/HumanRightsWatch?v=app_2344061033#!/HumanRightsWatch?v=box_3 Then disable JS I then proceed to revisit the same url e.g. http://www.facebook.com/HumanRightsWatch?v=app_2...

Best way to create a random hash

What is the best way of making a md5 hash for the purpose of storing a session? Also, I am looking for one that works with PHP and works without many extensions added because I want my code to be portable. Also, I have heard of the word nonce, but how do I really use a nonce? ...

bCrypt implementation in Javascript

I'm wondering if anyone has written or come across any implementations of bcrypt in JavaScript. I'm not against writing the code myself but if someone with a stonger background in cryptography has already written one why reinvent the wheel? Especially considering I'd probably come up with a shoddy wheel. [edit]: Following the links pro...

Are there circumstances where a hash algorithm can be guaranteed unique?

If I'm hashing size-constrained similar data (social security numbers, for example) using a hash algorithm with a larger byte size than the data (sha-256, for example), will the hash guarantee the same level of uniqueness as the original data? ...

Ruby - Evaluation woes

I'm trying to evaluate something like this but more complex, but I get a TypeError because apparently you can't convert a hash to a string. Without changing my entire script, is there a decent workaround for this already ugly workaround? hash = { :somestuff => "etc", ... } eval module + "::" + object + "." + function + "(" + hash + ")" ...

A couple of questions about Hash Tables

I've been reading a lot about Hash Tables and how to implement on in C and I think I have almost all the concepts in my head so I can start to code my own, I just have a couple of questions that I have yet to properly understand. As a reference, I've been reading this: http://eternallyconfuzzled.com/jsw_home.aspx 1) As I've read on the...

What is the correct datatype for storing hashed passwords in mysql?

Hello, I am writing an application in ColdFusion where storing passwords is necessary. I plan to hash the passwords on the server (using the SHA512 Hash function in ColdFusion) before inserting them into a password column in my database. I would like to know what datatype to use for the password column. Many thanks! ...

Are there any working implementations of the rolling hash function used in the Rabin-Karp string search algorithm?

I'm looking to use a rolling hash function so I can take hashes of n-grams of a very large string. For example: "stackoverflow", broken up into 5 grams would be: "stack", "tacko", "ackov", "ckove", "kover", "overf", "verfl", "erflo", "rflow" This is ideal for a rolling hash function because after I calculate the first n-gram ha...

How can I make a new, empty hash reference in Perl?

Say I had something like: # %superhash is some predefined hash with more than 0 keys; %hash = (); foreach my $key (keys %superhash){ $superhash{ $key } = %hash; %hash = (); } Would all the keys of superhash point to the same empty hash accessed by %hash or would they be different empty hashes? If not, how can I make sure they...

Django array or list output?

I'm pulling a set of image urls and their respective titles. I've tried creating a hash or associative array, but the data seems to overwrite so I only end up with the last item in the array. For example; thumbnail_list = [] for file in media: thumbnail_list['url'] = file.url thumbnail_list['title'] = file.title I've even tr...

How to make object instance a hash key in Ruby?

I have a class Foo with a few member variables. When all values in two instances of the class are equal I want the objects to be 'equal'. I'd then like these objects to be keys in my hash. When I currently try this, the hash treats each instance as unequal. h = {} f1 = Foo.new(a,b) f2 = Foo.new(a,b) f1 and f2 should be equal at th...

Is it safe to store passwords hashed with MD5CryptoServiceProvider in C#?

We are storing hashed passwords in a database table. We prepend each password with a random salt value and hash using MD5CryptoServiceProvider. Is this safe? I have heard MD5 was "broken". If not, can you recommend an alternate hash method to use (specific .NET framework class)? ...