Search Results

Search found 5987 results on 240 pages for 'nested sets'.

Page 20/240 | < Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >

  • Intersection of sets Mongodb

    - by afvasd
    Hi everyone I am new to mongo, this is my db design: product := { name: str group: ref, comments: [ ref, ref, ref, ref ] } comments := { ... a bunch of comments stuff } tag := { _id: int, #Need this for online requests tag: str, products: [ {product: ref, score: float}, ... ], comments: [ {comment: ref, score: float}, ...], } So my usage pattern is: GIVEN a product, find comments that have certain tag and sort them accordingly. My current approach involves: Look for that tag object that has tag=myTag pull all the comments out, sorted look for that product where product.name=myProduct pull all the comments out (which are dbrefs by the way) loop through the result of 2, and checking if they are in 4, (this I can do a limit 10) etc. It's pretty inefficient. Any better methods?

    Read the article

  • Character sets offered in the Eclipse properties

    - by bmargulies
    I've just been handed a pile of Java source that, I suspect, is in ISO-8859-8. Eclipse's menu of charsets, here on my Mac, does not include that. Or any of a wide variety of other encodings supported by the JDK. Is there a recipe for expanding the list of encodings that show up in the menu?

    Read the article

  • Flex 4: Getter getting before setter sets

    - by Steve
    I've created an AS class to use as a data model, shown here: package { import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.http.HTTPService; public class Model { private var xmlService:HTTPService; private var _xml:XML; private var xmlChanged:Boolean = false; public function Model() { } public function loadXML(url:String):void { xmlService = new HTTPService(); if (!url) xmlService.url = "DATAPOINTS.xml"; else xmlService.url = url; xmlService.resultFormat = "e4x"; xmlService.addEventListener(ResultEvent.RESULT, setXML); xmlService.addEventListener(FaultEvent.FAULT, faultXML); xmlService.send(); } private function setXML(event:ResultEvent):void { xmlChanged = true; this._xml = event.result as XML; } private function faultXML(event:FaultEvent):void { Alert.show("RAF data could not be loaded."); } public function get xml():XML { return _xml; } } } And in my main application, I'm initiating the app and calling the loadXML function to get the XML: <fx:Script> <![CDATA[ import mx.containers.Form; import mx.containers.FormItem; import mx.containers.VBox; import mx.controls.Alert; import mx.controls.Button; import mx.controls.Label; import mx.controls.Text; import mx.controls.TextInput; import spark.components.NavigatorContent; private function init():void { var model:Model = new Model(); model.loadXML(null); var xml:XML = model.xml; } ]]> </fx:Script> The trouble I'm having is that the getter function is running before loadXML has finished, so the XML varible in my main app comes up undefined in stack traces. How do I put a condition in here somewhere that tells the getter to wait until the loadXML() function has finished before running?

    Read the article

  • SSIS - 'Execute SQL' Task and Record Sets

    - by Mick Walker
    Hi, How can I access a 'RecordSet' within a 'Execute SQL' task when using SSIS? I have looked at the parameter mapping options within the Execute SQL Task Editor and cannot find a type of object to allow me to pass the variable holding my record set to the task.

    Read the article

  • how to refactor tricky logic involving consecutive sets?

    - by keruilin
    The rule at work here is that users can be awarded badges for a streak of 10, 20, and 30. If the user has a streak over 30, such as 40 or 50, then the logic must be that it only awards a 10-streak badge for 40 and a 20-streak badge for 50, and so on. def check_win_streak(streak) badge = 10 while badge < badge::MAX_STREAK_BADGE_SIZE do # MAX_STREAK_BADGE_SIZE = 30 if streak < badge then break end if (streak % badge == 0) then award_streak_badge(badge) end badge += 10 end end

    Read the article

  • has_many association, nested models and callbacks

    - by fl00r
    Hi! I've got model A and model Attach. I'm editing my A form with nested attributes for :attaches. And when I am deleting all attaches from A via accepts_nested_attributes_for how can I get after_update/after_save callbacks for all of my nested models? Problem is that when I am executing callbacks in model A they are executed right AFTER model A is updated and BEFORE model Attach is updated, so I can't, for example, know if there is NO ANY attaches after I delete them all :). Look for example: my callback after_save :update_status won't work properly after I delete all of my attaches. model A after_save :update_status has_many :attaches accepts_nested_attributes_for :attaches, :reject_if => proc { |attributes| attributes['file'].blank? }, :allow_destroy => true def update_status print "\n\nOUPS! bag is empty!\n\n" if self.attaches.empty? end end model Attach belongs_to A end I am using rails 3 beta

    Read the article

  • Python: How do sets work

    - by Guy
    I have a list of objects which I want to turn into a set. My objects contain a few fields that some of which are o.id and o.area. I want two objects to be equal if these two fields are the same. ie: o1==o2 if and only if o1.area==o2.area and o1.id==o2.id. I tried over-writing __eq__ and __cmp__ but I get the error: TypeError: unhashable instance. What should I over-write?

    Read the article

  • m2eclipse sets JDK compliance to 1.4

    - by jihedamine
    Using eclipse 3.5, when I create a new maven project, m2eclipse automatically adds J2SE1.4 to libraries and Compiler Compliance Level to 1.4 (Project properties Java Compiler). My JRE system library is 1.6 and my default compiler compliance level is 1.6. I don't even have 1.4 installed. Can I make m2eclipse use my default settings and prevent it from modifying project settings?

    Read the article

  • Find inner arrays in nested arrays

    - by 50ndr33
    I have a nested array in PHP: array ( '0' => "+5x", '1' => array ( '0' => "+", '1' => "(", '2' => "+3", '3' => array ( '0' => "+", '1' => "(", '2' => array ( // I want to find this one. '0' => "+", '1' => "(", '2' => "+5", '3' => "-3", '4' => ")" ), '3' => "-3", '4' => ")" ), '4' => ")" ) ); I need to process the innermost arrays here, the one with the comment: "I want to find this one." Is there a function for that? I have thought about doing (written as an idea, not as correct PHP): foreach ($array as $id => $value) { if ($value is array) { $name = $id; foreach ($array[$id] as $id_2 => $value_2) { if ($value_2 is array) { $name .= "." . $id_2; foreach ($array[$id][$id_2] as $id_3 => $value_3) { if ($value_3 is array) { $name .= "." . $id_3; foreach ($array[$id][$id_2][$id_3] as $id_4 => $value_4) { if ($value_4 is array) { $name .= "." . $id_4; foreach [and so it goes on]; } else { $listOfInnerArrays[] = $name; break; } } } else { $listOfInnerArrays[] = $name; break; } } } else { $listOfInnerArrays[] = $name; break; } } } } So what it does is it makes $name the current key in the array. If the value is an array, it goes into it with foreach and adds "." and the id of the array. So we would in the example array end up with: array ( '0' => "1.3.2", ) Then I can process those values to access the innner arrays. The problem is that the array that I'm trying to find the inner arrays of is dynamic and made of a user input. (It splits an input string where it finds + or -, and puts it in a separate nested array if it contains brackets. So if the user types a lot of brackets, there will be a lot of nested arrays.) Therefore I need to make this pattern go for 20 times down, and still it will only catch 20 nested arrays no matter what. Is there a function for that, again? Or is there a way to make it do this without my long code? Maybe make a loop make the necessary number of the foreach pattern and run it through eval()? Long answer to J. Bruni: <?php $liste = array ( '0' => "+5x", '1' => array ( '0' => "+", '1' => "(", '2' => "+3", '3' => array ( '0' => "+", '1' => "(", '2' => array ( '0' => "+", '1' => "(", '2' => "+5", '3' => "-3", '4' => ")" ), '3' => "-3", '4' => ")" ), '4' => ")" ) ); function find_deepest( $item, $key ) { echo "0"; if ( !is_array( $item ) ) return false; foreach( $item as $sub_item ) { if ( is_array( $sub_item ) ) return false; } echo "1"; print_r( $item ); return true; } array_walk_recursive( $liste, 'find_deepest' ); echo "<pre>"; print_r($liste); ?> I wrote echo 0 and 1 to see what the script did, and here is the output: 00000000000000 Array ( [0] => +5x [1] => Array ( [0] => + [1] => ( [2] => +3 [3] => Array ( [0] => + [1] => ( [2] => Array ( [0] => + [1] => ( [2] => +5 [3] => -3 [4] => ) ) [3] => -3 [4] => ) ) [4] => ) ) )

    Read the article

  • Using using to dispose of nested objects

    - by TooFat
    If I have code with nested objects like this do I need to use the nested using statements to make sure that both the SQLCommand and the SQLConnection objects are disposed of properly like shown below or am I ok if the code that instantiates the SQLCommand is within the outer using statement. using (SqlConnection conn = new SqlConnection(sqlConnString)) { using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.CommandText = cmdTextHere; conn.Open(); cmd.Connection = conn; rowsAffected = cmd.ExecuteNonQuery(); } }

    Read the article

  • Crontab sets 18:00 to 09:00

    - by abubacker
    I just want to set a crontab using that I want to make a program run at every 15 minutes from 18:00 to 09:00 I have given this statement and waited but I don't think it is working */15 18-9 * * 1-6 Program_name Any suggestion would be greatly appreciated

    Read the article

  • Effective way to calculate a similarity percentage between data sets

    - by UltraVi01
    I am currently working with User objects -- each of which have many Goal objects. The Goal objects are not User specific, that is, Users can share the same Goal. I am attempting to fashion a way to calculate a "similarity percentage" between two Users... (i.e., taking into account how many Goals they share as well as how many Goals they do not share) Does anyone have experience with this type of situation? I am using Grails with Mysql if that is helpful. Thanks

    Read the article

  • initializing properties with private sets in .Net

    - by Martin Neal
    public class Foo { public string Name { get; private set;} // <-- Because set is private, } void Main() { var bar = new Foo {Name = "baz"}; // <-- This doesn't compile /*The property or indexer 'UserQuery.Foo.Name' cannot be used in this context because the set accessor is inaccessible*/ using (DataContext dc = new DataContext(Connection)) { // yet the following line works. **How**? IEnumerable<Foo> qux = dc.ExecuteQuery<Foo>( "SELECT Name FROM Customer"); } foreach (q in qux) Console.WriteLine(q); } I have just been using the private modifier because it works and kept me from being stupid with my code, but now that I need to create a new Foo, I've just removed the private modifier from my property. I'm just really curious, why does the ExecuteQuery into an IEnumerable of Foo's work?

    Read the article

  • Java ArrayList remove dupes without sets

    - by Kieran
    I'm having problems removing duplicates from an ArrayList. It's for an assignment for college. Here's the code I have already: public int numberOfDiffWords() { ArrayList<String> list = new ArrayList<>(); for(int i=0; i<words.size()-1; i++) { for(int j=i+1; j<words.size(); j++) { if(words.get(i).equals(words.get(j))) { // do nothing } else { list.add(words.get(i)); } } } return list.size(); } The problem is in the numberOfDiffWords() method. The populate list method is working correctly, as my instructor has given me a sample string (containing 4465 words) to analyse - printing words.size() gives the correct result. I want to return the size of the new ArrayList with all duplicates removed. words is an ArrayList class attribute. UPDATE: I should have mentioned I'm only allowed to use dynamic indexed-based storage for this part of the assignment, which means no hash-based storage.

    Read the article

  • Sorted sets and comparators

    - by Jack
    Hello, I'm working with a TreeSetthat is meant to store pathfind locations used during the execution of a A* algorithm. Basically until there are "open" elements (still to be exhaustively visited) the neighbours of every open element are taken into consideration and added to a SortedSetthat keeps them ordered by their cost and heuristic cost. This means that I have a class like: public class PathTileInfo implements Comparable<PathTileInfo> { int cost; int hCost; final int x, y; @Override public int compareTo(PathTileInfo t2) { int c = cost + hCost; int c2 = t2.cost + t2.hCost; int costComp = c < c2 ? -1 : (c > c2 ? 1: 0); return costComp != 0 ? costComp : (x < t2.x || y < t2.y ? -1 : (x > t2.x || y > t2.y ? 1 : 0)); } @Override public boolean equals(Object o2) { if (o2 instanceof PathTileInfo) { PathTileInfo i = (PathTileInfo)o2; return i.cost + i.hCost == cost + hCost && x == i.x && y == i.y; } return false; } } In this way first the total cost is considered, then, since a total ordering is needed (consistency with equals) a ordering according to the x,y coordinate is taken into account. This should work but simply it doesn't, if I iterate over the TreeSet during the algorithm execution like in for (PathTileInfo t : openSet) System.out.print("("+t.x+","+t.y+","+(t.cost+t.hCost)+") "); I get results in which the right ordering is not kept, eg: (7,7,6) (7,6,7) (6,8,6) (6,6,7) (5,8,7) (5,7,7) (6,7,6) (6,6,7) (6,5,7) (5,7,7) (5,5,8) (4,7,7) (4,6,8) (4,5,8) is there something subtle I am missing? Thanks!

    Read the article

  • Displaying Nested Array Content with Time Delay in Flex

    - by MooCow
    I have a JSON array that look like this: (array here) I'm trying to use Flex to display each Project and its Milestone elements similar to a nested for-loop for 15 seconds per Milestone element before advancing to the next Project. I was shown a technique that works well for something without another array buried into it. var key:int = 0; var timer:timer = new timer (10000, project.length); timer.addEventListener (TimerEvent.TIMER, function showStuff(event:EVENT):void { trace project[key].projectName; key++; }); timer.start(); But that only replicate a single FOR-LOOP and not a nested FOR-LOOP. Any suggestions?

    Read the article

  • Simple user control for conditionally rendering nested HTML

    - by Goyuix
    What I would like to do, is be able to pass two attributes to a user control, a ListName and a Permission, like so: <uc:check id="uc" List="Shared Documents" Permission="OpenItems" runat="server"> <!-- have some HTML content here that is rendered if the permission is true --> </uc:check> Then in the actual check user control, have something similar to: <%@ Control language="C#" ClassName="check" %> <% // determine permission magic placeholder if (DoesUserHavePermissions(perm)) { // render nested HTML content } else { // abort rendering as to not show nested HTML content } %> I have read the page on creating a templated control on MSDN, and while that would work - it really seems to be a bit overkill for what I am trying to do. Is there a control that already renders content based on a boolean expression or a simpler template example? http://msdn.microsoft.com/en-us/library/36574bf6.aspx

    Read the article

  • Having two sets of input combined on hadoop

    - by aeolist
    I have a rather simple hadoop question which i'll try to present with an example say you have a list of strings and a large file and you want each mapper to process a piece of the file and one of the strings in a grep like program. how are you supposed to do that? I am under the impression that the number of mappers is a result of the inputsplits produced. I could run subsequent jobs, one for each string, but it seems kinda... messy?

    Read the article

  • JSON is not nested in rails view

    - by SeanGeneva
    I have a several models in a heirarchy, 1:many at each level. Each class is associated only with the class above it and the one below it, ie: L1 course, L2 unit, L3 unit layout, L4 layout fields, L5 table fields (not in code, but a sibling of layout fields) I am trying to build a JSON response of the entire hierarchy. def show @course = Course.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json do @course = Course.find(params[:id]) @units = @course.units.all @unit_layouts = UnitLayout.where(:unit_id => @units) @layout_fields = LayoutField.where(:unit_layout_id => @unit_layouts) response = {:course => @course, :units => @units, :unit_layouts => @unit_layouts, :layout_fields => @layout_fields} respond_to do |format| format.json {render :json => response } end end end end The code is bring back the correct values, but the units, unit_layouts and layout_fields are all nested at the same level under course. I would like them to be nested inside their parent.

    Read the article

  • How to override a related sets "add" method?

    - by MB_
    I am working on a django project and i want to send a signal when something get's added to some models related set, e.g. we have an owner wo has a set of collectables and each time the method owner.collectable_set.add(something) is getting called i want signal like "collectable_added" or something. signals are clear to me, but in which manager(?) the "add" method sits that i want to override is unclear to me.

    Read the article

  • Streaming large result sets with MySQL

    - by configurator
    I'm developing a spring application that uses large MySQL tables. When loading large tables, I get an OutOfMemoryException, since the driver tries to load the entire table into application memory. I tried using statement.setFetchSize(Integer.MIN_VALUE); but then every ResultSet I open hangs on close(); looking online I found that that happens because it tries loading any unread rows before closing the ResultSet, but that is not the case since I do this: ResultSet existingRecords = getTableData(tablename); try { while (existingRecords.next()) { // ... } } finally { existingRecords.close(); // this line is hanging, and there was no exception in the try clause } The hangs happen for small tables (3 rows) as well, and if I don't close the RecordSet (which happened in one method) then connection.close() hangs.

    Read the article

  • Creating attribute sets and attributes programatically magento

    - by digital_paki
    I am using the code listed on the following link =: http://www.magentocommerce.com/wiki/5_-_modules_and_development/catalog/programmatically_adding_attributes_and_attribute_sets Everything works until the point: // Just add a default group. else { $this->logInfo("Creating default group [{$this->groupName}] for set."); $modelGroup = Mage::getModel('eav/entity_attribute_group'); $modelGroup->setAttributeGroupName($this->groupName); $modelGroup->setAttributeSetId($id); // This is optional, and just a sorting index in the case of // multiple groups. // $modelGroup->setSortOrder(1); $model->setGroups(array($modelGroup)); } I am unsure where the object reference would need to be set from - I am attempting to have this as a separate file that can be automated - I am running this file by doing a require_once 'app/Mage.php'; Mage::app(); Any help in this would be greatly appreciated Thanks

    Read the article

< Previous Page | 16 17 18 19 20 21 22 23 24 25 26 27  | Next Page >