Converting a string to a number by using INT (no hash method)

D

Dave Angel

Actually, to give credit where it's due, it wasn't me. I just modified someone else's interesting solution in this thread and added the silly limit of 10000 to it.

That's okay. The OP doesn't seem to know anything about programming, or
about information theory, so the fact you gave a single line that
actually "works" must be extraordinarily valuable to him. When he was
trying to use the md5 module, I gave him the hints about his five
programming errors, and was about to expand on it when i noticed his 4
digit limitation.
Exactly. Four digits is hardly enough range for it to be even remotely safe. And even then range isn't really the issue as technically it just improves your odds.

The results of a modulus operator are still non-unique no matter how many digits are there to work with ... within reason. Statistically anyone who buys a ticket could potentially win the lottery no matter how bad the odds are. ;)

And now back to the OP, I'm still confused on this four-digit limitation. Why isn't the limitation at least adhering to a bytelength like byte/short/long? Is this database storing a string of characters instead of an actual number? (And if so, then why not just block out 255 characters instead of 4 to store a whole path? Or at the very least treat 4 characters as 4 bytes to greatly increase the numeric range?)

I wish I had done the internet search earlier. This name 'ferrous
cranus' is a pseudonym of various trolls, and anybody who'd adopt it
isn't worth our time.

Thanks to Alan Spence for spotting that. I'll plonk 'ferrous cranus' now.
 
D

Dennis Lee Bieber

Finally!!!!!! THANK YOU VERY MUCH!!! THIS IS WHAT I WAS LOOKING FOR!!!

NOW, if you please explain it to me from the innermost parenthesis please, because i do want to understand it!!!

And since i'am sure it works, and i just used it on http://superhost.gr

Really: Try running:

-=-=-=-=-=-=-
import os
import collections

PATH = "c:/windows" #change this to your need

fids = os.listdir(PATH)

print "Number of files in directory %s: %s" % (PATH, len(fids))

cntr = collections.Counter()

for fid in fids:
pin = int( fid.encode("hex"), 16 ) % 10000
cntr.update([pin])

for pin, cnt in cntr.items():
if cnt > 1:
print "%10s %10s COLLISION" % (pin, cnt)


-=-=-=-=-=-
Number of files in directory c:/windows: 290
9799 2 COLLISION
7209 2 COLLISION
8900 2 COLLISION
6985 2 COLLISION
1972 2 COLLISION
2532 2 COLLISION
3559 2 COLLISION

-=-=-=-=-=-
Number of files in directory e:/userdata/wulfraed/my documents/python
progs: 157
1369 2 COLLISION
6041 3 COLLISION
3945 3 COLLISION
8489 2 COLLISION
7417 2 COLLISION
9076 2 COLLISION
6249 2 COLLISION
2457 2 COLLISION
937 2 COLLISION
8249 2 COLLISION
 
A

alex23

Unless you constrain your users to very restrictive filenames, what you
ask here simply cannot be done.

He's also INSISTED in other threads that these files should be
moveable at will by other users and still be recognisable as the same
file. So yes: troll or willful ignorance seems to be what we're seeing
here.
 
S

Steven D'Aprano

He's also INSISTED in other threads that these files should be moveable
at will by other users and still be recognisable as the same file. So
yes: troll or willful ignorance seems to be what we're seeing here.

Definitely troll, and we got well and truly had.

Shame on us -- he practically *screamed* "I am a troll" in his user-name.
"Ferrous Cranus" ("Iron Skull") is the name of a particular subspecies of
troll in Mike Reed's well known compendium:

http://redwing.hutman.net/~mreed/warriorshtm/ferouscranus.htm


How many days was he posting here, pretending to be dumber than a box of
hammers? How many hours have we collectively wasted, reading and replying
to his posts?

I wouldn't even trust that he is Greek. Quite likely he uses a non-
English attribution line to hint that English is not his first language,
so his victims will think that there is a language barrier. "Maybe he
doesn't understand me. If I answer again, in a slightly different way,
perhaps it will be more clear."
 
A

alex23

How many days was he posting here, pretending to be dumber than a box of
hammers? How many hours have we collectively wasted, reading and replying
to his posts?

Trying to find some positive in this: the people sincerely responding
at least stretched themselves to try and find solutions or better ways
of communicating. The troll just learned how to be a better troll.

We still win.
 
F

Ferrous Cranus

Τη ΤÏίτη, 22 ΙανουαÏίου 2013 10:40:39 μ.μ. UTC+2, ο χÏήστης John Gordon έγÏαψε:
I tried going to that address and got some error output. I noticed this

in the error dump:



186 if cursor.rowcount == 0:

187 cursor.execute( '''INSERT INTO visitors(pin, host

, hits, useros, browser, date) VALUES(%s, %s, %s, %s, %s)''', (pin, hos

t, 1, useros, browser, date) )



The INSERT statement gives six column names but only five placeholders (%s)

in the VALUES clause.



Perhaps that's the problem?

Excatly Gordon, i missed the extra placeholder(%s) when i was adding a new useros column. I also used a 5-digit number.

Now my website finally works as intended. Just visit the following links plz.
------------------------------------------------------------------------------
1. http://superhost.gr

2. http://superhost.gr/?show=log

3. http://i.imgur.com/3Hcz1uP.png (this displays the database's column 'pin', a 5-digit number acting as a filepath indicator. I guess i won't be needing column 'page' anymore)

4. http://i.imgur.com/kRwzLp3.png (this is the detailed page information associated to 'pin' column indicator instead of something like '/home/nikos/public_html/index.html'

Isn't it a nice solution?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top