ruby using the “&:methodname” shortcut from array.map(&:methodname) for hash key strings rather than methodname

You can do this with a lambda: extract_keyname = ->(h) { h[:keyname] } ary_of_hashes.map(&extract_keyname) This tends to be more useful if the block’s logic is more complicated than simply extracting a value from a Hash. Also, attaching names to your bits of logic can help clarify what a chain of Enumerable method calls is trying … Read more

Password hash function for Excel VBA

Here’s a module for calculating SHA1 hashes that is usable for Excel formulas eg. ‘=SHA1HASH(“test”)’. To use it, make a new module called ‘module_sha1’ and copy and paste it all in. This is based on some VBA code from http://vb.wikia.com/wiki/SHA-1.bas, with changes to support passing it a string, and executable from formulas in Excel cells. … Read more

Is there a way to initialize an object through a hash?

You can define an initialize function on your class: class A attr_accessor :b,:c,:d def initialize(h) h.each {|k,v| public_send(“#{k}=”,v)} end end Or you can create a module and then “mix it in” module HashConstructed def initialize(h) h.each {|k,v| public_send(“#{k}=”,v)} end end class Foo include HashConstructed attr_accessor :foo, :bar end Alternatively you can try something like constructor

C# Create a hash for a byte array or image [duplicate]

There’s plenty of hashsum providers in .NET which create cryptographic hashes – which satisifies your condition that they are unique (for most purposes collision-proof). They are all extremely fast and the hashing definitely won’t be the bottleneck in your app unless you’re doing it a trillion times over. Personally I like SHA1: public static string … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)