Search Results

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

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

  • How do check if PDO object is connected properly inside a different class?

    - by tgun926
    I want to fetch some information from my mysql database in a class, so I'm passing in the PDO object into a __construct function, and working from there. However, what's an elegant way of checking to see if the PDO object was correctly created, and that the connection is open when the Table class is instantiated? class Table{ public function __construct(PDO $db, $week){ try{ $query = $db -> query ("SELECT * FROM `table1` where `day` = 'monday'"); } catch(PDOExeption $e){ echo 'error: '. $e->getMessage(); //die(); } } } I don't think this code does what I want.

    Read the article

  • How to check whether a String fully matches a Regex in Scala?

    - by mkneissl
    Assume I have a Regex pattern I want to match many Strings to. val Digit = """\d""".r I just want to check whether a given String fully matches the Regex. What is a good and idiomatic way to do this in Scala? I know that I can pattern match on Regexes, but this is syntactically not very pleasing in this case, because I have no groups to extract: scala> "5" match { case Digit() => true case _ => false } res4: Boolean = true Or I could fall back to the underlying Java pattern: scala> Digit.pattern.matcher("5").matches res6: Boolean = true which is not elegant, either. Is there a better solution?

    Read the article

  • Best way in Python to determine all possible intersections in a matrix?

    - by ssweens
    So if I have a matrix (list of lists) of unique words as my column headings, document ids as my row headings, and a 0 or 1 as the values if the word exists in that particular document. What I'd like to know is how to determine all the possible combinations of words and documents where more than one word is in common with more than one document. So something like: [[Docid_3, Docid_5], ['word1', 'word17', 'word23']], [[Docid_3, Docid_9, Docid_334], ['word2', 'word7', 'word23', 'word68', 'word982']], and so on for each possible combination. Would love a solution that provides the complete set of combinations and one that yields only the combinations that are not a subset of another, so from the example, not [[Docid_3, Docid_5], ['word1', 'word17']] since it's a complete subset of the first example. I feel like there is an elegant solution that just isn't coming to mind and the beer isn't helping. Thanks.

    Read the article

  • Best way to make an attribute always an array?

    - by Shadowfirebird
    I'm using my MOO project to teach myself Test Driven Design, and it's taking me interesting places. For example, I wrote a test that said an attribute on a particular object should always return an array, so -- t = Thing.new("test") p t.names #-> ["test"] t.names = nil p t.names #-> [] The code I have for this is okay, but it doesn't seem terribly ruby to me: class Thing def initialize(names) self.names = names end def names=(n) n = [] if n.nil? n = [n] unless n.instance_of?(Array) @names = n end attr_reader :names end Is there a more elegant, Ruby-ish way of doing this? (NB: if anyone wants to tell me why this is a dumb test to write, that would be interesting too...)

    Read the article

  • Copy one column over another in a delimited file

    - by user275455
    For instance, I needed to remove column 25 and replace it with a copy of column 22 in a simple csv file with no embedded delimiters. The best I could come up with was the awkward looking: awk -F, '{ for(x=1;x<25;x++){printf("%s,", $x)};printf("%s,",$22);for(x=26;x<59;x++){printf ("%s,", $x)};print $59}' I would expect something like cut -d, -f1-24,23,26-59 to work but cut doesn't seem to want to print the same column two times... Is there a more elegant way to do it using anything typicaly available in a linux shell environment?

    Read the article

  • How to read arbitrary number of values using std::copy?

    - by Miro Kropacek
    Hi, I'm trying to code opposite action to this: std::ostream outs; // properly initialized of course std::set<int> my_set; // ditto outs << my_set.size(); std::copy( my_set.begin(), my_set.end(), std::ostream_iterator<int>( outs ) ); it should be something like this: std::istream ins; std::set<int>::size_type size; ins >> size; std::copy( std::istream_iterator<int>( ins ), std::istream_iterator<int>( ins ) ???, std::inserter( my_set, my_set.end() ) ); But I'm stuck with the 'end' iterator -- input interators can't use std::advance and neither I can use two streams with the same source... Is there any elegant way how to solve this? Of course I can use for loop, but maybe there's something nicer :)

    Read the article

  • Help doing a dynamic sort?

    - by Kevin
    I have a notifications table which contains different types of notifications for different events. Inside the table is a notifications_type:string column that contains the type of notification, i.e. "foo" or "bar" or "oof" I want the user to be able to select what notifications they want to display, so there are checkboxes below the result that correspond to prefs_display_foo:boolean, prefs_display_bar:boolean in the User model. What is an elegant way for me to set the :conditions in the find to properly display the sorted results? Also, currently I have it as a method in the user, but how would I do it as a has_many :notifications, :conditions = .....

    Read the article

  • Creating a Drop-Down Menu with Javascript

    - by iceteea
    Question about logics here: What's the most elegant way to make the menu appear/disappear onmouseover/onmouseout? See the following JsBin: http://jsbin.com/owayeb/edit#source The Menu is hidden by default. If the user moves his cursor above the Link the showme() function gets called. When the user moves his cursor away the hideme() functions gets called. How would I get the Menu to persist while the user moves his mouse away from the Link to above the Menu? Or is this all the wrong school of thought?

    Read the article

  • Can I stop SQL*Plus from displaying "connected" when I have a "connect" in a script?

    - by René Nyffenegger
    I have a few sql scripts that I need to run via SQL*Plus. These scripts connect several times as different users with a connect user_01/pass_01@db_01. Now, each time the script does such a connect, it confirms the successful connection with a connected. This is distracting and I want to turn it off. I can achieve what I want with a set termout off connect user_01/pass_01@db_01 set termout on Is there a more elegant solution to my problem? Note, it doesn't help to permanently set termout off at the start of the script since I need to know if a command didn't run successfully.

    Read the article

  • Best way to utilise an include file which just includes an array in PHP

    - by alex
    Kohana's config files look like this.. here is an example of a database config file (simplified) return array( 'dbhost' => 'localhost', 'user' => 'Tom_Jones' ); I've also got a CMS which wants the connection details. Whilst the CMS uses a different user (with more rights), I'd like to know the best way to include this file and get the data out of it (so as to not repeat myself for hostname and dbname). I haven't thought up of any elegant solutions yet and have not yet dug around Kohana to see how it does it. It's late Friday here so it's probably really obvious to everyone except me. UPDATE My apologies, I forgot to include that this is using Kohana 3!

    Read the article

  • Class.getArrayType in Java?

    - by ???
    I use the following trick to get the array type of a specific class: @SuppressWarnings("unchecked") public static <T> Class<T[]> getArrayType(Class<T> componentType) { String arrayClassName = "[L" + componentType.getName() + ";"; try { return (Class<T[]>) Class.forName(arrayClassName); } catch (ClassNotFoundException e) { throw new UnexpectedException("Can't get the array type for " + componentType, e); } } But, is there any more elegant way to get this?

    Read the article

  • Detecting inconsistent revisions of shared sources in SVN

    - by maxim1000
    I have an SVN repository containing several components: LibraryA LibraryB - depends on LibraryA Application - depends on LibraryB and LibraryA More detailed structure (branches and tags are not related to the problem): LibraryA LibraryA_code LibraryB LibraryB_code svn:externals to a fixed revision R1 of LibraryA_code Application Application_code svn:externals to a fixed revision R2 of LibraryA_code svn:externals to a fixed revision R3 of LibraryB_code The problem I'm trying to solve is automatic detection of situation when R2 differs from R1 (breaking expectations of LibraryB_code) and notification about this (e.g. build failure). I'll describe in an answer the only solution which I see for now, but I hope for something more elegant :) Environment: Windows, Visual Studio, SVN.

    Read the article

  • Method to register method to be called when event is raised

    - by zaidwaqi
    I have a Panel which contains 20 PictureBox controls. If a user clicks on any of the controls, I want a method within the Panel to be called. How do I do this? public class MyPanel : Panel { public MyPanel() { for(int i = 0; i < 20; i++) { Controls.Add(new PictureBox()); } } // DOESN'T WORK. // function to register functions to be called if the pictureboxes are clicked. public void RegisterFunction( <function pointer> func ) { foreach ( Control c in Controls ) { c.Click += new EventHandler( func ); } } } How do I implement RegisterFunction()? Also, if there are cool C# features that can make the code more elegant, please share.

    Read the article

  • attaching multiple files to a domain class

    - by Emyr
    I've seen various Grails plugins which allow easier handling of file uploads, however these tend only to support a single file per form-submit. I'd like a multi-attach form where as soon as you pick one file, an extra field and button is added using JS (various sites do it like this). Do you know of any good plugins which provide elegant uploading of multiple files without excessive coding? A progress bar either per-file of for the whole process would also be very nice. I don't know to what extent I can allow GORM to handle a java.io.File field (or in this case a Collection<File>).

    Read the article

  • Ensuring uniqueness on a varchar greater than 255 in MYSQL/InnoDB

    - by Vijay Boyapati
    I have a table which contains HTML entries for news pages. When I initially designed it I used URL as the primary key. I've learned the error of my ways because left-joining is super slow. So I want to redesign the table with an integer (id) primary key, but still keep the rows unique based on the URL. The problem is that I've found URLs longer than 255 characters, and MySQL isn't letting my create a key on the URL. I'm using an InnoDB/UTF8 table. From what I understand it's using multiple bytes per character with a limit of 766 bytes for the key (in InnoDB). I would really love suggestions on an elegant way of keeping the rows unique based on URL, while using an integer primary key. Thanks!

    Read the article

  • Generating incremental numeric column values during INSERT SELECT statement

    - by Charles
    I need to copy some data from one table to another in Oracle, while generating incremental values for a numeric column in the new table. This is a once-only exercise with a trivial number of rows (100). I have an adequate solution to this problem but I'm curious to know if there is a more elegant way. I'm doing it with a temporary sequence, like so: CREATE SEQUENCE temp_seq START WITH 1; INSERT INTO new_table (new_col, copied_col1, copied_col2) SELECT temp_seq.NEXTVAL, o.* FROM (SELECT old_col1, old_col2 FROM old_table) o; DROP SEQUENCE temp_seq; Is there way to do with without creating the sequence or any other temporary object? Specifically, can this be done with a self-contained INSERT SELECT statement? There are similar questions, but I believe the specifics of my question are original to SO.

    Read the article

  • Communication between c++ objects.

    - by Pradyot
    This is an issue, that I have come acrosss earlier. Basically a c++ object has a member object that does some work, once the work is done , a notification needs to made to the parent. What is the most elegant solution to allow this communication. Does being in this position indicate a flaw with the design to begin with? To elaborate. class A { B member; void do_something(); } class B{ void talk_to_network(); }; void do_something() { //Conditional wait on a variable that will change when talk to network completes. //So need a way for B to inform A, that it is done. }

    Read the article

  • More compact way to do this?

    - by Macha
    I have a couple of functions that loop around the surrounding cells of a cell. The grid is contained inside an array. In my code, I have checks to make sure it's not one of the edge cells, as checking an undefined cell causes an error. As such, I have code like this: if(x > 0) { var firstX = x - 1; } else { var firstX = x; } if(x < 199) { var lastX = x + 1; } else { var lastX = x; } if(y > 0) { var firstY = y - 1; } else { var firstY = y; } if(y < 199) { var lastY = y + 1; } else { var lastY = y; } A lot of lines of code to do very little. Is there a more elegant way to do this?

    Read the article

  • How do I do pivoting in this query in SQL?

    - by dewacorp.alliances
    Hi there I have this table like this: Name; Amount1, Amount, Rate1, Rate2 Test; 1000; 2000; 1.0; 2.0 I want to display into: Parameter; Amount1; Rate1; Total 'Parameter 1'; 1000; 1.0; 1000 'Parameter 2'; 2000; 2.0; 4000 BTW ... I am using SQL2K5. All I can think of is CURSOR. Any other solution in elegant way? Thanks

    Read the article

  • Splitting Nucleotide Sequences in JS with Regexp

    - by TEmerson
    I'm trying to split up a nucleotide sequence into amino acid strings using a regular expression. I have to start a new string at each occurrence of the string "ATG", but I don't want to actually stop the first match at the "ATG". Valid input is any ordering of a string of As, Cs, Gs, and Ts. For example, given the input string: ATGAACATAGGACATGAGGAGTCA I should get two strings: ATGAACATAGGACATGAGGAGTCA (the whole thing) and ATGAGGAGTCA (the first match of "ATG" onward). A string that contains "ATG" n times should result in n results. I thought the expression /(?:[ACGT]*)(ATG)[ACGT]*/g would work, but it doesn't. If this can't be done with a regexp it's easy enough to just write out the code for, but I always prefer an elegant solution if one is available.

    Read the article

  • Hiding What Site You're On (Branding Issues)

    - by John
    Here's the scenario: I have a private site that, once logged on, will display different information depending on the attributes of your account: the pages are branded differently based upon what company you are associated with. The problem is the companies linking to this site want everything to be displayed as their own brand, and do not want to see my brand anywhere, especially in the URL (i.e. from www.theirbrand.com they do not want to have links to www.mybrand.com). Is there an elegant solution to this? Is the best option to add a page on www.theirbrand.com that contains an iframe with a source of www.mybrand.com (I'm not sure if that would interfere with back/forward navigation, etc), or is there a better way?

    Read the article

  • How to do something after effect animation ends in Flex?

    - by Chobicus
    I'm a beginner in Flex so there must be more elegant way of doing this. //move effect private var m:Move = new Move(); //this function creates labels with some text and starts move effect on them public function moveText(i:int):void { var myLabel:Label = new Label(); myLabel.text = "some text"; m.target = myLabel; ... m.play(); } Method moveText is called in a loop so I guess that labels don't get "garbage collected". What I want to do is to remove Labels created in moveText method after play animation ends. Another way of doing this is maybe creating some kind of "pool" of labels which I would use to move arround text. I don't know how would I return labels in to "pool". The question is how to do something after effect animation ends?

    Read the article

  • [Bash] Save part of matching pattern to variable

    - by Ben
    I want to extract a substring matching a pattern and save it to a file. An example string: Apr 12 19:24:17 PC_NMG kernel: sd 11:0:0:0: [sdf] Attached SCSI removable disk I want to extract the part between the brackets, in this case []. I tried to do something like grep -e '[$subtext]' to save the text in the brackets to a variable. Of course it doesn't work, but I am looking for a way similar to this. It would be very elegant to include a variable in a regex like this. What can I do best? Thanks!

    Read the article

  • Getting Reference to Calling Activity from AsyncTask (NOT as an inner class)

    - by stormin986
    Is it at all possible, from within an AsyncTask that is NOT an inner class of the calling Activity class, to get a reference to the instance of Activity that initiated execution of the AsyncTask? I am aware of this thread, however it doesn't exactly address how to reference the calling Activity. Some suggest passing a reference to the Activity as a parameter to the AsyncTask constructor, however, it's reported that doing so will always result in a NullPointerException. So, I'm at a loss. My AsyncTask provides robust functionality, and I don't want to have to duplicate it as an inner class in every Activity that wants to use it. There must be an elegant solution.

    Read the article

  • PivotControl item changing behavior in Silverlight Windows Phone 7

    - by Rosarch
    I have an app where the user is sent to a page with a PivotControl. The SelectedIndex is not known until the user navigates to the page. I'm setting the SelectedIndex, but it causes the PivotControl to start on index 0, then flip through to the index I set. This is kind of annoying, and I'd rather just have it go directly to the index I set. Is there some way around this? One hack I thought up was providing the data to pivotControl.ItemsSource in an order such that the item I want the user to start on is index 0 in ItemsSource. But that would be kind of messy, and I'm wondering if there's a more elegant solution.

    Read the article

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