Search Results

Search found 163 results on 7 pages for 'banana'.

Page 2/7 | < Previous Page | 1 2 3 4 5 6 7  | Next Page >

  • Pros and cons of making database IDs consistent and "readable"

    - by gmale
    Question Is it a good rule of thumb for database IDs to be "meaningless?" Conversely, are there significant benefits from having IDs structured in a way where they can be recognized at a glance? What are the pros and cons? Background I just had a debate with my coworkers about the consistency of the IDs in our database. We have a data-driven application that leverages spring so that we rarely ever have to change code. That means, if there's a problem, a data change is usually the solution. My argument was that by making IDs consistent and readable, we save ourselves significant time and headaches, long term. Once the IDs are set, they don't have to change often and if done right, future changes won't be difficult. My coworkers position was that IDs should never matter. Encoding information into the ID violates DB design policies and keeping them orderly requires extra work that, "we don't have time for." I can't find anything online to support either position. So I'm turning to all the gurus here at SA! Example Imagine this simplified list of database records representing food in a grocery store, the first set represents data that has meaning encoded in the IDs, while the second does not: ID's with meaning: Type 1 Fruit 2 Veggie Product 101 Apple 102 Banana 103 Orange 201 Lettuce 202 Onion 203 Carrot Location 41 Aisle four top shelf 42 Aisle four bottom shelf 51 Aisle five top shelf 52 Aisle five bottom shelf ProductLocation 10141 Apple on aisle four top shelf 10241 Banana on aisle four top shelf //just by reading the ids, it's easy to recongnize that these are both Fruit on Aisle 4 ID's without meaning: Type 1 Fruit 2 Veggie Product 1 Apple 2 Banana 3 Orange 4 Lettuce 5 Onion 6 Carrot Location 1 Aisle four top shelf 2 Aisle four bottom shelf 3 Aisle five top shelf 4 Aisle five bottom shelf ProductLocation 1 Apple on aisle four top shelf 2 Banana on aisle four top shelf //given the IDs, it's harder to see that these are both fruit on aisle 4 Summary What are the pros and cons of keeping IDs readable and consistent? Which approach do you generally prefer and why? Is there an accepted industry best-practice?

    Read the article

  • Python: Errors saving and loading objects with pickle module

    - by Peterstone
    Hi, I am trying to load and save objects with this piece of code I get it from a question I asked a week ago: Python: saving and loading objects and using pickle. The piece of code is this: class Fruits: pass banana = Fruits() banana.color = 'yellow' banana.value = 30 import pickle filehandler = open("Fruits.obj","wb") pickle.dump(banana,filehandler) filehandler.close() file = open("Fruits.obj",'rb') object_file = pickle.load(file) file.close() print(object_file.color, object_file.value, sep=', ') At a first glance the piece of code works well, getting load and see the 'color' and 'value' of the saved object. But, what I pursuit is to close a session, open a new one and load what I save in a past session. I close the session after putting the line filehandler.close() and I open a new one and I put the rest of your code, then after putting object_file = pickle.load(file) I get this error: Traceback (most recent call last): File "<pyshell#5>", line 1, in <module> object_file = pickle.load(file) File "C:\Python31\lib\pickle.py", line 1365, in load encoding=encoding, errors=errors).load() AttributeError: 'module' object has no attribute 'Fruits' Can anyone explain me what this error message means and telling me how to solve this problem? Thank so much and happy new year!!

    Read the article

  • MySQL LIMIT 1 but query 15 rows?

    - by Ian
    Basically what I'm trying to do is compare the ID's of rows against 15 results in MySQL, eliminating all but 1 (using NOT IN) and then pull that result. Now normally this would be fine by itself, however the order of the 15 rows I'm doing the SQL query for are constantly changing based on a ranking, so there is a possibility that between the time the ranking updates, and the ajax request (which I submit the ID's for NOT IN) more than just one ID has changed, which would of course bring back more than one row which I do not want. So in short, is there a way in which I can query 15 rows, but only return one? Without having to run two separate queries. Any help is appreciated, thank you. EXAMPLE: Say I have 7 items in my database, and I'm displaying 5 on the page to the user. These are what are being displayed to the user: Apple Orange Kiwi Banana Grape But in the database I also have Peach Blackberry Now what I want to do is if the user deletes an item from their list, it will add another item (based on a ranking they have) Now the issue is, in order to know what they have on their list at the moment I send the remaining items to the database (say they deleted Kiwi, I would send Apple, Orange, Banana, and Grape) So now I select the highest ranked 5 items from are remaining six items, make sure they are not the ones already displayed on the page, and then add the new one to list (either Peach or Blackberry) All good and well, except that if both peach and blackberry now outrank grape, then I will be returning two results instead of just one. Because it would've searched... Apple Orange Banana Peach Blackberry and excluded... Apple Orange Banana Grape Which leaves us with both Peach and Blackberry, instead of just Peach or Blackberry

    Read the article

  • Sort each standalone line alphabetically

    - by Daniel
    I want to sort some items in alphabetic order, but in a very specifc way. I have, for example, the following list, each item separated by comma: monkeys, dogs, cats pineapple, banana, orange yellow, red, blue, green silver, gold, platinum delphi, java, c++, visual basic I want to sort each line alphabetically, WITHOUT changing line order. My desired result would be: cats, dogs, monkeys banana, orange, pineapple blue, green, red, yellow gold, platinum, silver c++, delphi, java, visual basic My target list has got 3000+ lines, so it should be an automated process. Thanks!

    Read the article

  • gcc returns error with nested class

    - by Nate
    Howdy, I am attempting to use the fully qualified name of my nested class as below, but the compiler is balking! template <class T> class Apple { //constructors, members, whatevers, etc... public: class Banana { public: Banana() { //etc... } //other constructors, members, etc... }; }; template <class K> class Carrot{ public: //etc... void problemFunction() { Apple<int>::Banana freshBanana = someVar.returnsABanana(); //line 85 giveMonkey(freshBanana); //line 86 } }; My issue is, the compiler says: Carrot.h:85: error: expected ';' before 'freshBanana' Carrot.h:86: error: 'freshBanana' was not declared in this scope I had thought that using the fully qualified name permitted me to access this nested class? It's probably going to smack me in the face, but what on earth am I not seeing here??

    Read the article

  • Use some CSS properties in many selectors without editing HTML or using JS

    - by OrB
    CSS: .bananaTrans { -moz-transition : all 1s ease-in-out; -webkit-transition: all 1s ease-in-out; transition : all 1s ease-in-out; } .bananaClass { color: yellow; } HTML: <div class="bananaClass">Banana Banana Banana</div> The objective is to make every element that has class "bananaClass" inherit the properties of "bananaTrans" without editing the HTML or using JavaScript. It ("bananaTrans") don't need exactly to be a class, it's just a bunch of properties to be used amongst other selectors.

    Read the article

  • Grouping a query with php

    - by Tom Hoad
    Basic question! I have 2 tables FRUIT id | fruit_name ------------------- 1 | Apple 2 | Banana 3 | Carrot VARIETIES id | fk_fruit_id | variety_name --------------------------------------- 1 1 Cox 2 1 Braeburn 3 2 Chester 4 3 Kotaka 5 3 Imperial 6 3 Oneal I'd like to output a list of varieties per fruit e.g. APPLE - Cox, Braeburn BANANA - Chester CARROT - Kotaka, Imperial, Oneal My current code is $query = "SELECT * FROM produce, varieties WHERE produce.id = varieties.fk_fruit_id"; $result = mysql_query($query) or die('Error : ' . mysql_error()); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $produce_fruit_code = $row['fruit_code']; $variety_name = $row['variety_name']; echo $produce_fruit_code.' - '.$variety_name.'<br/>'; } which outputs: Apple - Cox Apple - Braeburn Banana - Chester Carrot - Kotaka Carrot - Imperial Carrot - Oneal Not a million miles away, but still not there. Any help is much appreciated, thanks!

    Read the article

  • Can't Reorder a UITableViewCell into _some_ empty sections of a UITableView

    - by Jeremy Lightsmith
    If I have a UITableView in edit mode, w/ reordering turned on, it seems I can't move some (but not all) cells into some (but not all) empty sections. For example, if I have this layout : Section 1 apple banana Section 2 doberman Section 3 Section 4 Then I can move 'doberman' into any slot in section 1 (except after 'banana'), but I can't move it into section 3 or 4 at all. On the other hand, I can move 'apple' & 'banana' into section section 2 (except after 'doberman'), and I CAN move it into section 3, but NOT into section 4. What gives? this seems like buggy behavior. How do people work around it? Is apple aware of this bug?

    Read the article

  • How can I generate a list of words made up of combinations of three word lists in Perl?

    - by Chris Denman
    I have three lists of words. I would like to generate a single list of all the combinations of words from the three lists. List 1: red green blue List 2: one two List 3: apple banana The final list would like like so: red one apple red two apple red one banana red two banana ... and so on Ideally I'd like to pass in three arrays and the routine return one array. I have done a simple loop like so: foreach $word1 (@list1){ foreach $word2 (@list2){ foreach $word3 (@list3){ print "$word1 $word2 $word3\n"; } } } However, this doesn't work if there's nothing in the second or third list (I may only want to iterate between one, two or three lists at a time - in other words, if I only supply two lists it should iterate between those two lists).

    Read the article

  • Change ID to text in paragraph with jQuery

    - by Reuben
    I would like to take what text is in my p tag and make that the p tags parent (div) that ID. I would also like to add a _ for any spaces in the p tag. Example: <div class="circle"><p>Apple</p></div> <div class="circle"><p>Banana</p></div> <div class="circle"><p>Carrot Juice</p></div> to <div id="Apple" class="circle"><p>Apple</p></div> <div id="Banana" class="circle"><p>Banana</p></div> <div id="Carrot_Juice" class="circle"><p>Carrot Juice</p></div>

    Read the article

  • how to add markup to text using JavaScript regex

    - by Richard
    I need to add markup to some text using JavaScript regular expressions. In Python I could do this with: >>> import re >>> re.sub('(banana|apple)', r'<b>{\1}</b>', 'I have 1 banana and 2 apples!') 'I have 1 <b>{banana}</b> and 2 <b>{apple}</b>s!' What is the equivalent in JavaScript? string.replace(regex, newstring) seems to only take a raw string for replacing.

    Read the article

  • Order a sentence alphabetically and count the number of times each words appears and print in a table

    - by JaAnTr
    I am struggling with the print in a table part of the question. So far I have managed to order the user inputted sentence alphabetically and count the number of times each word occurs. Here is the code: thestring = (raw_input()) sentence = thestring.split(" ") sentence.sort() count = {} for word in thestring.split(): try: count[word] += 1 except KeyError: count[word] = 1 print sentence print count And when I run the code I get this: ['apple', 'apple', 'banana', 'mango', 'orange', 'pear', 'pear', 'strawberry'] {'apple': 2, 'pear': 2, 'strawberry': 1, 'mango': 1, 'orange': 1, 'banana': 1} However, ideally I want it printed in a table that looks something like: apple.....|.....2 banana....|.....1 mango.....|.....1 orange....|.....1 pear......|.....2 strawberry|.....1 Thanks for any help!

    Read the article

  • Constant Assigment Bug in Ruby?

    - by aronchick
    We caught some code in Ruby that seems odd, and I was wondering if someone could explain it: $ irb irb(main):001:0> APPLE = 'aaa' => "aaa" irb(main):002:0> banana = APPLE => "aaa" irb(main):003:0> banana << 'bbb' => "aaabbb" irb(main):004:0> banana => "aaabbb" irb(main):005:0> APPLE => "aaabbb" Catch that? The constant was appended to at the same time the local variable was. Known behavior? Expected?

    Read the article

  • EF4 (CPT5) ForeignKeyAttribute in base class - Assert Failure entityType != null

    - by Anthony Johnston
    Getting an error when trying to set a ForeignKeyAttribute in a base class class User{} abstract class FruitBase{ [ForeignKey("CreateById")] public User CreateBy{ get; set; } public int CreateById{ get; set; } } class Banana{} class DataContext : DbContext{ DbSet<Banana> Bananas{ get; set; } } If I move the FruitBase code into the banana, all is well, but I don't want to, as there will be many many fruit and I want to remain relatively DRY if I can Is this a know issue that will be fixed by March? Does anyone know a work around?

    Read the article

  • How to $.extend 2 objects by adding numerical values together from keys with the same name?

    - by muudless
    I currently have 2 obj and using the jquery extend function, however it's overriding value from keys with the same name. How can I add the values together instead? obj1 = {"orange":2,"apple":1, "grape":1} obj2 = {"orange":5,"apple":1, "banana":1} mergedObj = $.extend({}, obj1, obj2); var printObj = typeof JSON != "undefined" ? JSON.stringify : function(obj) { var arr = []; $.each(obj, function(key, val) { var next = key + ": "; next += $.isPlainObject(val) ? printObj(val) : val; arr.push( next ); }); return "{ " + arr.join(", ") + " }"; }; console.log('all together: '+printObj(mergedObj) ); And I get obj1 = {"orange":5,"apple":1, "grape":1, "banana":1} What I need is obj1 = {"orange":7,"apple":2, "grape":1, "banana":1}

    Read the article

  • Handling multiple exceptions

    - by the-banana-king
    Hi there, I have written a class which loads configuration objects of my application and keeps track of them so that I can easily write out changes or reload the whole configuration at once with a single method call. However, each configuration object might potentially throw an exception when doing IO, yet I do not want those errors to cancel the overall process so that the other objects are still given a chance to reload/write. Therefore I collect all exceptions which are thrown while iterating over the objects and store them in a super-exception, which is thrown after the loop, since each exception must still be handled and someone has to be notified of what exactly went wrong. However, that approach looks a bit odd to me. Someone out there with a cleaner solution? Here is some code of the mentioned class: public synchronized void store() throws MultipleCauseException { MultipleCauseException me = new MultipleCauseException("unable to store some resources"); for(Resource resource : this.resources.values()) { try { resource.store(); } catch(StoreException e) { me.addCause(e); } } if(me.hasCauses()) throw me; }

    Read the article

  • Create array of objects based on another array?

    - by xckpd7
    I want to take an array like this: var food = [ { name: 'strawberry', type: 'fruit', color: 'red', id: 3483 }, { name: 'apple', type: 'fruit', color: 'red', id: 3418 }, { name: 'banana', type: 'fruit', color: 'yellow', id: 3458 }, { name: 'brocolli', type: 'vegetable', color: 'green', id: 1458 }, { name: 'steak', type: 'meat', color: 'brown', id: 2458 }, ] And I want to create something like this dynamically: var foodCategories = [ { name: 'fruit', items: [ { name: 'apple', type: 'fruit', color: 'red', id: 3418 }, { name: 'banana', type: 'fruit', color: 'yellow', id: 3458 } ] }, { name: 'vegetable', items: [ { name: 'brocolli', type: 'vegetable', color: 'green', id: 1458 }, ] }, { name: 'meat', items: [ { name: 'steak', type: 'meat', color: 'brown', id: 2458 } ] } ] What's the best way to go about doing this?

    Read the article

  • Parsing a file with hierarchical structure in Python

    - by Kevin Stargel
    I'm trying to parse the output from a tool into a data structure but I'm having some difficulty getting things right. The file looks like this: Fruits Apple Auxiliary Core Extras Banana Something Coconut Vegetables Eggplant Rutabaga You can see that top-level items are indented by one space, and items beneath that are indented by two spaces for each level. The items are also in alphabetical order. How do I turn the file into a Python list that's something like ["Fruits", "Fruits/Apple", "Fruits/Banana", ..., "Vegetables", "Vegetables/Eggplant", "Vegetables/Rutabaga"]?

    Read the article

  • How should I write this string-prefix check so that it's idiomatic Python?

    - by Kevin Stargel
    I have a couple of lists of items: specials = ['apple', 'banana', 'cherry', ...] smoothies = ['banana-apple', 'mocha mango', ...] I want to make a new list, special_smoothies, consisting of elements in smoothies that start with the elements in specials. However, if specials is blank, special_smoothies should be identical to smoothies. What's the most Pythonic way to do this? Is there a way to do this without a separate conditional check on whether specials is blank?

    Read the article

  • htaccess: Redirect a Dynamic URL - Show only Static URL - Double Content

    - by elmaso
    Hi, I have a rewrite rule to get clean urls.. the only problem is, google shows some dynamic url and i dont want to serve dynamic urls. What I want: if a user types in the dynamic url, he gets redirected to the clean url.. example: http://www.example.com/?index=bananas (if someone types that in, he gets redirect to the url above) http://www.examplcom/bananas/ this is my htacces: Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond $1 !apple\+banana RewriteRule ^(.*)\+apple\+banana/$ ?q=$1 [L] thank you!!

    Read the article

< Previous Page | 1 2 3 4 5 6 7  | Next Page >