How can I get a reference to a method?

You want Object#method: ———————————————————- Object#method obj.method(sym) => method ———————————————————————— Looks up the named method as a receiver in obj, returning a Method object (or raising NameError). The Method object acts as a closure in obj’s object instance, so instance variables and the value of self remain available. class Demo def initialize(n) @iv = n end … Read more

compute crc of file in python

A little more compact and optimized code def crc(fileName): prev = 0 for eachLine in open(fileName,”rb”): prev = zlib.crc32(eachLine, prev) return “%X”%(prev & 0xFFFFFFFF) PS2: Old PS is deprecated – therefore deleted -, because of the suggestion in the comment. Thank you. I don’t get, how I missed this, but it was really good.

Possible to calculate MD5 (or other) hash with buffered reads?

You use the TransformBlock and TransformFinalBlock methods to process the data in chunks. // Init MD5 md5 = MD5.Create(); int offset = 0; // For each block: offset += md5.TransformBlock(block, 0, block.Length, block, 0); // For last block: md5.TransformFinalBlock(block, 0, block.Length); // Get the has code byte[] hash = md5.Hash; Note: It works (at least … Read more

How can I hash a string with SHA256 in JS?

Hellow there 😀 it’s quite a function. If you are a scholar, you would like to check this article: https://www.movable-type.co.uk/scripts/sha256.html Pure javascript: var sha256 = function sha256(ascii) { function rightRotate(value, amount) { return (value>>>amount) | (value<<(32 – amount)); }; var mathPow = Math.pow; var maxWord = mathPow(2, 32); var lengthProperty = ‘length’ var i, j; … Read more

Are unique indexes better for column search performance? (PGSQL & MySQL)

If your data are unique, you should create a UNIQUE index on them. This implies no additional overhead and affects optimizer’s decisions in certain cases so that it can choose a better algorithm. In SQL Server and in PostgreSQL, for instance, if you sort on a UNIQUE key, the optimizer ignores the ORDER BY clauses … Read more

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