Search Results

Search found 3440 results on 138 pages for 'returning'.

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

  • Generic extension method returning IEnumerable<T> without using reflection

    - by roosteronacid
    Consider this snippet of code: public static class MatchCollectionExtensions { public static IEnumerable<T> AsEnumerable<T>(this MatchCollection mc) { return new T[mc.Count]; } } And this class: public class Ingredient { public String Name { get; set; } } Is there any way to magically transform a MatchCollection object to a collection of Ingredient? The use-case would look something like this: var matches = new Regex("([a-z])+,?").Matches("tomato,potato,carrot"); var ingredients = matches.AsEnumerable<Ingredient>();

    Read the article

  • Returning values from Swing using invokeAndWait

    - by Joonas Pulakka
    I've been using the following approach to create components and return values from Swing to/from outside the EDT. For instance, the following method could be an extension to JFrame, to create a JPanel and add it to the parent JFrame: public JPanel threadSafeAddPanel() { final JPanel[] jPanel = new JPanel[1]; try { EventQueue.invokeAndWait(new Runnable() { public void run() { jPanel[0] = new JPanel(); add(jPanel[0]); } }); } catch (InterruptedException ex) { } catch (InvocationTargetException ex) { } return jPanel[0]; } The local 1-length array is used to transfer the "result" from inside the Runnable, which is invoked in the EDT. Well, it looks "a bit" hacky, and so my questions: Does this make sense? Is anybody else doing something like this? Is the 1-length array a good way of transferring the result? Is there an easier way to do this?

    Read the article

  • jQuery Plugin with $.getJSON Returning undefined?

    - by Oscar Godson
    Inside of a jQuery plugin I made I have: $.getJSON(base_url,{ agenda_id:defaults.id, action:defaults.action+defaults.type, output:defaults.output },function(json){ return json; }); And in a separate JS file (yes, it comes after the plugin): json = $('#agenda-live-preview').agenda({action:'get',type:'agenda',output:'json'}); alert(json[0].agenda_id); If i do the above $.getJSON and put an alert inside of the $.getJSON it works and returns "3", which is correct. If I do it like the json=$('#agenda-live-preview').agenda(...)... it returns undefined. My JSON is valid, and the json[0].agenda_id is correct also, I know it's in a callback, so how do I get the stuff inside of a callback in a function return?

    Read the article

  • Left Join not returning all rows

    - by DisgruntledGoat
    I have this query in MySQL: SELECT pr.*, pr7.value AS `room_price_high` FROM `jos_hp_properties` pr LEFT OUTER JOIN `jos_hp_properties2` pr7 ON pr7.property=pr.id WHERE pr7.field=23 The jos_hp_properties table has 27 rows but the query only returns one. Based on this question I think it may be because of the WHERE clause. The jos_hp_properties2 table has fields id, property, field, value, where field is a foreign key to a third table (which I don't need to get data from). Is there a way to select all the rows from the first table, including the value from table #2 where the field is 23 (or NULL if there is no field 23)?

    Read the article

  • Returning S_FALSE from a C# COM dll

    - by AntonyW
    I have a method defined in IDL as follows : interface IMyFunc : IDispatch { [id(1), helpstring("method GetNextFunction")] HRESULT GetNextFunction([in,out] long* lPos, [out, retval] BSTR* bstrName); } Using C++ I always implemented this as follows : STDMETHODIMP CMyFunc::GetNextFunction(long *nID, long *lPos, BSTR *bstrName) { if ( function to return ) { // setup return values; return S_OK; } else { // just exit return S_FALSE; } } Now I am implementing this in C# and have used tlbimp on the type library and ended up with : public string GetNextFunction(ref int nID, ref int lPos) I understand that this is because [out, retval] is used as the return type instead of the HRESULT as in C++. Is there a simple way to return the S_OK / S_FALSE values without changing the method definition? The only way I can see is that I have to use ildasm / ilasm to add preservesig so I end up with something like this : public int GetNextFunction(ref int nID, ref int lPos, ref string bstrName) I was wondering if there was some other way without doing the il compilation step.

    Read the article

  • Returning more than one result

    - by Hairr
    I'm using the following code: def recentchanges(bot=False,rclimit=20): """ @description: Gets the last 20 pages edited on the recent changes and who the user who edited it """ recent_changes_data = { 'action':'query', 'list':'recentchanges', 'rcprop':'user|title', 'rclimit':rclimit, 'format':'json' } if bot is False: recent_changes_data['rcshow'] = '!bot' else: pass data = urllib.urlencode(recent_changes_data) response = opener.open('http://runescape.wikia.com/api.php',data) content = json.load(response) pages = tuple(content['query']['recentchanges']) for title in pages: return title['title'] When I do recentchanges() I only get one result. If I print it though, all the pages are printed. Am I just misunderstanding or is this something relating to python? Also, opener is: cj = CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

    Read the article

  • Returning XML natively in a .NET (C#) webservice?

    - by James McMahon
    I realize that SOAP webservices in .NET return XML representation of whatever object the web method returns, but if I want to return data formatting in XML what is the best object to store it in? I am using the answer to this question to write my XML, here is the code: XmlWriter writer = XmlWriter.Create(pathToOutput); writer.WriteStartDocument(); writer.WriteStartElement("People"); writer.WriteStartElement("Person"); writer.WriteAttributeString("Name", "Nick"); writer.WriteEndElement(); writer.WriteStartElement("Person"); writer.WriteStartAttribute("Name"); writer.WriteValue("Nick"); writer.WriteEndAttribute(); writer.WriteEndElement(); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); Now I can return this output as a String to my calling webmethod, but it shows up as <string> XML HERE </string>, is there anyway to just return the full xml? Please in your answer, give an example of how to use said object with either XmlWriter or another internal object (if you consider XmlWriter to be a poor choice). The System.Xml package (namespace) has many objects, but I haven't been able to uncover decent documentation on how to use the objects together, or what to use for what situations.

    Read the article

  • Returning from method inside a @synchronized block

    - by Michael Waterfall
    I'd just like to know if it's advised to return from a method within a @synchronized block? For example: - (id)test { @synchronized(self) { if (a) return @"A"; else return @"B"; } } As opposed to: - (id)test { NSString *value; @synchronized(self) { if (a) value = @"A"; else value = @"B"; } return value; } This sample is rather simplistic, but sometimes in a complex method it would make things simpler to be able to return from within a @synchronized block.

    Read the article

  • view is not rendered when returning ModelAndView

    - by adancu
    Hi, I have the following problem. I need to export a PDF in a controller The code below, where I return a View, works as expected. @RequestMapping(method = RequestMethod.GET) public View exportReport( @RequestParam(value = "userName", required = true) String userName, @RequestParam(value = "startDate", required = true) Date startDate, @RequestParam(value = "endDate", required = true) Date endDate) { /////////////////////////////////////////// return new TimeSheetReportPdfView(); } The problem occurs if I change the method to return a ModelAndView: @RequestMapping(method = RequestMethod.GET) public ModelAndView exportReport( @RequestParam(value = "userName", required = true) String userName, @RequestParam(value = "startDate", required = true) Date startDate, @RequestParam(value = "endDate", required = true) Date endDate) { /////////////////////////////////////////// return new ModelAndView(new TimeSheetReportPdfView(), model); } Now, the PDF is not exported, all I get is a blank page and nothing in the logs. Any help appreciated. Thanks.

    Read the article

  • Javascript "Match" Function Not Returning Proper Results in Safari or IE (but yes in FF)

    - by Jascha
    Forgive me as this is a time sensitive issue and I will have to switch the site back in a few hours so the link will be bad... but: I am simply comparing two strings looking for a match with this function... I have an array of objects called linkArray and I need to match the .src of each object to a .src I send it (the src of the clicked image). if the the src of the image I clicked matches the src of an object in my array, I set a variable to the link string of that object and return true, letting my page know that the link is available. Now, this works great in FF. But not in any other browser and I can't figure out for the life of me why. I have set up a dialogue box to literally compare, by eye, the two strings that should at the very least throw the message "match". Can anyone see what I am missing here??? here is the link... http://7thart.com/Jewish-History-and-Culture/Jews-and-Baseball-An-American-Love-Story If you click any of the thumbnails on the left, you will activate the function. Again, I apologize as after a few hours I have to switch back to the original site and this link will be invalid. Thanks in advance for your help. (function below)... function matchLink(a){ for(var i=0;i<linkArray.length;i++){ var fixLink = '../' + linkArray[i]['src']; alert(fixLink + '\n = \n' + a); if(fixLink == a){ alert('match'); newLink = linkArray[i]['link']; return true; } } return false; } Note: The "match" will return on two of the images.. the initial image, and the first thumbnail on the left. The second thumbnail SHOULD match, and the third one SHOULD NOT match.

    Read the article

  • constructing a recursive function returning an array

    - by Admiral Kunkka
    I'm developing a function that has a random chance to loop through itself and put it's results in one array for me to use later in my PHP class. Is there a better way to do this more organized, specifically case 5. The array becomes sloppy if it rolls 5, after 5, after 5 looking unpleasant. private function dice($sides) { return mt_rand(1, $sides); } private function randomLoot($dice) { switch($dice) { case 1: $array[] = "A fancy mug."; break; case 2: $array[] = "A buckler."; break; case 3: $array[] = "A sword."; break; case 4: $array[] = "A jewel."; break; case 5: $array[] = "A treasure chest with contents:"; $count = $this->dice(3); $i = 1; while($i <= $count) { $array[] = $this->randomLoot($this->dice(5)); $i++; } break; } return $array; }

    Read the article

  • XPathNavigator.Evaluate returning incorrect value?

    - by Eric
    I'm expecting this code to return true but it doesn't ? What am I missing here. string xml = @"<data><e id=""NUM_CPUS"">1</e><e id=""ACE_PRESENT"">1</e></data>"; XPathDocument doc = new XPathDocument(new StringReader(xml)); string expr = "(id('NUM_CPUS'))>=1 and (id('ACE_PRESENT'))=1"; XPathNavigator nav = doc.CreateNavigator(); XPathExpression query = nav.Compile(expr); object result = nav.Evaluate(query); bool b = bool.Parse(result.ToString()); if (!b) throw new Exception("Should be true");

    Read the article

  • Returning an integer from a select box - JavaScript

    - by Ross
    Very simply, I want to be able to access the year from the select box as an integer. In my test, my alertbox is telling me the value is undefined. <form name="form1" method="post" action=""> <label>birth year <select name="birth year" id="dueYear"> <OPTION VALUE='' SELECTED>--Year--</OPTION> <OPTION VALUE='2011'>2011</OPTION> <OPTION VALUE='2010'>2010</OPTION> <OPTION VALUE='2009'>2009</OPTION></SELECT> </select> </label> </form> <script type="text/javascript"> var dueDateYear = parseInt(document.getElementById("dueYear")); </script> <button onclick="alert(dueDateYear)">Click Me!</button> All I want it to do, is tell me the year I have selected -- any help would be appreciated, I am a newbie :(

    Read the article

  • Haskell maps returning a monad

    - by sabauma
    The lookup function in Data.Map and Data.IntMap currently return values wrapped in Maybe with the type signature lookup :: Ord k => k -> Map k a -> Maybe a It used to have the more general type of lookup :: (Monad m, Ord k) => k -> Map k a -> m a I realize the former likely reduces the need of extra type specification, but the latter would make it much more general and allow lookup to be used in list comprehensions. Is there any way to mimic this behavior with the newer version, or would I have to use an older version of the library?

    Read the article

  • PHP is not returning me a number type

    - by Tristan
    Hello, i tryed to follow that great tutorial (STAR rating with css : http://stackoverflow.com/questions/1987524/turn-a-number-into-star-rating-display-using-jquery-and-css) but i've just a big problem : When i do <span class="stars">1.75</span> or $foo='1.75'; echo '<span class="stars">'.$foo.'</span> the stars is correctly shown, but as soon as i do : while($val = mysql_fetch_array($result)) { $average = ($val['services'] + $val['serviceCli'] + $val['interface'] + $val['qualite'] + $val['rapport'] ) / 5 ; <span class="stars">.$average.</span> } the stars stops working i double checked the data type in mysql : they're all TINYINT(2) and i tryed that : $average = intval($average); but it's still not working, Thank you

    Read the article

  • google maps call within a For Loop not returning distance

    - by Richard Reddy
    Hi, I am calling google maps within a for loop in my javascript as I have mulitple routes that need to be costed separately based on distances. Everything works great except that the distance is only returned for one of the routes. I have a feeling that it is something to do with the way I have the items declared within the ajax call for the maps. Any ideas what could be the issue from the code below? for (var i = 1; i <= numJourneys; i++) { var mapContainer = 'directionsMap' + i; var directionContainer = $('#getDistance' + i); $.ajax({ async: false, type: "POST", url: "Journey/LoadWayPoints", data: "{'args': '" + i + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { if (msg.d != '[]') { var map = new GMap2(document.getElementById(mapContainer)); var distance = directionContainer; var wp = new Array(); //routes var counter = 0; $.each(content, function () { wp[counter] = new GLatLng(this['Lat'], this['Long']); counter = counter + 1; }); map.clearOverlays(); map.setCenter(wp[0], 14); // load directions directions = new GDirections(map); GEvent.addListener(directions, "load", function () { alert(directions.getDistance()); //directionContainer.html(directions.getDistance().html); }); directions.loadFromWaypoints(wp, { getSteps: true }); } } }); }

    Read the article

  • PHP5 getrusage() returning incorrect information?

    - by Andrew
    I'm trying to determine CPU usage of my PHP scripts. I just found this article which details how to find system and user CPU usage time (Section 4). However, when I tried out the examples, I received completely different results. The first example: sleep(3); $data = getrusage(); echo "User time: ". ($data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000); echo "System time: ". ($data['ru_stime.tv_sec'] + $data['ru_stime.tv_usec'] / 1000000); Results in: User time: 29.53 System time: 2.71 Example 2: for($i=0;$i<10000000;$i++) { } // Same echo statements Results: User time: 16.69 System time: 2.1 Example 3: $start = microtime(true); while(microtime(true) - $start < 3) { } // Same echo statements Results: User time: 34.94 System time: 3.14 Obviously, none of the information is correct except maybe the system time in the third example. So what am I doing wrong? I'd really like to be able to use this information, but it needs to be reliable. I'm using Ubuntu Server 8.04 LTS (32-bit) and this is the output of php -v: PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2 (cli) (built: Jan 6 2010 22:01:14) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    Read the article

  • Jquery Returning values to original

    - by Cam
    So my script works perfectly, but here is the issue, I have buttons (Sprite action here) that are 40px height, but the top 20 only shows perfectly. When you click the button ie img the bottom 20px show perfecto! but... Issue, i included in my script a way to return all others to there default (only one should be selected) now, how can I fix this issue that I seem unable to correct as I can select multiple of them ** USERS can switch ** The last part of the script that is the issue. Thanks $(document).ready(function() { $('.form_sub').hide(); $('.theader').addClass('active'); $('.theader_t').click(function() { $('.form_header').show(); $('.form_sub').hide(); $('.theader').addClass('active'); $('.sub_theader').removeClass('active'); }); $('.sub_theader_t').click(function() { $('.form_header').hide(); $('.form_sub').show(); $('.theader').removeClass('active'); $('.sub_theader').addClass('active'); }); $('.top_head_img').click(function() { $(this).css({ position: 'relative', bottom: '20px' }).siblings().css( 'bottom', '0' ); }); }); <ul class="top_head"> <li> <a href="javascript:void(0)" onClick="selectPic5('top');"><img src="custom/images/top2.jpg" alt="Left" border="0" class="top_head_img"/></a> </li> <li> <a href="javascript:void(0)" onClick="selectPic5('center');"><img src="custom/images/mid2.jpg" alt="Center" border="0" class="top_head_img"/></a> </li> <li> <a href="javascript:void(0)" onClick="selectPic5('bottom');"><img src="custom/images/bot2.jpg" alt="Right" border="0" class="top_head_img"/></a> </li> </ul>

    Read the article

  • Some facebook friends' birthdays returning as null but I have the correct API permissions

    - by Andrei Radulescu
    I'm tring to get my friends' birthdays in my app and some of them are null. I thought that those people don't have a birthday set, but they actually do. My fql query is: SELECT uid,name,birthday_date FROM user WHERE uid IN (SELECT uid2 from friend where uid1=me()) My app has the "friends_birthday" permission set. I also tried with "birthday" instead of "birthday_date". Same result. I imagine that this happens because they opted out somehow, but I don't know how. Is there an alternate solution to actually get their birthdays from facebook? Thanks!

    Read the article

  • Returning user data for forms that have errors in when using ModelForms

    - by Sevenearths
    forms.py from django.forms import ModelForm from client.models import ClientDetails, ClientAddress, ClientPhone from snippets.UKPhoneNumberForm import UKPhoneNumberField class ClientDetailsForm(ModelForm): class Meta: model = ClientDetails class ClientAddressForm(ModelForm): class Meta: model = ClientAddress class ClientPhoneForm(ModelForm): number = UKPhoneNumberField() class Meta: model = ClientPhone views.py from django.shortcuts import render_to_response, redirect from django.template import RequestContext from client.forms import ClientDetailsForm, ClientAddressForm, ClientPhoneForm def new_client_view(request): formDetails = ClientDetailsForm(initial={'marital_status':'u'}) formAddress = ClientAddressForm() formHomePhone = ClientPhoneForm(initial={'phone_type':'home'}) formWorkPhone = ClientPhoneForm(initial={'phone_type':'work'}) formMobilePhone = ClientPhoneForm(initial={'phone_type':'mobi'}) return render_to_response('client/new_client.html', {'formDetails': formDetails, 'formAddress': formAddress, 'formHomePhone': formHomePhone, 'formWorkPhone': formWorkPhone, 'formMobilePhone': formMobilePhone}, context_instance=RequestContext(request)) (the new_client.html is nothing special) How should I write views.py so that if the user's data raises an error, instead of showing them the form again with the errors in but none of their original data, it shows them the form again with the errors AND their original data?

    Read the article

  • imagecopyresampled to resize and crop an image - not returning the expected result

    - by David
    imagecopyresized ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) This is what I want to do: I have an image that's 600x1000px in size, and I want to create a thumb that's 100x100px after resizing that image to 300x500px, the x coordinate for the top left point of the thumb square should be at 100(src x) and 120(src y). According to what I understand from the manual, the command should be $dst_image = imagecreatetruecolor(100,100); $src_image = imagecreatefromjpeg('/home/sandbox/imagetoresize.jpg'); imagecopyresized ($dst_image, $src_image, 0, 0, 100, 120, **300 , 500 , 600 , 1000** ) It is cropping the image just fine, but it isn't resizing it correctly. I never got it to match what I see in my image editor (the GIMP). What am I doing wrong? I confirmed that all the numbers are correct, but it's always shifted up or down no matter what I do. Your help would really be appreciated!

    Read the article

  • Returning superclass of return type from remote EJB method

    - by fish
    Let's say I have remote interface A: @Remote public interface A { public Response doSomething(); } And implementation: @Stateless public class B implements A { public BeeResponse doSomething() {...} } Where: BeeResponse extends Response. Response is located in the EJB-API jar and BeeResponse is in the implementation jar. Response and BeeResponse have different serialVersionUID. My assumption is that the unmarshalling of the response from B will fail, am I correct?

    Read the article

  • Returning data from SQL Server reporting web service call

    - by user79339
    Hi, I am generating a report that contains the version number. The version number is stored in the DB and retrieved/incremented as part of the report generation. The only problem is, I am calling SSRS via a web service call, which returns the generated report as a byte array. Is there any way to get the version number out of this generated report? For example to display a dialog that says "You generated Status Report, Version number 3". I tried passing in an output parameter and setting it inside the storedproc. Its modified when i execute it in sql management studio, but not in the reporting studio. Or atleast i can't seem to bind to the modified, post execution value (using expression "=Parameters!ReportVersion.Value"). Of course, I could get/increment the version number from database myself before calling the SSRS webservice and pass it along as a parameter to the Report, but that might cause concurrancy problems. On the whole, it just seems neater for the storedproc to access/generate a version number and return it to the ReportingEngine, which will generate the report with the version number and return the updated version number to the WebService client. Any thoughts/Ideas?

    Read the article

  • Function returning MYSQL_ROW

    - by Gabe
    I'm working on a system using lots of MySQL queries and I'm running into some memory problems I'm pretty sure have to do with me not handling pointers right... Basically, I've got something like this: MYSQL_ROW function1() { string query="SELECT * FROM table limit 1;"; MYSQL_ROW return_row; mysql_init(&connection); // "connection" is a global variable if (mysql_real_connect(&connection,HOST,USER,PASS,DB,0,NULL,0)){ if (mysql_query(&connection,query.c_str())) cout << "Error: " << mysql_error(&connection); else{ resp = mysql_store_result(&connection); //"resp" is also global if (resp) return_row = mysql_fetch_row(resp); mysql_free_result(resp); } mysql_close(&connection); }else{ cout << "connection failed\n"; if (mysql_errno(&connection)) cout << "Error: " << mysql_errno(&connection) << " " << mysql_error(&connection); } return return_row; } And function2(): MYSQL_ROW function2(MYSQL_ROW row) { string query = "select * from table2 where code = '" + string(row[2]) + "'"; MYSQL_ROW retorno; mysql_init(&connection); if (mysql_real_connect(&connection,HOST,USER,PASS,DB,0,NULL,0)){ if (mysql_query(&connection,query.c_str())) cout << "Error: " << mysql_error(&conexao); else{ // My "debugging" shows me at this point `row[2]` is already fubar resp = mysql_store_result(&connection); if (resp) return_row = mysql_fetch_row(resp); mysql_free_result(resp); } mysql_close(&connection); }else{ cout << "connection failed\n"; if (mysql_errno(&connection)) cout << "Error : " << mysql_errno(&connection) << " " << mysql_error(&connection); } return return_row; } And main() is an infinite loop basically like this: int main( int argc, char* args[] ){ MYSQL_ROW row = NULL; while (1) { row = function1(); if(row != NULL) function2(row); } } (variable and function names have been generalized to protect the innocent) But after the 3rd or 4th call to function2, that only uses row for reading, row starts losing its value coming to a segfault error... Anyone's got any ideas why? I'm not sure the amount of global variables in this code is any good, but I didn't design it and only got until tomorrow to fix and finish it, so workarounds are welcome! Thanks!

    Read the article

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