Daily Archives

Articles indexed Wednesday April 14 2010

Page 14/122 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • [Ruby] Modifying object inside a loop doesn't change object outside of the loop?

    - by Jergason
    I am having problems with modifying objects inside blocks and not getting the expected values outside the blocks. This chunk of code is supposed to transform a bunch of points in 3d space, calculate a score (the rmsd or root mean squared deviation), and store both the score and the set of points that produced that score if it is lower than the current lowest score. At the end, I want to print out the best bunch of points. first = get_transformed_points(ARGV[0]) second = get_transformed_points(ARGV[1]) best_rmsd = first.rmsd(second) best_points = second #transform the points around x, y, and z and get the rmsd. If the new points # have a smaller rmsd, store them. ROTATION = 30 #rotate by ROTATION degrees num_rotations = 360/ROTATION radians = ROTATION * (Math::PI/180) num_rotations.times do |i| second = second * x_rotate num_rotations.times do |j| second = second * y_rotate num_rotations.times do |k| second = second * z_rotate rmsd = first.rmsd(second) if rmsd < best_rmsd then best_points = second best_rmsd = rmsd end end end end File.open("#{ARGV[1]}.out", "w") {|f| f.write(best_points.to_s)} I can print out the points that are getting stored inside the block, and they are getting transformed and stored correctly. However, when I write out the points to a file at the end, they are the same as the initial set of points. Somehow the best_points = second chunk doesn't seem to be doing anything outside of the block. It seems like there are some scoping rules that I don't understand here. I had thought that since I declared and defined best_points above, outside of the blocks, that it would be updated inside the blocks. However, it seems that when the blocks end, it somehow reverts back to the original value. Any ideas how to fix this? Is this a problem with blocks specifically?

    Read the article

  • Spring MVC: should service layer be returning operation specific DTO's ?

    - by arrages
    In my Spring MVC application I am using DTO in the presentation layer in order to encapsulate the domain model in the service layer. The DTO's are being used as the spring form backing objects. hence my services look something like this: userService.storeUser(NewUserRequestDTO req); The service layer will translate DTO - Domain object and do the rest of the work. Now my problem is that when I want to retrieve a DTO from the service to perform say an Update or Display I can't seem to find a better way to do it then to have multiple methods for the lookup that return different DTO's like... EditUserRequestDTO userService.loadUserForEdit(int id); DisplayUserDTO userService.loadUserForDisplay(int id); but something does not feel right about this approach. The reason do have separate DTO's is that DisplayUserDTO is strongly typed to be read only and also there are many properties of user that are entities from a lookup table in the db (like city and state) so the DisplayUserDTO would have the string description of the properties while the EditUserRequestDTO will have the id's that will back the select drop down lists in the forms. What do you think? thanks

    Read the article

  • Updating Model with entity collection

    - by jean27
    There are a group of entities named Book and Magazine which inherits from the abstract class PublishedItem. PublishedItem have these properties: ID, Name, Publisher, List of Authors, List of Genres. The Book entity has the ISBN property and the Magazine entity has the ISSN property. I just want to ask how I can update the book's or magazine's list of genres or list of authors?

    Read the article

  • GRAPH PROBLEM: find an algorithm to determine the shortest path from one point to another in a recta

    - by newba
    I'm getting such an headache trying to elaborate an appropriate algorithm to go from a START position to a EXIT position in a maze. For what is worth, the maze is rectangular, maxsize 500x500 and, in theory, is resolvable by DFS with some branch and bound techniques ... 10 3 4 7 6 3 3 1 2 2 1 0 2 2 2 4 2 2 5 2 2 1 3 0 2 2 2 2 1 3 3 4 2 3 4 4 3 1 1 3 1 2 2 4 2 2 1 Output: 5 1 4 2 Explanation: Our agent looses energy every time he gives a step and he can only move UP, DOWN, LEFT and RIGHT. Also, if the agent arrives with a remaining energy of zero or less, he dies, so we print something like "Impossible". So, in the input 10 is the initial agent's energy, 3 4 is the START position (i.e. column 3, line 4) and we have a maze 7x6. Think this as a kind of labyrinth, in which I want to find the exit that gives the agent a better remaining energy (shortest path). In case there are paths which lead to the same remaining energy, we choose the one which has the small number of steps, of course. I need to know if a DFS to a maze 500x500 in the worst case is feasible with these limitations and how to do it, storing the remaining energy in each step and the number of steps taken so far. The output means the agent arrived with remaining energy= 5 to the exit pos 1 4 in 2 steps. If we look carefully, in this maze it's also possible to exit at pos 3 1 (column 3, row 1) with the same energy but with 3 steps, so we choose the better one. With these in mind, can someone help me some code or pseudo-code? I have troubles working this around with a 2D array and how to store the remaining energy, the path (or number of steps taken)....

    Read the article

  • C++ detecting end of file

    - by xbonez
    I have a C++ program that is reading in info from a file, that stores info seperated by "$$$$". An example of how the file looks is: abc bcd $$$$ def $$$$ qwe gfh $$$$ How can I detect the file has ended, without using the eof() function? I have it set like this, getline(sin,temp) if (temp=="$$$$") { } After reading the last set of four dollars, how can I check the next line to ensure another set of data isn't beginning, and that the file has ended? If the file has indeed ended, I plan on using a boolean flag to terminate the while loop.

    Read the article

  • Access denied when trying to read information about SharePoint groups

    - by strongopinions
    I am trying to get the membership of a group in WSS 3.0. I am doing this in an elevated permissions block. Here is the code: SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { using (SPWeb rootWeb = site.RootWeb) { SPGroup gAdmins = rootWeb.SiteGroups["Admins"]; } } }); I get taken to the "access denied" SharePoint screen when I run this code. The group exists. The identity of the application pool for the web application is in the dbo role in the content database. The code works on my development server, but not on another server, which leads me to believe there is something wrong with the permissions or configuration on this server, maybe something in dcomcnfg? Here are some lines from the SharePoint log that seem to be related: PermissionMask check failed. asking for 0x08000000, have 0x00000000 Unknown SPRequest error occurred. More information: 0x80070005 Access Denied for /Pages/UserAdmin.aspx. StackTrace: Microsoft.SharePoint.Utilities.SPUtility:Void HandleAccessDenied(System.Exception), Microsoft.SharePoint.SPGlobal:Void HandleUnauthorizedAccessException(System.UnauthorizedAccessException), .... [UserAdmin.aspx hosts my custom web part containing the code]

    Read the article

  • nginx + ssi + remote uri access does not work

    - by stunti
    I have a setup where my nginx is in front with apache+PHP behind. My PHP application cache some page in memcache which are accessed by nginx directly except some dynamic part which are build using SSI in Nginx. The first problem I had was nginx didnt try to use memcache for ssi URI. <!--# include virtual="/myuser" --> So I figured that if I force it to use a full URL, it would do it. <!--# include virtual="http://www.example.com/myuser" --> But in logs file (both nginx and apache) I can see that a slash has been added at the beginning of the url http ssi filter "/http://www.example.com/myuser" In the source code of the SSI module I see a PREFIX that seems to be added, but I can really tell if I can disable it. Anybody got this issue? Nginx version : 0.7.62 on Ubuntu Karmic 64bits Thanks a lot

    Read the article

  • SharePoint 2007 Force Culture and UI Culture

    - by jdcorr
    i'm developing a sharepoint portal, and i want to force a portal culture to 'pt-PT', i already installed the moss and wss language packs and i changed the web.config too with the following statment: but if i set the browser language to other language the controls change their culture (this only occurs in portal frontoffice, in backoffice the culture is always pt). What i have to do to fix this problem?

    Read the article

  • NHibernate and SetSessionAuth audit columns

    - by user86431
    We have audit columns set by triggers. For obscure security reasons predating my tenure and out of my control, we log in with a generic user, and do a 'set session authorization' to change the user to the db user of the user who is logged in. When we converted to NHibernate, it creates a whole new session and jacks everything up when we try to do a set session auth, so we turned the set session auth off... Now we are trying to find out a way to get NHibernate to let us do 'set session authorization' without recycling the session on us, so we can use our existing trigger based audit column stuff with both legacy apps, and our new NHibernate apps. It's not a ideal soloution, or the best way to do it even, but is it possible? I was hoping there was a alternate interface that allowed this kind of access. Does anyone know how to do it, or can you point me towards and good hints? Thanks, Eric-

    Read the article

  • PHP XML Validation

    - by efritz
    What's the best way to validate an XML file (or a portion of it) against multiple XSD files? For example, I have the following schema for a configuration loader: <xsd:schema xmlns="http://www.kauriproject.org/schema/configuration" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.kauriproject.org/schema/configuration" elementFormDefault="qualified"> <xsd:element name="configuration" type="configuration" /> <xsd:complexType name="configuration"> <xsd:choice maxOccurs="unbounded"> <xsd:element name="import" type="import" minOccurs="0" maxOccurs="unbounded" /> <xsd:element name="section" type="section" /> </xsd:choice> </xsd:complexType> <xsd:complexType name="section"> <xsd:sequence> <xsd:any minOccurs="0" maxOccurs="unbounded" processContents="lax" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" use="required" /> <xsd:attribute name="type" type="xsd:string" use="required" /> </xsd:complexType> <xsd:complexType name="import" mixed="true"> <xsd:attribute name="resource" type="xsd:string" /> </xsd:complexType> </xsd:schema> As the Configuration class exists now, it lets one add a <section> tag with a define concrete parser class (much like custom configuration sections in ASP.NET). However, I'm unsure of how to validate the section being parsed. If it possible to validate just this section of code with an XSD file/string without writing it back to a file?

    Read the article

  • Show all objects on canvas in window

    - by Number8
    Hello -- We have a canvas with a large number of objects. The user can pan and zoom the view of the canvas. I am trying to figure out how to implement "show entire canvas" -- that is, zoom and center the canvas in the window to show all objects. We know the max and min X and Y coordinates. I am looking at our current zoom and pan implementations to try to figure out if there is a way to use them. Any suggestions on how to do this would be appreciated... Thanks.

    Read the article

  • Best practice for system clock sync on KVM host

    - by Tauren
    I have an Ubuntu 9.10 server running as a KVM host with ntpd installed on it. The host system has the correct system time. At the moment I only have a single KVM guest, also Ubuntu 9.10 server. I do not have ntpd installed on it, and I just discovered the clock is about 6 minutes slow. It wasn't that way when it was installed about a month ago. I thought that I only needed to keep the host clock synchronized and that the guests used the host clock. But maybe that is a memory from using OpenVZ. I believe the reasoning was related to only the host could modify the physical system clock. Is running ntpd on both the host and all the guests the correct thing to do? Or is there something else that is preferred? How should I keep the guest clocks in sync?

    Read the article

  • Hosting SQL at remote location?

    - by Syd
    Hey guys, My OSCommerce site includes a separately programmed feature for which I use SQL tables. I've decided to host its tables on a remote site offering free SQL accounts. I'd like to know if there could be any disadvantages to this approach. Thanks Syd

    Read the article

  • JqueryUI dialog box causes button to lose styling

    - by superexsl
    Hey everyone, I'm using JQueryUI dialog boxes and, while it works, it seems to remove any CSS styling on the button that opens the dialog. I have to manually refresh the page to get the styling back. An example button which launches the dialog: (button_submit is my CSS theme and launc_popup is used to detect the button click in JQuery. <asp:Button ID="btnLaunch" CssClass="button_sub launch_popup" runat="server" Text="Dialog..." CausesValidation="false" OnClientClick="return false;" /> My jquery: $('.launch_popup').click(function() { $("#dialog-form").dialog("open"); }); My dialog-form: $("#dialog-form").dialog({ autoOpen: false, height: 300, width: 300, modal: true, buttons: { 'Close': function() { $(this).dialog('close'); } } }); This happens to all the buttons that open dialogs. Is there a way to 'restyle' the button without refreshing the page? (It's in an updatepanel if that makes a difference, although this bit's client-side so not sure if that should affect it). Thanks for any help

    Read the article

  • c# Convert LINQ var result to actual type

    - by DrBob
    In c#, Given the following code: public class Person { public int PersonID { get; set; } public int Age { get; set; } public string Name { get; set; } } and List<Person> people = new List<Person>(); for (int i = 0; i != 15; i++) { Person p = new Person(); p.PersonID = i; p.Age = i * 12; p.Name = "Name " + i; people.Add(p); } var sortedPeople = from qPeople in people where qPeople.Age > 0 && qPeople.Age < 25 || qPeople.Age > 100 orderby qPeople.Age descending select qPeople; Can I load the results of sortedPeople back into a List<Person without a loop? Thanks.

    Read the article

  • Clicking Elements in Android Doesn't Display the Correct Values

    - by Devin
    I apologize if this code looks a bit like a mess (considering the length); I figured I'd just include everything that goes on in my program at the moment. I'm attempting to create a fairly simple Tic Tac Toe app for Android. I've set up my UI nicely so far so that there are a "grid" of TextViews. As a sort of "debug" right now, I have it so that when one clicks on a TextView, it should display the value of buttonId in a message box. Right now, it displays the correct assigned value for the first element I click, but no matter what I click afterwards, it always just displays the first value buttonID had. I attempted to debug it but couldn't exactly find a point where it would pull the old value (to the best of my knowledge, it reassigned the value). There's a good possibility I'm missing something small, because this is my first Android project (of any note). Can someone help get different values of buttonId to appear or point out the error in my logic? The code: package com.TicTacToe.app; import com.TicTacToe.app.R; //Other import statements public class TicTacToe extends Activity { public String player = "X"; public int ALERT_ID; public int buttonId; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Sets up instances of UI elements final TextView playerText = (TextView)findViewById(R.id.CurrentPlayerDisp); final Button button = (Button) findViewById(R.id.SetPlayer); final TextView location1 = (TextView)findViewById(R.id.location1); final TextView location2 = (TextView)findViewById(R.id.location2); final TextView location3 = (TextView)findViewById(R.id.location3); final TextView location4 = (TextView)findViewById(R.id.location4); final TextView location5 = (TextView)findViewById(R.id.location5); final TextView location6 = (TextView)findViewById(R.id.location6); final TextView location7 = (TextView)findViewById(R.id.location7); final TextView location8 = (TextView)findViewById(R.id.location8); final TextView location9 = (TextView)findViewById(R.id.location9); playerText.setText(player); //Handlers for events button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Perform action on click if (player.equals("X")){ player = "O"; playerText.setText(player); } else if(player.equals("O")){ player = "X"; playerText.setText(player); } //Sets up the dialog buttonId = 0; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 1; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 2; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 3; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location4.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 4; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location5.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 5; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location6.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 6; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location7.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 7; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location8.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 8; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); location9.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Sets up the dialog buttonId = 9; ALERT_ID = 0; onCreateDialog(ALERT_ID); showDialog(ALERT_ID); } }); } protected Dialog onCreateDialog(int id){ String msgString = "You are on spot " + buttonId; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(msgString) .setCancelable(false) .setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); return alert; } }

    Read the article

  • Good hash function for a 2d index

    - by rlbond
    I have a struct called Point. Point is pretty simple: struct Point { Row row; Column column; // some other code for addition and subtraction of points is there too } Row and Column are basically glorified ints, but I got sick of accidentally transposing the input arguments to functions and gave them each a wrapper class. Right now I use a set of points, but repeated lookups are really slowing things down. I want to switch to an unordered_set. So, I want to have an unordered_set of Points. Typically this set might contain, for example, every point on a 80x24 terminal = 1920 points. I need a good hash function. I just came up with the following: struct PointHash : public std::unary_function<Point, std::size_t> { result_type operator()(const argument_type& val) const { return val.row.value() * 1000 + val.col.value(); } }; However, I'm not sure that this is really a good hash function. I wanted something fast, since I need to do many lookups very quickly. Is there a better hash function I can use, or is this OK?

    Read the article

  • How do I memoize expensive calculations on Django model objects?

    - by David Eyk
    I have several TextField columns on my UserProfile object which contain JSON objects. I've also defined a setter/getter property for each column which encapsulates the logic for serializing and deserializing the JSON into python datastructures. The nature of this data ensures that it will be accessed many times by view and template logic within a single Request. To save on deserialization costs, I would like to memoize the python datastructures on read, invalidating on direct write to the property or save signal from the model object. Where/How do I store the memo? I'm nervous about using instance variables, as I don't understand the magic behind how any particular UserProfile is instantiated by a query. Is __init__ safe to use, or do I need to check the existence of the memo attribute via hasattr() at each read? Here's an example of my current implementation: class UserProfile(Model): text_json = models.TextField(default=text_defaults) @property def text(self): if not hasattr(self, "text_memo"): self.text_memo = None self.text_memo = self.text_memo or simplejson.loads(self.text_json) return self.text_memo @text.setter def text(self, value=None): self.text_memo = None self.text_json = simplejson.dumps(value)

    Read the article

  • How to design data storage for partitioned tagging system?

    - by Morgan Cheng
    How to design data storage for huge tagging system (like digg or delicious)? There is already discussion about it, but it is about centralized database. Since the data is supposed to grow, we'll need to partition the data into multiple shards soon or later. So, the question turns to be: How to design data storage for partitioned tagging system? The tagging system basically has 3 tables: Item (item_id, item_content) Tag (tag_id, tag_title) TagMapping(map_id, tag_id, item_id) That works fine for finding all items for given tag and finding all tags for given item, if the table is stored in one database instance. If we need to partition the data into multiple database instances, it is not that easy. For table Item, we can partition its content with its key item_id. For table Tag, we can partition its content with its key tag_id. For example, we want to partition table Tag into K databases. We can simply choose number (tag_id % K) database to store given tag. But, how to partition table TagMapping? The TagMapping table represents the many-to-many relationship. I can only image to have duplication. That is, same content of TagMappping has two copies. One is partitioned with tag_id and the other is partitioned with item_id. In scenario to find tags for given item, we use partition with tag_id. If scenario to find items for given tag, we use partition with item_id. As a result, there is data redundancy. And, the application level should keep the consistency of all tables. It looks hard. Is there any better solution to solve this many-to-many partition problem?

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >