hash

Generate shorter public id

给你一囗甜甜゛ 提交于 2020-01-04 06:03:17
问题 I am looking for a way to generate public ids for my objects (like a facebook uid). The id should be unique and the user should not be able to guess it (or the next one). Right now I am using this: sha1('a fixed random string' . $this->getId()) The problem is that sha1 generates very long strings (40 chars) and I would like it to be shorter. I thought about using MD5 but it's known to be not save because you can create collisions. Is this really a problem in my case? What alternatives do I

How to switch hash_algos() on ? I'm with Php 5.2.11

会有一股神秘感。 提交于 2020-01-04 05:48:08
问题 My PHP version is 5.2.11 which is higher than the required version for hash_algos. however, when I run it either via web or command line, it returns Fatal error: Call to undefined function hash_algos() So as for other Hash functions. Do i have to turn anything on in the php.inin or what should I do? I have checked the php --re hash and the extension isn't there. I am very sure it is either not there or disabled. I also tried to installed it (PECL) but don't know how. 回答1: You'll need to

Get Hash URL from anchor and load into Div

廉价感情. 提交于 2020-01-04 05:34:08
问题 I have a video gallery that has a menu on the left and loads the content into a div on the right hand side. The menu is generated from php video posts so we need a general script that will effect everything. -- The problem -- The links will load the URL of the video as an anchor on the current URL - eg. http://www.divethegap.com/update/community/videos/#http://www.divethegap.com/update/2010/10/test-video-2/ So all I need is a script that will get the hash tag and load the content into a div.

Formula for Unique Hash from Integer Pair

烈酒焚心 提交于 2020-01-04 05:29:06
问题 I think I can use Cantor's to create a unique hash n = ((x + y)*(x + y) + x - y)/2... but can I reverse this hash? And if not, can someone provide a similar formula pair for a reversible hash? Thanks. 回答1: if x and y and n are all the same data types. n = ((x + y)*(x + y) + x - y)/2... when x and y are near the datatype::max n will overflow and you will lose information and not be able to recover x and y. If on the other hand if x and y are always within a range let say 0-FOO n = Foo * x + y

Formula for Unique Hash from Integer Pair

試著忘記壹切 提交于 2020-01-04 05:29:01
问题 I think I can use Cantor's to create a unique hash n = ((x + y)*(x + y) + x - y)/2... but can I reverse this hash? And if not, can someone provide a similar formula pair for a reversible hash? Thanks. 回答1: if x and y and n are all the same data types. n = ((x + y)*(x + y) + x - y)/2... when x and y are near the datatype::max n will overflow and you will lose information and not be able to recover x and y. If on the other hand if x and y are always within a range let say 0-FOO n = Foo * x + y

HashSet.contains returns false when it shouldn't

家住魔仙堡 提交于 2020-01-04 05:22:28
问题 I have this code: public class Tray { private Set<Block> blocks; private int numColumns; private int numRows; //constructor public Tray (int numRows, int numColumns){ this.numColumns = numColumns; this.numRows = numRows; blocks = new HashSet<>(); } public boolean satisfiesGoal(Tray other){ Block thisBlock = this.blocks.iterator().next(); Block otherBlock = other.blocks.iterator().next(); boolean hashesEqual = thisBlock.hashCode() == otherBlock.hashCode(); // this is true boolean areEqual =

flattening json to csv format

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-04 04:56:13
问题 i am trying to convert a json value to a flat csv based on the field that is selected by user . My json looks like var data = { "_index": "test", "_type": "news", "_source": { "partnerName": "propertyFile 9", "relatedSources": "null", "entityCount": "50", "Categories": { "Types": { "Events": [{ "count": 1, "term": "Time", "Time": [{ "term": "Dec 9", "Dec_9": [{ "count": 1, "term": "2012" }] }] }, { "count": 4, "term": "News", "News": [{ "term": "Germany", "Germany": [{ "count": 1, "term":

Efficient incremental hash computation during program interpretation

那年仲夏 提交于 2020-01-04 04:05:08
问题 I'd like to write a recursively memoizing Scheme interpreter . At any point during evaluation, the interpreter should be able to detect when it receives as arguments a pair of expression and environment that it has previously seen. Plain memoization of eval and apply is inefficient . It would require looking up the arguments in a hash table on every call of eval / apply , which would require walking the entire (possibly big) arguments on hash table matches. For example, assume that the

Extraction and printing of key-value pair from a text file using Perl

北慕城南 提交于 2020-01-04 03:57:09
问题 I have a text file temp.txt which contains entries like, cinterim=3534 cstart=517 cstop=622 ointerim=47 ostart=19 ostop=20 Note: key-value pairs may be arranged in new line or all at once in one line separated by space. I am trying to print and store these values in DB for corresponding keys using Perl. But I am getting many errors and warnings. Right now I am just trying to print those values. use strict; use warnings; open(FILE,"/root/temp.txt") or die "Unable to open file:$!\n"; while (my

How to do repeatable sampling in BigQuery Standard SQL?

感情迁移 提交于 2020-01-04 03:54:07
问题 In this blog a Google Cloud employee explains how to do repeatable sampling of data sets for machine learning in BigQuery. This is very important for creating (and replicating) train/validation/test partitions of your data. However the blog uses Legacy SQL, which Google has now deprecated in favor of Standard SQL. How would you re-write the blog's sampling code shown below, but using Standard SQL? #legacySQL SELECT date, airline, departure_airport, departure_schedule, arrival_airport, arrival