Search Results

Search found 1524 results on 61 pages for 'elegant'.

Page 39/61 | < Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >

  • Using different validation rules based on user input.

    - by chiefanov
    I have a simple form: a combobox and a textbox. My combobox has 2 values: A and B. When value A is selected I want textbox to use a validation rule. When value B is selected there should be no validation rules applied to the textbox. I've read an article that has a solution and I'm trying to use it, but had no luck so far, and I think there might be a more elegant solution. Has anyone done anything like this before? Any ideas are highly appreciated.

    Read the article

  • Correct approach to validate attributes of an instance of class

    - by systempuntoout
    Having a simple Python class like this: class Spam(object): __init__(self, description, value): self.description = description self.value = value Which is the correct approach to check these constraints: "description cannot be empty" "value must be greater than zero" Should i: 1.validate data before creating spam object ? 2.check data on __init__ method ? 3.create an is_valid method on Spam class and call it with spam.isValid() ? 4.create an is_valid static method on Spam class and call it with Spam.isValid(description, value) ? 5.check data on setters declaration ? 6.... Could you recommend a well designed\Pythonic\not verbose (on class with many attributes)\elegant approach?

    Read the article

  • Evenly distribute range of specified values within a vector

    - by nofunsally
    I have a vector A and I want to populate it with values as evenly as possible. For example, if A is 1x30 and I want to use three values I would use a code like this below: % A = zeros(1,30); A([1:10])=0; A([11:20])=1; A([21:30])=2; This works, but seems a bit cumbersome to me. Is there a more elegant way to evenly (as possible) distribute a specified range of values within a vector? I am intent on keeping each of the values in "clumps." Thank you kindly in advance.

    Read the article

  • Event(s) for opening the workbook AND worksheets

    - by KeyMs92
    I'm looking for an elegant solution to trigger an event for opening the workbook as well as opening different worksheets. I don't need seperate operations for each worksheet: they all trigger the same method. I know I can use the events Workbook_Activate / Workbook_Open and Workbook_SheetActivate at the same time but I don't know if this is 'the official way' to do it. Perhaps there's a way to do this with one event. I was also wondering if it is relevant in this matter where I put the code. I now have all the code inside "ThisWorkbook" and not in a "Module"...

    Read the article

  • Multiplying numbers on horizontal, vertial, and diagonal lines

    - by untwisted
    I'm currently working on a project Euler problem (www.projecteuler.net) for fun but have hit a stumbling block. One of the problem provides a 20x20 grid of numbers and asks for the greatest product of 4 numbers on a straight line. This line can be either horizontal, vertical, or diagonal. Using a procedural language I'd have no problem solving this, but part of my motivation for doing these problems in the first place is to gain more experience and learn more Haskell. As of right now I'm reading in the grid and converting it to a list of list of ints, eg -- [[Int]]. This makes the horizontal multiplication trivial, and by transposing this grid the vertical also becomes trivial. The diagonal is what is giving me trouble. I've thought of a few ways where I could use explicit array slicing or indexing, to get a solution, but it seems overly complicated and hackey. I believe there is probably an elegant, functional solution here, and I'd love to hear what others can come up with.

    Read the article

  • Assign RegEx submatches to variables or map (C++/C)

    - by Michael
    I need to extract the SAME type of information (e.g. First name, Last Name, Telephone, ...), from numerous different text sources (each with a different format & different order of the variables of interest). I want a function that does the extraction based on a regular expression and returns the result as DESCRIPTIVE variables. In other words, instead of returning each match result as submatch[0], submatch[1], submatch[2], ..., have it do EITHER of the following: 1.) return std::map so that the submatches can be accessed via: submatch["first_name"], submatch["last_name"], submatch["telephone"] 2.) return a variables with the submatches so that the submatches can be accessed via: submatch_first_name, submatch_last_name, submatch_telephone I can write a wrapper class around boost::regex to do #1, but I was hoping there would be a built-in or a more elegant way to do this in C++/Boost/STL/C.

    Read the article

  • changing body class based on user's local time

    - by John
    I'm trying to add a body class of 'day' if it's 6am-5pm and 'night' if "else" based on the user's local time. I tried the following but it didn't work. Any ideas? In the head: <script> function setTimesStyles() { var currentTime = new Date().getHours(); if(currentTime > 5 && currentTime < 17) { document.body.className = 'day'; } else { document.body.className = 'night'; } } </script> In the body: <body onload="setTimeStyles();"> Also, is there a more elegant way to achieve what I need?

    Read the article

  • A better way of representing File Attachment into a list(c#3.0)

    - by Newbie
    I have written List<Attachment> lstAttachment = new List<Attachment>(); //Check if any error file is present in which case it needs to be send if (new FileInfo(Path.Combine(errorFolder, errorFileName)).Exists) { Attachment unprocessedFile = new Attachment(Path.Combine(errorFolder, errorFileName)); lstAttachment.Add(unprocessedFile); } //Check if any processed file is present in which case it needs to be send if (new FileInfo(Path.Combine(outputFolder, outputFileName)).Exists) { Attachment processedFile = new Attachment(Path.Combine(outputFolder, outputFileName)); lstAttachment.Add(processedFile); } Working fine and is giving the expected output. Basically I am attaching the file to the list based on whether the file is present or not. I am looking for any other elegant solution than the one I have written. Reason: Want to learn differnt ways of representing the same program. I am using C#3.0 Thanks.

    Read the article

  • Creating a CD auto-start dialog

    - by emilyshaun
    For me, compact discs and these customized auto-start dialogs are somewhat outdated and waste... However, I have to create such a dialog as an index for a CD consisting of a few PDF files. Making one to work on Microsoft Windows is quite easy. As there might be users from different platforms (Unix, Apple,...), the question raises how to offer them such a (auto-starting) dialog as well. Java is of course an option, but I think it's overloaded and naturally too slow for this purpose. Now, I think of a single webpage that will appear in the local browser. Using all these web standards this could a very creative, light-weight approach working on most systems. Do you see any problems that might occur here? Probably, there is a different and more elegant solution to this issue?

    Read the article

  • how-to initialize 'const std::vector<T>' like a c array

    - by vscharf
    Is there an elegant way to create and initialize a const std::vector<const T> like const T a[] = { ... } to a fixed (and small) number of values? I need to call a function frequently which expects a vector<T>, but these values will never change in my case. In principle I thought of something like namespace { const std::vector<const T> v(??); } since v won't be used outside of this compilation unit.

    Read the article

  • Creating audit triggers in SQL Server

    - by Mike C.
    I need to implement change tracking on two tables in my SQL Server 2005 database. I need to audit additions, deletions, updates (with detail on what was updated). I was planning on using a trigger to do this, but after poking around on Google I found that it was incredibly easy to do this incorrectly, and I wanted to avoid that on the get-go. Can anybody post an example of an update trigger that accomplishes this successfully and in an elegant manner? I am hoping to end up with an audit table with the following structure: ID LogDate TableName TransactionType (update/insert/delete) RecordID FieldName OldValue NewValue ... but I am open for suggestions. Thanks!

    Read the article

  • Best way to handle different panels occupying same area

    - by gmnnn
    I have this application: I want to change the marked area when the user is clicked one of the navBarItems (like Microsoft OUTLOOK). I've been doing some research and a lot of people said that I can add several panels and show/hide them when user is clicked a navBarItem. But the area will contain a lot of gridviews and a lot of other controls. I don't know if I want to initialize all of them when application starts because it's gonna be hard on the cpu and memory to keep all the controls running at the same time. And I don't think it's an elegant solution for this kind of situation. But if I choose to initialize controls when user is clicked to corresponding navBarItem, it's gonna be laggy for the user. What is the best design approach for this situation? PS: I can use commercial libraries too. Thank you.

    Read the article

  • Where should I declare a list of 5,000+ words?

    - by user647362
    I am writing a game in python in which I must periodically pull a random word from a list of words. When I prototyped my game I declared a word_list = ['cat','dog','rat','house'] of ten words at the top of one of my modules. I then use choice(word_list) to get a random word. However, I must must change this temporary hack into something more elegant because I need to increase the size of the word list to 5,000+ words. If I do this in my current module it will look ridiculous. Should I put all of these words in a flat txt file, and then read from that file as I need words? If so, how would I best do that? Put each word an a separate line and then read one random line? I'm not sure what the most efficient way is.

    Read the article

  • MySQL pivot tables - covert rows to columns

    - by user2723490
    This is the structure of my table: Then I run a query SELECT `date`,`index_name`,`results` FROM `mst_ind` WHERE `index_name` IN ('MSCI EAFE Mid NR USD', 'Alerian MLP PR USD') AND `time_period`='M1' and get a table like How can I convert "index_name" rows to columns like: date | MSCI EAFE Mid NR USD | Alerian MLP PR USD etc In other words I need each column to represent an index and rows to represent date-result. I understand that MySQL doesn't have pivot table functions. What is the easiest way of doing this? I've tried this code, but it generates an error: SELECT `date`, MAX(IF(index_name = 'Alerian MLP PR USD' AND `time_period`='M1', results, NULL)) AS res1, MAX(IF(index_name = 'MSCI EAFE Mid NR USD' AND `time_period`='M1', results, NULL)) AS res2 FROM `mst_ind` GROUP BY `date I need to make the conversion on the query level - not PHP. Please suggest a nice and elegant solution. Thanks!

    Read the article

  • VSTO 3.0 Get/Change an excel 2007 workbook connection

    - by RQueiroga
    Hi all, I've struggling to find a way to get and change and excel 2007 workbook connection (Menu Data - Existing Connections - Connections on this Workbook).It's a connection (several actually) to a SQL Server and used in a pivot table. I've tried using Application.ActiveWorkbook.Connections or Globals.ThisWorkbook.Connections but they both return always Null..I've tried in an sheet event as well as in a custom ribbon's button event as well. The only way left I can think of is use to code a VBA method that does the work and then invoque it in my VSTO code, but it's not very elegant is it... Thanks in advanced :-)

    Read the article

  • Approach to Selecting top item matching a criteria

    - by jkelley
    I have a SQL problem that I've come up against routinely, and normally just solved w/ a nested query. I'm hoping someone can suggest a more elegant solution. It often happens that I need to select a result set for a user, conditioned upon it being the most recent, or the most sizeable or whatever. For example: Their complete list of pages created, but I only want the most recent name they applied to a page. It so happens that the database contains many entries for each page, and only the most recent one is desired. I've been using a nested select like: SELECT pg.customName, pg.id FROM ( select id, max(createdAt) as mostRecent from pages where userId = @UserId GROUP BY id ) as MostRecentPages JOIN pages pg ON pg.id = MostRecentPages.id AND pg.createdAt = MostRecentPages.mostRecent Is there a better syntax to perform this selection?

    Read the article

  • Clojure: find repetition

    - by demi
    Let we have a list of integers: 1, 2, 5, 13, 6, 5, 7 and I want to find the first number has a duplicate before it and return a vector of two indices, In my sample, it's 5 at [2, 5]. What I did so far is loop, but can I do it more elegant, short way? (defn get-cycle [xs] (loop [[x & xs_rest] xs, indices {}, i 0] (if (nil? x) [0 i] ; Sequence is over before we found a duplicate. (if-let [x_index (indices x)] [x_index i] (recur xs_rest (assoc indices x i) (inc i)))))) No need to return number itself, because I can get it by index and, second, it may be not always there.

    Read the article

  • Are instance initializers good or bad?

    - by berry120
    I personally quite like instance initializers - I use them to assign default values to things such as collections so when writing constructors I don't have to remember to assign them the same default values each time. It seems quite elegant to me - avoids annoying NPE's popping up and avoids duplicate code. A private method doesn't seem as nice because a) it can't assign values to final fields, b) it could be run elsewhere in code and c) the method still needs to be explicitly called at the start of each constructor. However, the flip side with others I have spoken to is that they're confusing, some people reading the code might not understand what they do or when they're called and thus they could cause more problems than they solve. Are proper use of these initializers something to be encouraged or avoided? Or is it an "each to their own" case?

    Read the article

  • How do I count list elements that are not hidden?

    - by Baloneysammitch
    Starting with a simple list: <ul> <li>Item 1</li> <li style="display: none;">Item 2</li> <li>Item 3</li> </ul> I know that I can subtract the hidden elements from the list total $('ul li').size() - $('ul li:hidden').size() But I thought there might be a more elegant way to achieve this with jquery: $('ul li:hidden:not').size() That doesn't work. Any ideas?

    Read the article

  • Rails: updating an item along with associated items

    - by shmichael
    Suppose I have a simple to-do list application. The application contains two models: lists (have an owner and description) items (have name and due-date) that belong to a specific list I would like to have a single edit screen for a list in which I update the list attributes (such as description) and also create/delete/modify associated items. There should be a single "save" button that will commit all changes. Unless save is pressed, any change to the list and the items should be forgotten. I wasn't able to find an elegant best practice for this. Would greatly appreciate any suggestions and/or references to existing implementations.

    Read the article

  • Select distinct ... inner join vs. select ... where id in (...)

    - by Tonio
    I'm trying to create a subset of a table (as a materialized view), defined as those records which have a matching record in another materialized view. For example, let's say I have a Users table with user_id and name columns, and a Log table, with entry_id, user_id, activity, and timestamp columns. First I create a materialized view of the Log table, selecting only those rows with timestamp some_date. Now I want a materliazed view of the Users referenced in my snapshot of the Log table. I can either create it as select * from Users where user_id in (select user_id from Log_mview), or I can do select distinct u.* from Users u inner join Log_mview l on u.user_id = l.user_id (need the distinct to avoid multiple hits from users with multiple log entries). The former seems cleaner and more elegant, but takes much longer. Am I missing something? Is there a better way to do this?

    Read the article

  • Object directing to a property when accessed as an iterable

    - by ThE_JacO
    I'm trying to figure out if there's an elegant and concise way to have a class accessing one of its own properties when "used" as a dictionary, basically redirecting all the methods that'd be implemented in an ordered dictionary to one of its properties. Currently I'm inheriting from IterableUserDict and explicitly setting its data to another property, and it seems to be working, but I know that UserDict is considered sort of old, and I'm concerned I might be overlooking something. What I have: class ConnectionInterface(IterableUserDict): def __init__(self, hostObject): self._hostObject= hostObject self.ports= odict.OrderedDict() self.inputPorts= odict.OrderedDict() self.outputPorts= odict.OrderedDict() self.data= self.ports This way I expect the object to behave and respond (and be used) the way I mean it to, except I want to get a freebie ordered dictionary behaviour on its property "ports" when it's iterated, items are gotten by key, something is looked up ala if this in myObject, and so on. Any advice welcome, the above seems to be working fine, but I have an odd itch that I might be missing something. Thanks in advance.

    Read the article

  • Trimming strings in Go

    - by user1263980
    I'm trying to read an entire line from the console (including whitespace), then process it. Using bufio.ReadString, the newline character is read together with the input, so I came up with the following code to trim the newline character: input,_:=src.ReadString('\n') inputFmt:=input[0:len(input)-2]+"" Is there a more idiomatic way to do this? That is, is there already a library that takes care of the ending null byte when extracting substrings for you? (Yes, I know there is already a way to read a line without the newline character in go readline -> string but I'm looking more for elegant string manipulation.)

    Read the article

  • Reorganized JSON

    - by couatl
    Need to be reorganized JSON into a new structure. Python. for example { 'a' : 1, 'b' : 1, 'd' : {'d1' : '1', 'd2' : 2}, 'm' : [ {'x' : 6, 'y' : 5, 'z' : {'foo' : 'foo1', 'bar : 'bar1'} }, {'x' : 8, 'y' : 8, 'z' : {'foo' : 'foo2', 'bar : 'bar2'} } ... ] } to { 'new_a' : 1, 'new_d' : {'new_d1' : '1', 'new_d2' : 2}, 'new_m' : [ {'new_x' : 6, 'new_z' : {'new_foo' : 'foo1', new_'bar : 'bar1'} }, {'new_x' : 8, 'new_z' : {'new_foo' : 'foo2', 'new_bar : 'bar2'} } ... ] } There is the idea of ??a new form of an old JSON Is there a more elegant way of that? import json new_data = {} new_data['new_a'] = old_data['a'] new_data['new_d'] = {} new_data['new_d']['new_d1'] = old_data['d']['d1'] new_data['new_d']['new_d2'] = old_data['d']['d2'] new_data['new_m'] = {} new_m = [] for m in old_data: new_m.append({'new_x' : m['x'], 'new_z' : {'new_foo' ....

    Read the article

  • Challenges in multi-player Android Game Server with RESTful Nature

    - by Kush
    I'm working on an Android Game based on Contract Bridge, as a part of my college Summer Internship project. The game will be multi-player such that 4 Android devices can play it, so there's no BOT or CPU player to be developed. At the time of getting project, I realized that most of the students had already worked on the project but none of their works is reusable now (for variety of reasons like, undocumented code and design architecture, different platform implementation). I have experience working on several open source projects and hence I emphasis to work out on this project such that components I make become reusable as much as possible. Now, as the game is multi-player and entire game progress will be handled on server, I'm currently working on Server's design, since I wanted to make game server reusable such that any client platform can use it, I was previously confused in selecting Socket or REST for Game Server's design, but later finalized to work on REST APIs for the server. Now, since I have to keep all players in-sync while they make movements in game, on server I've planned to use Database which will keep all players' progress, specific for each table (in Bridge, 4 players play on single table, and server will handle many such game tables). I don't know if its an appropriate decision to use database as shared medium to track progress of each game table (let me know if there's an appropriate or better option). Obviously, when game is completed for the table, data for that table on server's database is discarded. Now the problem is that, access to REST service is an HTTP call, so as long as client doesn't make any request, server will remain idle, and consider a situation where A player has played a card on his device and the device requests to apply this change on the server. Now, I need to let rest of the three devices know that the player has played a card, and also update view on their device. AFAIK, REST cannot provide a sort-of Push-notification system, since the connection to the server is not persistent. One solution that I thought was to make each device constantly poll the server for any change (like every 56 ms) and when changes are found, reflect it on the device. But I feel this is not an elegant way, as every HTTP request is expensive. (and I choose REST to make game play experience robust since, a mobile device tends to get disconnected from Internet, and if there's Socket-like persistent connection then entire game progress is subject to lost. Also, portability on client-end is important) Also, imagining a situation where 10 game tables are in progress and 40 players are playing, a server must be capable to handle flooded HTTP requests from all the devices which make it every 56 ms. So I wonder if the situation is assumed as DoS attack. So, explaining the situation, am I going on the right track for the server design? I wanted to be sure before I proceed much further with the code.

    Read the article

< Previous Page | 35 36 37 38 39 40 41 42 43 44 45 46  | Next Page >