unique

How to defend against users with Multiple Accounts?

We have a service where we literally give away free money. Naturally said service is ripe for abuse. To defend against this we do the following: log ip address use unique email addresses (only 1 acct/email addy) collect more info like st. address, phone number, etc. use signup captcha BHOs (I've seen poker rooms use these) Now, let'...

Get X unique numbers from a set

What is the most elegant way to grab unique random numbers I ponder? At the moment I need random unique numbers, I check to see if it's not unique by using a while loop to see if I've used the random number before. So It looks like: int n = getRandomNumber % [Array Size]; for each ( Previously used n in list) Check if I've used n...

Cakephp isUnique validation is not triggered on one field, but works on another

When I save the information from a registration form I have some validation rules on the username and email fields (I've pasted the rules below). Validation is called automatically with the saveAll() function. The problem is that the isUnique rule on the username field doesn't work at all (doesn't return any error). The other rules for ...

How to unique a dict by value?

I want to unique duplicate values in a dict. It looks like this: d = { "a":1, "b":2, "c":2, "d":3, "e":4, "f":5, "g":1, "h":2, "i":2, "j":1, "k":1} Here is what I did: # sort and unique the dict values obj = d.values() K = [] K = sorted(list(zip(*[(x,K.append(x)) for x in obj if not x in K])[0] V=[] for v1 in L: V.append([k f...

How can I find unique rows in a matrix, with no element order within each row?

Hi, I have an array comprising n rows and 4 colums. Each of the four entries on the row is an integer, i.e., X = [ 111 112 432 2 6 9 115 111 112 432 111 2 ]; Each row represents the vertices of a tetrahedron. These vertices have no directionality thus, in the case above, the tetrahedra represented b...

PHP Unique Computer ID

Is it possible for php(or javascript in the worst case) to create a unique id for a user that is not cookie or ip dependant. I have seen on myminicity.com that on each city the count only goes up once a day(it has a unique id for everyone i think) and even if I delete my cookies and refresh ip it still seems to detect me as visited alrea...

Permutating through the array of chars

Suppose you need to discover all possible permutations of 'n' distinct characters, say 'a', 'b', 'c'. Can you suggest an algorithm I can use to get this done? Generally speaking, how would you go about it? ...

Enforcing uniqueness on PostgreSQL table column after non-unique values already inserted

I already have 80 million records inserted into a table, but need to ensure a few columns are jointly unique. However, the columns already contain non-unique data, so ALTER TABLE doesn't work. I'd like either a query that will let me easily delete records that are non-unique, while keeping one of them, or one that will allow me to load ...

Generate unique temporary file paths

Hi, I want to generate unique file paths in Objective-C. I looked at NSTemporaryDirectory() but the closest I could get was to this and this. But in the second one they create such a file. I do not want to create it, I just want an NSString for a unique writable path... I don't need paths to folders, just files. How is this possible? ...

Delete an item from a list

Hey, I was trying to delete an item form a list (without using set): list1 = [] for i in range(2,101): for j in range(2,101): list1.append(i ** j) list1.sort() for k in range(1,len(list1) - 1): if (list1[k] == list1[k - 1]): list1.remove(list1[k]) print "length = " + str(len(list1)) The set function works fine,...

What's the fastest way to check List<String> contains a unique String?

It's in Java. Basically I have about 1,000,000 strings, for each request I have to check a String is belonged to the list or not. I'm worried about the performance, so what's the best method? ArrayList? Hash? Thanks. ...

I need a unique subset of data from my table using SQL

I am working with a Dbase table via SQL commands. I have the following free table to work with. import1 account, phone, subaccount, locationid I need the first occurrence of each uinique combination of account and phone. No one field in the table is unique. I can get a partial subset of data using the distinct qualifier but i need the...

indexes needed for table inheritance in postgres?

this is a fairly simple question, but it's one i can't find a firm answer on. i have a parent table in postgres, and then several child tables which have been defined. a trigger has been established, and the children tables only have data inserted if a field, say field x, meets a certain criteria. when i query the parent table with ...

In mysql has the same effect in speed terms using a UNIQUE key than a NORMAL key?

For example, I'm doing the next action: SELECT COUNT(id) FROM users WHERE unique_name = 'Wiliam' // if Wiliam don't exists then... INSERT INTO users SET unique_name = 'Wiliam' The question is, I'm doing the SELECT COUNT(id) check every time I insert a new user, despite of using an unique key or not, so... if "unique_name" h...

Find duplicates in database and rename one

I've got a table in Postgres that is chock full of articles. The articles have a url slug associated with them, which are used to display them as example.com/pretty_name as opposed to example.com\2343. Unfortunately, when I started out, I enforced a unique constraint on urls, but neglected to do so on a case insensitive basis, and I'd l...

INSERT or return row if entry already exists in a table with UNIQUE constraint

Greetings, I have this table, on a postgreSQL 8.4 server : CREATE TABLE tags ( tagid bigserial PRIMARY KEY, name text NOT NULL, value text NOT NULL, UNIQUE(name,value) ); The normal INSERT behavior is to throw an error when new values break the unique...

How do I prevent MySQL from auto-incrementing the Primary Key while using ON DUPLICATE KEY UPDATE when the duplicate is a different unique column?

Consider the following table: +-------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+------------------+------+-----+---------+----------------+ | vendor_id | int(10) unsigned | NO | PRI | NULL | auto_increment | | vendor...

uniqueness of composite id with null component

Hi, I am running into problems using unique constraints. The following combinations are allowed A.name B.name foo NULL foo bar foo bar1 foo1 bar It should not be possible to create a new A with same name, only if it has a different B. With the constraints below it is possible to create A.name B.name foo NULL foo ...

Django unique constraint + form errors

I'm having some issues with double-posting on my site. I figure a simple unique constraint across all the relevant fields will solve the issue on a database level, but then it just produces a nasty error page for the user. Is there a way I can turn this into a pretty form error instead? Like a non_field_error? Or what approach should I t...

How to get all the possible values of a function called with any two values of an array?

Consider this code: class MyClass { string PropertyA; int PropertyB; double PropertyC; object PropertyD; static ComparisonResult Compare(MyClass a, MyClass b){ // returns a ComparisonResult with // _sampleElement = a // _commonProperties = flags that describe the common properties of a and b ...