unique

How can I generate a list of n unique elements picked from a set?

五迷三道 提交于 2020-01-03 16:51:23
问题 How to generate a list of n unique values ( Gen[List[T]] ) from a set of values (not generators) using ScalaCheck? This post uses Gen[T]* instead of a set of values, and I can't seem to rewrite it to make it work. EDIT At @Jubobs' request I now shamefully display what I have tried so far, revealing my utter novice status at using ScalaCheck :-) I simply tried to replace gs: Gen[T] repeated parameter to a Set in what @Eric wrote as a solution here: def permute[T](n: Int, gs: Set[T]): Gen[Seq[T

How can I get the unique values of an array in .net?

我们两清 提交于 2020-01-03 13:31:55
问题 Say I've got this array: MyArray(0)="aaa" MyArray(1)="bbb" MyArray(2)="aaa" Is there a .net function which can give me the unique values? I would like something like this as an output of the function: OutputArray(0)="aaa" OutputArray(1)="bbb" 回答1: Assuming you have .Net 3.5/LINQ: string[] OutputArray = MyArray.Distinct().ToArray(); 回答2: A solution could be to use LINQ as in the following example: int[] test = { 1, 2, 1, 3, 3, 4, 5 }; var res = (from t in test select t).Distinct<int>();

Zend Framework generate unique string

元气小坏坏 提交于 2020-01-03 13:07:43
问题 I want to generate a unique 4-6 char long AlphaNumeric string to save in db with each record(user). The db field has a unique index, so trying to save a pre-existing string generates an error. Right now I am generating a random string and using try-catch, so when adding a new record if it throws an exception, I generate another random string and attempt to save again, and the code keep trying until it adds a record successfully. This whole solution not only looks heavy but also ugly, so I

How to see if all values within group are unique/identify those that aren't

痞子三分冷 提交于 2020-01-03 02:57:15
问题 Say that I have data like this: group value 1 fox 1 fox 1 fox 2 dog 2 cat 3 frog 3 frog 4 dog 4 dog I want to be able to tell if all values of value are the same within group . Another way to see this is if I could create a new variable that contains all unique values of value within group like the following: group value all_values 1 fox fox 1 fox fox 1 fox fox 2 dog dog cat 2 cat dog cat 3 frog frog 3 frog frog 4 dog dog 4 dog dog As we see, all groups except group 2 have only one distinct

Index multiple columns and Match distinct values, returning list of unique values across columns

人走茶凉 提交于 2020-01-03 02:50:10
问题 I've searched far and wide for a solution to my problem... over several long weeks now. I've come up a partially working solutions, which I'll include at the bottom for those who might know how to modify/extend them to resolve the problem. Here's what I'm trying to accomplish (the following descriptions are in reference to this screen capture http://imgur.com/oTkbjrw): 1) I am looking to match values from Column G with Column A ($G2 with $A$2:$A$10). 2) If the values match, then extract

Rails 3 uniqueness validation with scope on polymorphic table

泪湿孤枕 提交于 2020-01-02 23:05:23
问题 I've got the following setup: class Vote < ActiveRecord::Base belongs_to :voteable, :polymorphic => :true, :counter_cache => true end class Proposition < ActiveRecord::Base has_many :votes, :as => :voteable end class Winner < ActiveRecord::Base has_many :votes, :as => :voteable end The Vote table looks like this: t.string "ip_address" t.integer "voteable_id" t.string "voteable_type" I want to validate the following. A user with a given ip_address can only vote on 1 proposition. So the

How can I Identify unique users on my website even IP is changed or browser data has been cleared?

风格不统一 提交于 2020-01-02 03:31:46
问题 I am developing a video streaming website. I want to count unique views on each video. I referred to some sites on internet and even asked some other programmers. They say either use cookies or session or IP address. But these things changes over time. Also if possible can we do this using MAC address of the user's machine? Also I came across a similar question here -> http://bit.ly/Qh1KNR. They say there is something like browser fingerprint that uses MAC address. So can you tell me what

Hash of unique value = unique hash?

回眸只為那壹抹淺笑 提交于 2020-01-01 17:12:24
问题 Theoretically does hashing a unique value yield a unique value? Let's say I have a DB table with 2 columns: id and code. id is an auto-incrementing int and code is a varchar. If I do ... $code = sha1($id); ... and then store $code into the same row as $id. Will my code column be unique as well? What about if I append the current time? eg: $code = sha1($id . time()); Thanks. 回答1: In general, the answer is no. This is trivial to show: SHA-1 has 2^160 different outputs - 160 bits, but there are

How make univoque my enumeration by xs:unique

早过忘川 提交于 2020-01-01 16:10:57
问题 Can anyone point me as to why the unique element in my XSD is not forcing unique-ness? This should throw an error because the last ScreenResult element does not contain a unique value for the Type attribute. I should also note that I'm truly after forcing one of each Type within ScreenResults ( ScreenResult is required to exist 3 times, there are 3 types of screens and I am requiring unique-ness) so if there is a better way to accomplish that, I'm all for that as well. Thank you. Here is my

How make univoque my enumeration by xs:unique

 ̄綄美尐妖づ 提交于 2020-01-01 16:10:13
问题 Can anyone point me as to why the unique element in my XSD is not forcing unique-ness? This should throw an error because the last ScreenResult element does not contain a unique value for the Type attribute. I should also note that I'm truly after forcing one of each Type within ScreenResults ( ScreenResult is required to exist 3 times, there are 3 types of screens and I am requiring unique-ness) so if there is a better way to accomplish that, I'm all for that as well. Thank you. Here is my