Let's say I have two objects: User and Race.
class User
attr_accessor :first_name
attr_accessor :last_name
end
class Race
attr_accessor :course
attr_accessor :start_time
attr_accessor :end_time
end
Now let's say I create an array of hashes like this:
user_races = races.map{ |race| {:user => race.user, :race => race} }
...
This is the first time I have manipulated hashes and arrays in this way -- and it is working. Basically, for every key there are multiple values that I want to record and then print out in the form "key --> value --> value --> val..."
My code is as follows. I am surprised that it works, so concerned that it works "by mistake". Is this t...
I'm just a newbie to ruby. I've seen a string method (String).hash .
For example, in irb, I've tried
>> "mgpyone".hash
returns
=> 144611910
how does this method works ?
...
I am trying to pass some filters in my params through a form like so:
hidden_field_tag "filters", params[:filters]
For some reason the params get changed in the next page. For example, if params[:filters] used to be...
"filters"=>{"name_like_any"=>["apple"]} [1]
...it gets changed to...
"filters"=>"{\"name_like_any\"=>[\"apple\"]}"...
@aoaoh;
$aoaoh[0][0]{21} = 31;
$aoaoh[0][0]{22} = 31;
$aoaoh[0][0]{23} = 17;
for $k (0 .. $#aoaoh) {
for $i(0.. $#aoaoh) {
for $val (keys %{$aoaoh[$i][$k]}) {
print "$val=$aoaoh[$i][$k]{$val}\n";
}
}
}
The output is:
22=31
21=31
23=17
but i expect it to be
21=31
22=31
...
I'd like to set non-integer primary keys for a table using some kind of hash function. md5() seems to be kind of long (32-characters).
What are some alternative hash functions that perhaps use every letter in the alphabet as well as integers that are perhaps shorter in string length and have low collision rates?
Thanks!
...
I'm looking for a very quick way to generate an alphanumeric unique id for a primary key in a table.
Would something like this work?
def genKey():
hash = hashlib.md5(RANDOM_NUMBER).digest().encode("base64")
alnum_hash = re.sub(r'[^a-zA-Z0-9]', "", hash)
return alnum_hash[:16]
What would be a good way to generate random nu...
I use a Javascript hash object to store a set of numerical counters, set up like this [this is greatly simplified]:
var myHash = {
A: 0,
B: 0,
C: 0
};
Is there a way to make other keys, ones not explicitly in myHash, map to keys that are? For instance, I'd like [again, this is simplified]:
myHash['A_prime']++; // or myHas...
How do I create a reference to the value in a specific hash key. I tried the following but $$foo is empty. Any help is much appreciated.
$hash->{1} = "one";
$hash->{2} = "two";
$hash->{3} = "three";
$foo = \${$hash->{1}};
$hash->{1} = "ONE";
#I want "MONEY: ONE";
print "MONEY: $$foo\n";
...
EDIT Sorry I forgot the most important part here. Each key can have more than one value. Apologies to those who already answered. print and join will be used later to print multiple values for $key on a single line.
In the example code below, assuming that the value $keyvalue is constantly changing, I am attempting to use a single line ...
Of course I know is possible to create a file with a certain size and how to do it. But is it possible to create a file with a certain size and also a certain MD5 fingerprint?
...
I want to use unique hashes for each model rather than ids.
I implemented the following function to use it across the board easily.
import random,hashlib
from base64 import urlsafe_b64encode
def set_unique_random_value(model_object,field_name='hash_uuid',length=5,use_sha=True,urlencode=False):
while 1:
uuid_number = str(ra...
Is there a way to take any number, from say, 1 to 40000 and generate an 8 character hash?
I was thinking of using base_convert but couldn't figure out a way to force it to be an 8 character hash.
Any help would be appreciated! Thanks.
...
I'm searching for strategies one might use to programmatically find files which may be duplicates of each other. Specifically in this case, videos.
I'm not looking for exact matches (as nice as that would be in the land of rainbows and sunshine). I'm just looking to collect pairs of video which content might be the same so that a huma...
Hi there,
I'm trying to merge a hash with the key/values of string in ruby.
i.e.
h = {:day => 4, :month => 8, :year => 2010}
s = "/my/crazy/url/:day/:month/:year"
puts s.interpolate(h)
All I've found is to iterate the keys and replace the values. But I'm not sure if there's a better way doing this? :)
class String
def interpolate...
Some background information:
I am working on a C#/WPF application, which basically is about creating, editing, saving and loading some data model.
The data model contains of a hierarchy of various objects. There is a "root" object of class A, which has a list of objects of class B, which each has a list of objects of class C, etc. Ar...
In one of my main( or primary) routines,I have two or more hashes. I want the subroutine foo() to recieve these possibly-multiple hashes as distinct hashes. Right now I have no preference if they go by value, or as references. I am struggling with this for the last many hours and would appreciate help, so that I dont have to leave perl ...
Hi,
I have been using mootools for a year now. I need to use jquery for my new projects.
I always used hash() to make namespaces for my functions in mootools. For example,
var person = new Hash({
say_name: function(){
},
say_age: function(){
}
});
Does Jquery has similar stuff?
...
I have a list of objects which I want to turn into a set. My objects contain a few fields that some of which are o.id and o.area. I want two objects to be equal if these two fields are the same. ie: o1==o2 if and only if o1.area==o2.area and o1.id==o2.id.
I tried over-writing __eq__ and __cmp__ but I get the error: TypeError: unhashable...
Hi fellas,
A) Are there any FOSS programs out there that can manage to hashchange all files in a directory tree?
B) Failing that, what methods could be used to develop this capability in a (crappy) self-written program without requiring the program to be sophisticated and content-aware?
C) [Answered] Is there any (roughly) univers...