Generating the SHA hash of a string using golang

An example : import ( “crypto/sha1” “encoding/base64” ) func (ms *MapServer) storee(bv []byte) { hasher := sha1.New() hasher.Write(bv) sha := base64.URLEncoding.EncodeToString(hasher.Sum(nil)) … } In this example I make a sha from a byte array. You can get the byte array using bv := []byte(myPassword) Of course you don’t need to encode it in base64 if … Read more

Hashing arrays in Python

Just try it: >>> hash((1,2,3)) 2528502973977326415 >>> hash([1,2,3]) Traceback (most recent call last): File “<stdin>”, line 1, in <module> TypeError: unhashable type: ‘list’ >>> hash(frozenset((1,2,3))) -7699079583225461316 >>> hash(set((1,2,3))) Traceback (most recent call last): File “<stdin>”, line 1, in <module> TypeError: unhashable type: ‘set’ So you can get hash of tuple and frozenset since the are … Read more

Descending sort by value of a Hash in Ruby

You can have it cleaner, clearer and faster, all at once! Like this: h.sort_by {|k,v| v}.reverse I benchmarked timings on 3000 iterations of sorting a 1000-element hash with random values, and got these times: h.sort {|x,y| -(x[1]<=>y[1])} — 16.7s h.sort {|x,y| y[1] <=> x[1]} — 12.3s h.sort_by {|k,v| -v} — 5.9s h.sort_by {|k,v| v}.reverse — … Read more

Algorithm to compare two images in C#

Here is a simple approach with a 256 bit image-hash (MD5 has 128 bit) resize the picture to 16×16 pixel reduce colors to black/white (which equals true/false in this console output) read the boolean values into List<bool> – this is the hash Code: public static List<bool> GetHash(Bitmap bmpSource) { List<bool> lResult = new List<bool>(); //create … Read more

RoR – MD5 generation

You can use Digest::MD5 from the Ruby standard library for this. irb(main):001:0> require ‘digest/md5’ => true irb(main):002:0> Digest::MD5.hexdigest(‘foobar’) => “3858f62230ac3c915f300c664312c63f” And one more thing: MD5 is a hash algorithm. You don’t “encrypt” anything with a hash algorithm.

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