Search Results

Search found 878 results on 36 pages for 'pairs'.

Page 4/36 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why does this Grails/HQL query with a JOIN return Lists of pairs of domain classes?

    - by ?????
    I'm having trouble figuring out how to do a "join" in Groovy/Grails and the return values I get person = User.get(user.id) def latestPhotosForUser = PhotoOwner.findAll("FROM PhotoOwner AS a, PhotoStorage AS b WHERE (a.owner=:person AND a.photo = b)", [person:person], [max:3]) latestPhotosForUser isn't a list of PhotoOwners. It's a list of [PhotoOwner, PhotoStorage] pairs. Since I'm doing a PhotoOwner.findAll, I would have expected to see only PhotoOwners. Am I doing something wrong, or is this the proper behavior?

    Read the article

  • How should I grab pairs from a list in python?

    - by tomaski
    Say I have a list that looks like this: ['item1', 'item2', 'item3', 'item4', 'item5', 'item6', 'item7', 'item8', 'item9', 'item10'] Using Python, how would I grab pairs from it, where each item is included in a pair with both the item before and after it? ['item1', 'item2'] ['item2', 'item3'] ['item3', 'item4'] ['item4', 'item5'] ['item5', 'item6'] ['item6', 'item7'] ['item7', 'item8'] ['item8', 'item9'] ['item9', 'item10'] Seems like something i could hack together, but I'm wondering if someone has an elegant solution they've used before?

    Read the article

  • How should I grab pairs from an array in python?

    - by tomaski
    Say I have an array that looks like this: ['item1', 'item2', 'item3', 'item4', 'item5', 'item6', 'item7', 'item8', 'item9', 'item10'] Using Python, how would I grab pairs from it, where each item is included in a pair with both the item before and after it? ['item1', 'item2'] ['item2', 'item3'] ['item3', 'item4'] ['item4', 'item5'] ['item5', 'item6'] ['item6', 'item7'] ['item7', 'item8'] ['item8', 'item9'] ['item9', 'item10'] Seems like something i could hack together, but I'm wondering if someone has an elegant solution they've used before?

    Read the article

  • What is the most efficient way to pass data (list of pairs of [Integer + Double]) between two Google App Engine instances?

    - by ruslan
    What is the most efficient way to pass data (list of pairs of [Integer, Double]) between two Google App Engine instances ? Currently I use Java binary serialization. Frontend servlet receives data from the client in JSON format. I convert it to byte[] using ObjectOutput.writeObject and then send it to backend servlet via HTTP POST. It's not in production yet. Should I just pass client's JSON as it is to backend? It seems more logical. But it's bigger in size. Or should I use Google Protocol Buffers as stated in this benchmark article ? Thank you!!!

    Read the article

  • php: possible to convert array of numbers to 'from' and 'to' pairs where consecutive?

    - by Haroldo
    I have an array of timestamps referring to the days when a holiday home is booked. each timestamp is a round day. I want to turn this into an array of 'begins' and 'ends' pairs for consecutive dates Are there any php functions I should be aware of for writing this function? Or does anyone have any pointers for this kind of thing? thanks! edit: example array: Array ( [0] => 1273536000 [1] => 1273622400 [2] => 1273708800 [3] => 1273795200 [4] => 1273881600 [5] => 1273968000 [6] => 1274054400 [7] => 1274140800 [8] => 1274227200 ) where a day = 86400 (seconds)

    Read the article

  • Bluetooth Headset pairs and appears in Sound Devices, but shows as Disconnected?

    - by Mike
    I recently got a TrueBlue TB-100T3 and tried pairing it with my computer (Windows 7 64-bit). At first it paired but would not appear under Sound Devices. I updated my Broadcom Bluetooth drivers here: http://www.broadcom.com/support/bluetooth/update.php Now my headset appears in both Playback and Recording, but shows as Disconnected. The device is on, paired, and appears under Device Manager as having no problems. I right-clicked and installed both the Hands-free Telephony and Headset services. Here is an image: http://i.stack.imgur.com/vG2S7.png Right-clicking the device and selecting Connect does nothing. Does anyone have a solution? Thanks!

    Read the article

  • Is there a peripheral that lets my computer monitor the connectivity of pairs of wires?

    - by raldi
    I've got a bunch of physical switches and circuits that act like switches (they're either connected to ground or they're just an open wire). Is there some sort of thing I can plug into my computer (ideally, via USB) that has a bunch of screw terminals, and I can attach wires to the screws and have the computer keep track of which circuits are closed and which are open? Bonus points if the device also lets the computer open and close switches, too. I don't even know what to google for.

    Read the article

  • How should my CAT6e cable be terminated? No pairs?

    - by user231465
    I have just bought 60 meters of CAT6e cables, sold as "4 pair UTP RJ45". I have looked at various videos on Youtube but I cannot determine the correct wiring. all the colors of the cable I saw there are different from mine. Mine is untwisted, and it is not color coded. I have 8 pin connectors all of a single color. How should I wire this cable? EDIT THE PACKAGE DOES SAY TWISTED but they are not (twisted).

    Read the article

  • Can I autogenerate/compile code on-the-fly, at runtime, based upon values (like key/value pairs) parsed out of a configuration file?

    - by Kumba
    This might be a doozy for some. I'm not sure if it's even 100% implementable, but I wanted to throw the idea out there to see if I'm really off of my rocker yet. I have a set of classes that mimics enums (see my other questions for specific details/examples). For 90% of my project, I can compile everything in at design time. But the remaining 10% is going to need to be editable w/o re-compiling the project in VS 2010. This remaining 10% will be based on a templated version of my Enums class, but will generate code at runtime, based upon data values sourced in from external configuration files. To keep this question small, see this SO question for an idea of what my Enums class looks like. The templated fields, per that question, will be the MaxEnums Int32, Names String() array, and Values array, plus each shared implementation of the Enums sub-class (which themselves, represent the Enums that I use elsewhere in my code). I'd ideally like to parse values from a simple text file (INI-style) of key/value pairs: [Section1] Enum1=enum_one Enum2=enum_two Enum3=enum_three So that the following code would be generated (and compiled) at runtime (comments/supporting code stripped to reduce question size): Friend Shared ReadOnly MaxEnums As Int32 = 3 Private Shared ReadOnly _Names As String() = New String() _ {"enum_one", "enum_two", "enum_three"} Friend Shared ReadOnly Enum1 As New Enums(_Names(0), 1) Friend Shared ReadOnly Enum2 As New Enums(_Names(1), 2) Friend Shared ReadOnly Enum3 As New Enums(_Names(2), 4) Friend Shared ReadOnly Values As Enums() = New Enums() _ {Enum1, Enum2, Enum3} I'm certain this would need to be generated in MSIL code, and I know from reading that the two components to look at are CodeDom and Reflection.Emit, but I was wondering if anyone had working examples (or pointers to working examples) versus really long articles. I'm a hands-on learner, so I have to have example code to play with. Thanks!

    Read the article

  • How to write regex that searches for a dynamic amount of pairs?

    - by citronas
    Lets say a have a string such as this one: string txt = "Lore ipsum {{abc|prop1=\"asd\";prop2=\"bcd\";}} asd lore ipsum"; The information I want to extract "abc" and pairs like ("prop1","asd") , ("prop3", "bcd") where each pair used a ; as delimeter. Edit1: (based on MikeB's) code Ah, getting close. I found out how to parse the following: string txt = "Lore ipsum {{abc|prop1=\"asd\";prop2=\"http:///www.foo.com?foo=asd\";prop3=\"asd\";prop4=\"asd\";prop5=\"asd\";prop6=\"asd\";}} asd"; Regex r = new Regex("{{(?<single>([a-z0-9]*))\\|((?<pair>([a-z0-9]*=\"[a-z0-9.:/?=]*\";))*)}}", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match m = r.Match(txt); if (m.Success) { Console.WriteLine(m.Groups["single"].Value); foreach (Capture cap in m.Groups["pair"].Captures) { Console.WriteLine(cap.Value); } } Question 1: How must I adjust the regex to say 'each value of a pair in delimited by \" only? I added chars like '.',';' etc, but I can't think of any char that I want to permit. The other way around would be much nicer. Question 2: How must I adjust this regex work with this thing here? string txt = "Lore ipsum {{abc|prop1=\"asd\";prop2=\"http:///www.foo.com?foo=asd\";prop3=\"asd\";prop4=\"asd\";prop5=\"asd\";prop6=\"asd\";}} asd lore ipsum {{aabc|prop1=\"asd\";prop2=\"http:///www.foo.com?foo=asd\";prop3=\"asd\";prop4=\"asd\";prop5=\"asd\";prop6=\"asd\";}}"; Therefore I'd probably try to get groups of {{...}} and use the other regex?

    Read the article

  • How to replace pairs of strings in two files to identical IDs?

    - by Péter Török
    Sorry if the title is not very intelligible, I couldn't come up with anything better. Hopefully my explanation is clear enough: I have a pair of rather large log files with very similar content, except that some strings are different between the two. A couple of examples: UnifiedClassLoader3@19518cc | UnifiedClassLoader3@d0357a JBossRMIClassLoader@13c2d7f | JBossRMIClassLoader@191777e That is, wherever the first file contains UnifiedClassLoader3@19518cc, the second contains UnifiedClassLoader3@d0357a, and so on. [Update] There are about 40 distinct pairs of such identifiers.[/Update] I want to replace these with identical IDs so that I can spot the really important differences between the two files. I.e. I want to replace all occurrences of both UnifiedClassLoader3@19518cc in file1 and UnifiedClassLoader3@d0357a in file2 with UnifiedClassLoader3@1; all occurrences of both JBossRMIClassLoader@13c2d7f in file1 and JBossRMIClassLoader@191777e in file2 with JBossRMIClassLoader@2 etc. Using the Cygwin shell, so far I managed to list all different identifiers occurring in one of the files with grep -o -e 'ClassLoader[0-9]*@[0-9a-f][0-9a-f]*' file1.log | sort | uniq However, now the original order is lost, so I don't know which is the pair of which ID in the other file. With grep -n I can get the line number, so the sort would preserve the order of appearance, but then I can't weed out the duplicate occurrences. Unfortunately grep can not print only the first match of a pattern. I figured I could save the list of identifiers produced by the above command into a file, then iterate over the patterns in the file with grep -n | head -n 1, concatenate the results and sort them again. The result would be something like 2 ClassLoader3@19518cc 137 ClassLoader@13c2d7f 563 ClassLoader3@1267649 ... Then I could (either manually or with sed itself) massage this into a sed command like sed -e 's/ClassLoader3@19518cc/ClassLoader3@2/g' -e 's/ClassLoader@13c2d7f/ClassLoader@137/g' -e 's/ClassLoader3@1267649/ClassLoader3@563/g' file1.log > file1_processed.log and similarly for file2. However, before I start, I would like to verify that my plan is the simplest possible working solution to this. Is there any flaw in this approach? Is there a simpler way?

    Read the article

  • Is there a way to transfrom a list of key/value pairs into a data transfer object

    - by weevie
    ...apart from the obvious looping through the list and a dirty great case statement! I've turned over a few Linq queries in my head but nothing seems to get anywhere close. Here's the an example DTO if it helps: class ClientCompany { public string Title { get; private set; } public string Forenames { get; private set; } public string Surname { get; private set; } public string EmailAddress { get; private set; } public string TelephoneNumber { get; private set; } public string AlternativeTelephoneNumber { get; private set; } public string Address1 { get; private set; } public string Address2 { get; private set; } public string TownOrDistrict { get; private set; } public string CountyOrState { get; private set; } public string PostCode { get; private set; } } We have no control over the fact that we're getting the data in as KV pairs, I'm afraid.

    Read the article

  • how to create and track multiple pairs "View-ViewModel"?

    - by Gianluca Colucci
    Hi! I am building an application that is based on MVVM-Light. I am in the need of creating multiple instances of the same View, and each one should bind to its own ViewModel. The default ViewModelLocator implements ViewModels as singletons, therefore different instances of the same View will bind to the same ViewModel. I could create the ViewModel in the VMLocator as a non-static object (as simple as returning new VM()...), but that would only partially help me. In fact, I still need to keep track of the opened windows. Nevertheless, each window might open several other windows (of a different kind, though). In this situation I might need to execute some operation on the parent View and all its children. For example before closing the View P, I might want to close all its children (view C1, view C2, etc.). Hence, is there any simple and easy way to achieve this? Or is there any best practice you would advice me to follow? Thanks in advance for your precious help. Cheers, Gianluca.

    Read the article

  • In OpenRasta is it possible to Pattern match multiple key/value pairs?

    - by Scott Littlewood
    Is it possible in OpenRasta to have a Uri pattern that allows for an array of values of the same key to be submitted and mapped to a handler method accepting an array of the query parameters. Example: Return all the contacts named Dave Smith from a collection. HTTP GET /contacts?filterBy=first&filterValue=Dave&filterBy=last&filterValue=Smith With a configuration of: What syntax would be best for the Uri string pattern matching? (Suggestions welcome) ResourceSpace.Has.ResourcesOfType<List<ContactResource>>() .AtUri("/contacts") .And.AtUri("/contacts?filterBy[]={filterBy}[]&filterValue[]={fv}[]") // Option 1 .And.AtUri("/contacts?filterBy={filterBy}[]&fv={fv}[]") // Option 2 Would map to a Handler method of: public object Get(params Filter[] filters) { /* create a Linq Expression based on the filters using dynamic linq query the repository using the Linq */ return Query.All<Contact>().Where(c => c.First == "Dave" && c.Last == "Smith").ToResource() } where Filter is defined by public class Filter { public string FilterBy { get; set; } public string FilterValue { get; set; } }

    Read the article

  • how to implement class with collection of string/object pairs so that an object can be returned with

    - by matti
    The values in a file are read as string and can be double, string or int or maybe even lists. An example file: DatabaseName=SomeBase Classes=11;12;13 IntValue=3 //this is required! DoubleValue=4.0 I was thinking something like this: public static T GetConfigValue(string cfgName) { // here we just return for example the value which could // be List[int] if parameter cfgName='Classes' // and LoadConfig was called with Dictionary containing // keyvaluepair 'Classes' / typeof(List[int]) } public static bool LoadConfig(Dictionary reqSettings, Dictionary optSettings) { foreach (KeyValuePair kvPair in reqSettings) { if (ReadCheckAndStore(kVPair, true)) return false; } foreach (KeyValuePair kvPair in reqSettings) { if (ReadCheckAndStore(kVPair, false)) return false; } return true; } private static bool ReadCheckAndStore(KeyValuePair kVPair, bool isRequired) { if (!ReadValue(kVPair.Key, out confValue) && isRequired) //req. IntValue !found return false; //here also have to test if read value is wanted type. //and if yes store to collection. } Thanks a lot & BR! -Matti PS. Additional issue is default values for optional settings. It's not elegant to pass them to LoadConfig in separate Dictionary, but that is an other issue...

    Read the article

  • How can I get an e-mail address out of a string of key=value pairs?

    - by noob
    How can I get some part of string that I need? accountid=xxxxxx type=prem servertime=1256876305 addtime=1185548735 validuntil=1265012019 username=noob directstart=1 protectfiles=0 rsantihack=1 plustrafficmode=1 mirrors= jsconfig=1 [email protected] lots=0 fpoints=6076 ppoints=149 curfiles=38 curspace=3100655714 bodkb=60000000 premkbleft=25000000 ppointrate=116 I want data after email= but up to live.com.?

    Read the article

  • How do I efficiently locate key-value pairs in a multi-dimensional PHP array?

    - by Kyle Noland
    I have an array in PHP as a result of the following query to a Wordpress database: SELECT * FROM wp_postmeta WHERE post_id = :id I am returned a multidimensional array that looks like this: Array ( [0] => Array ( [meta_id] => 380 [post_id] => 72 [meta_key] => _edit_last [meta_value] => 1 ) ... etc. What is the best way to find a particular key-value pair in this array? For instance, how would I located the row where [meta_key] = event_name so that I can extract that same row's [meta_value] value into a PHP variable? I realize I could turn this into many individual MySQL queries. Does anyone have an opinion of the efficiency of doing 10 SQL queries in a row rather than searching the array 10 times? I would think since the array is in memory, that will be the fastest method to find the values I need. Alternatively, is there a better way to query the database from the beginning so that my result set is formatted in a way that is easier to search?

    Read the article

  • Problem with multidimensional arrays in ruby.

    - by antiarchitect
    From script/console: >> pairs = Array.new(2).map!{Array.new(2).map!{Array.new(2, Array.new)}} => [[[[], []], [[], []]], [[[], []], [[], []]]] >> pair = Pair.first => #<Pair id: 39, charge_card_id: 1, classroom_id: 1, timeslot_id: 1, created_at: "2010-04-01 00:45:37", updated_at: "2010-04-01 00:45:47"> >> pairs[0][0][0] << pair => [#<Pair id: 39, charge_card_id: 1, classroom_id: 1, timeslot_id: 1, created_at: "2010-04-01 00:45:37", updated_at: "2010-04-01 00:45:47">] >> pairs[0][0] => [[#<Pair id: 39, charge_card_id: 1, classroom_id: 1, timeslot_id: 1, created_at: "2010-04-01 00:45:37", updated_at: "2010-04-01 00:45:47">], [#<Pair id: 39, charge_card_id: 1, classroom_id: 1, timeslot_id: 1, created_at: "2010-04-01 00:45:37", updated_at: "2010-04-01 00:45:47">]] >> So the question is why the pair object appears in pairs[0][0][0] AND in pairs[0][0][1] inspite of I did'n ask it to appear there. Notice I don't nedd to pairs[0][0][0] = pair - I want it as a first array member, so I need to use << or .push.

    Read the article

  • Implementing default constructors

    - by James
    Implement the default constructor, the constructors with one and two int parameters. The one-parameter constructor should initialize the first member of the pair, the second member of the pair is to be 0. Overload binary operator + to add the pairs as follows: (a, b) + (c, d) = (a + c, b + d); Overload the - analogously. Overload the * on pairs ant int as follows: (a, b) * c = (a * c, b * c). Write a program to test all the member functions and overloaded operators in your class definition. You will also need to write accessor (get) functions for each member. The definition of the class Pairs: class Pairs { public: Pairs(); Pairs(int first, int second); Pairs(int first); // other members and friends friend istream& operator>> (istream&, Pair&); friend ostream& operator<< (ostream&, const Pair&); private: int f; int s; }; Self-Test Exercise #17: istream& operator (istream& ins, Pair& second) { char ch; ins ch; // discard init '(' ins second.f; ins ch; // discard comma ',' ins second.s; ins ch; // discard final '(' return ins; } ostream& operator<< (ostream& outs, const Pair& second) { outs << '('; outs << second.f; outs << ", " ;// I followed the Author's suggestion here. outs << second.s; outs << ")"; return outs; }

    Read the article

  • Lua Operator Overloading

    - by Pessimist
    I've found some places on the web saying that operators in Lua are overloadable but I can't seem to find any example. Can someone provide an example of, say, overloading the + operator to work like the .. operator works for string concatenation? EDIT 1: to Alexander Gladysh and RBerteig: If operator overloading only works when both operands are the same type and changing this behavior wouldn't be easy, then how come the following code works? (I don't mean any offense, I just started learning this language): printf = function(fmt, ...) io.write(string.format(fmt, ...)) end Set = {} Set.mt = {} -- metatable for sets function Set.new (t) local set = {} setmetatable(set, Set.mt) for _, l in ipairs(t) do set[l] = true end return set end function Set.union (a,b) -- THIS IS THE PART THAT MANAGES OPERATOR OVERLOADING WITH OPERANDS OF DIFFERENT TYPES -- if user built new set using: new_set = some_set + some_number if type(a) == "table" and type(b) == "number" then print("building set...") local mixedset = Set.new{} for k in pairs(a) do mixedset[k] = true end mixedset[b] = true return mixedset -- elseif user built new set using: new_set = some_number + some_set elseif type(b) == "table" and type(a) == "number" then print("building set...") local mixedset = Set.new{} for k in pairs(b) do mixedset[k] = true end mixedset[a] = true return mixedset end if getmetatable(a) ~= Set.mt or getmetatable(b) ~= Set.mt then error("attempt to 'add' a set with a non-set value that is also not a number", 2) end local res = Set.new{} for k in pairs(a) do res[k] = true end for k in pairs(b) do res[k] = true end return res end function Set.tostring (set) local s = "{" local sep = "" for e in pairs(set) do s = s .. sep .. e sep = ", " end return s .. "}" end function Set.print (s) print(Set.tostring(s)) end s1 = Set.new{10, 20, 30, 50} s2 = Set.new{30, 1} Set.mt.__add = Set.union -- now try to make a new set by unioning a set plus a number: s3 = s1 + 8 Set.print(s3) --> {1, 10, 20, 30, 50}

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >