Search Results

Search found 613 results on 25 pages for 'ray wenderlich'.

Page 11/25 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Exception in thread "main" java.lang.StackOverflowError

    - by Ray.R.Chua
    I have a piece of code and I could not figure out why it is giving me Exception in thread "main" java.lang.StackOverflowError. This is the question: Given a positive integer n, prints out the sum of the lengths of the Syracuse sequence starting in the range of 1 to n inclusive. So, for example, the call: lengths(3) will return the the combined length of the sequences: 1 2 1 3 10 5 16 8 4 2 1 which is the value: 11. lengths must throw an IllegalArgumentException if its input value is less than one. My Code: import java.util.HashMap; public class Test { HashMap<Integer,Integer> syraSumHashTable = new HashMap<Integer,Integer>(); public Test(){ } public int lengths(int n)throws IllegalArgumentException{ int sum =0; if(n < 1){ throw new IllegalArgumentException("Error!! Invalid Input!"); } else{ for(int i =1; i<=n;i++){ if(syraSumHashTable.get(i)==null) { syraSumHashTable.put(i, printSyra(i,1)); sum += (Integer)syraSumHashTable.get(i); } else{ sum += (Integer)syraSumHashTable.get(i); } } return sum; } } private int printSyra(int num, int count){ int n = num; if(n == 1){ return count; } else{ if(n%2==0){ return printSyra(n/2, ++count); } else{ return printSyra((n*3)+1, ++count) ; } } } } Driver code: public static void main(String[] args) { // TODO Auto-generated method stub Test s1 = new Test(); System.out.println(s1.lengths(90090249)); //System.out.println(s1.lengths(5)); } . I know the problem lies with the recursion. The error does not occur if the input is a small value, example: 5. But when the number is huge, like 90090249, I got the Exception in thread "main" java.lang.StackOverflowError. Thanks all for your help. :) I almost forgot the error msg: Exception in thread "main" java.lang.StackOverflowError at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:65) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:65) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:60) at Test.printSyra(Test.java:60)

    Read the article

  • I want to combine my www and non www and keep the link jucie from both.

    - by John Ray
    My website shows up for some keywords in the www and some in the non www. Seaquake shows more links to the non www version. It is a PR2 either way. I would like to combine the link juice of the two versions into the non www version. Does anyone know the best way to combine the two and keep the link juice of both. It is as simple as a 301 redirect and if so does the 301 need to be handled in any specific way.

    Read the article

  • Rails acts_as_taggable_on grouped alphabetically?

    - by Ray Dookie
    Having sorted the tag_counts hash via the following code: sorted_tags = Contact.tag_counts.sort{ |x,y| x.name.downcase <= y.name.downcase } what is the easiest/most efficient way to display the tags in my view grouped by letters? i.e A - "Alpha", "Apple", "Aza" B - "Beta", "Bonkers" . . . Z - "Zeta", "Zimmer" Any ideas?

    Read the article

  • Threading is slow and unpredictable?

    - by Jake
    I've created the basis of a ray tracer, here's my testing function for drawing the scene: public void Trace(int start, int jump, Sphere testSphere) { for (int x = start; x < scene.SceneWidth; x += jump) { for (int y = 0; y < scene.SceneHeight; y++) { Ray fired = Ray.FireThroughPixel(scene, x, y); if (testSphere.Intersects(fired)) sceneRenderer.SetPixel(x, y, Color.Red); else sceneRenderer.SetPixel(x, y, Color.Black); } } } SetPixel simply sets a value in a single dimensional array of colours. If I call the function normally by just directly calling it it runs at a constant 55fps. If I do: Thread t1 = new Thread(() => Trace(0, 1, testSphere)); t1.Start(); t1.Join(); It runs at a constant 50fps which is fine and understandable, but when I do: Thread t1 = new Thread(() => Trace(0, 2, testSphere)); Thread t2 = new Thread(() => Trace(1, 2, testSphere)); t1.Start(); t2.Start(); t1.Join(); t2.Join(); It runs all over the place, rapidly moving between 30-40 fps and sometimes going out of that range up to 50 or down to 20, it's not constant at all. Why is it running slower than it would if I ran the whole thing on a single thread? I'm running on a quad core i5 2500k.

    Read the article

  • Why doesn't IB see my IBAction?

    - by Dan Ray
    I've been staring at this for way too long. There's nothing fancy happening here, and I've done this dozens of times, yet Interface Builder steadfastly refuses to provide me an action target for -(IBAction)slideDirections. I'm at the point where I'm willing to post publicly and feel stupid. So let 'er rip. Here's my .h: #import <UIKit/UIKit.h> #import <MapKit/MapKit.h> @interface PulseDetailController : UIViewController { NSDictionary *pulse; IBOutlet MKMapView *map; IBOutlet UIWebView *directions; IBOutlet UIView *directionsSlider; BOOL directionsExtended; IBOutlet UILabel *vendor; IBOutlet UILabel *offer; IBOutlet UILabel *offerText; IBOutlet UILabel *hours; IBOutlet UILabel *minutes; IBOutlet UILabel *seconds; IBOutlet UILabel *distance } @property (nonatomic, retain) NSDictionary *pulse; @property (nonatomic, retain) MKMapView *map; @property (nonatomic, retain) UIWebView *directions; @property (nonatomic, retain) UIView *directionsSlider; @property (nonatomic) BOOL directionsExtended; @property (nonatomic, retain) UILabel *vendor; @property (nonatomic, retain) UILabel *offer; @property (nonatomic, retain) UILabel *offerText; @property (nonatomic, retain) UILabel *hours; @property (nonatomic, retain) UILabel *minutes; @property (nonatomic, retain) UILabel *seconds; @property (nonatomic, retain) UILabel *distance; -(IBAction)slideDirections; @end

    Read the article

  • Craziest JavaScript behavior I've ever seen

    - by Dan Ray
    And that's saying something. This is based on the Google Maps sample for Directions in the Maps API v3. <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <title>Google Directions</title> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var directionDisplay; var directionsService = new google.maps.DirectionsService(); var map; function initialize() { directionsDisplay = new google.maps.DirectionsRenderer(); var myOptions = { zoom:7, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); directionsDisplay.setMap(map); directionsDisplay.setPanel(document.getElementById("directionsPanel")); } function render() { var start; if(navigator.geolocation) { navigator.geolocation.getCurrentPosition(function(position) { start = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); }, function() { handleNoGeolocation(browserSupportFlag); }); } else { // Browser doesn't support Geolocation handleNoGeolocation(); } alert("booga booga"); var end = '<?= $_REQUEST['destination'] ?>'; var request = { origin:start, destination:end, travelMode: google.maps.DirectionsTravelMode.DRIVING }; directionsService.route(request, function(response, status) { if (status == google.maps.DirectionsStatus.OK) { directionsDisplay.setDirections(response); } }); } </script> </head> <body style="margin:0px; padding:0px;" onload="initialize()"> <div><div id="map_canvas" style="float:left;width:70%; height:100%"></div> <div id="directionsPanel" style="float:right;width:30%;height 100%"></div> <script type="text/javascript">render();</script> </body> </html> See that "alert('booga booga')" in there? With that in place, this all works fantastic. Comment that out, and var start is undefined when we hit the line to define var request. I discovered this when I removed the alert I put in there to show me the value of var start, and it quit working. If I DO ask it to alert me the value of var start, it tells me it's undefined, BUT it has a valid (and accurate!) value when we define var request a few lines later. I'm suspecting it's a timing issue--like an asynchronous something is having time to complete in the background in the moment it takes me to dismiss the alert. Any thoughts on work-arounds?

    Read the article

  • Handling session between two pages in iframe-based facebook app.

    - by Ray Yun
    I'm a newbie to iframe based facebook application and stuck with session related problems. There are just two pages in my app. First page got many fb_sig_* parameters from facebook platform but when I click a anchor to next page, those fb_sig_* were lost because this is just direct request from end user's browser not from facebook. So I found that http://forum.developers.facebook.com/viewtopic.php?id=52885. It was told that I should not using cookie and always append every fb_sig* to every anchor. This can be the only solution for my problems? Any side effect like session expiry problem?

    Read the article

  • Why doesn't this UIButton show its text label?

    - by Dan Ray
    Everything about this UIButton renders great except the text that's supposed to be on it. NSLog demonstrates that the text is in the right place. What gives? UIButton *newTagButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [newTagButton addTarget:self action:@selector(showNewTagField) forControlEvents:UIControlEventTouchUpInside]; newTagButton.titleLabel.text = @"+ New Tag"; NSLog(@"Just set button label to %@", newTagButton.titleLabel.text); newTagButton.titleLabel.font = [UIFont systemFontOfSize:17]; newTagButton.titleLabel.textColor = [UIColor redColor]; CGSize addtextsize = [newTagButton.titleLabel.text sizeWithFont:[UIFont systemFontOfSize:17]]; CGSize buttonsize = { (addtextsize.width + 20), (addtextsize.height * 1.2) }; newTagButton.frame = CGRectMake(x, y, buttonsize.width, buttonsize.height); [self.mainView addSubview:newTagButton];

    Read the article

  • Improving the efficiency of Kinect for Windows DTWGestureRecognition Application

    - by Ray
    Currently I am using the DTWGestureRecognition open source tool for Kinect SDK v1.5. I have recorded a few gestures and use them to navigate through Windows 7. I also have implemented voice control for simple things such as opening PowerPoint, Chrome, etc. My main issue is that the application uses quite a bit of my CPU power which causes it to become slow. During gestures and voice commands, the CPU usage sometimes spikes to 80-90%, which causes the application to be unresponsive for a few seconds. I am running it on a 64 bit Windows 7 machine with an i5 processor and 8 GB of RAM. I was wondering if anyone with any experience using this tool or Kinect in general has made it more efficient and less performance hogging. Right now I removed sections which display the RGB video and the Depth video but even doing that did not make a big impact. Any help is appreciated, thanks!

    Read the article

  • Creating New Objects in JavaScript

    - by Ken Ray
    I'm a relatively newbie to object oriented programming in JavaScript, and I'm unsure of the "best" way to define and use objects in JavaScript. I've seen the "canonical" way to define objects and instantiate a new instance, as shown below. function myObjectType(property1, propterty2) { this.property1 = property1, this.property2 = property2 } // now create a new instance var myNewvariable = new myObjectType('value for property1', 'value for property2'); But I've seen other ways to create new instances of objects in this manner: var anotherVariable = new someObjectType({ property1: "Some value for this named property", property2: "This is the value for property 2" }); I like how that second way appears - the code is self documenting. But my questions are: Which way is "better"? Can I use that second way to instantiate a variable of an object type that has been defined using the "classical"way of defining the object type with that implicit constructor? If I want to create an array of these objects, are there any other considerations? Thanks in advance.

    Read the article

  • Application.ProcessMessages hangs???

    - by X-Ray
    my single threaded delphi 2009 app (not quite yet complete) has started to have a problem with Application.ProcessMessages hanging. my app has a TTimer object that fires every 100 ms to poll an external device. i use Application.ProcessMessages to update the screen when something changes so the app is still responsive. one of these was in a grid OnMouseDown event. in there, it had an Application.ProcessMessages that essentially hung. removing that was no problem except that i soon discovered another Application.ProcessMessages that was also blocking. i think what may be happening to me is that the TTimer is--in the app mode i'm currently debugging--probably taking too long to complete. i have prevented the TTimer.OnTimer event hander from re-entering the same code (see below): procedure TfrmMeas.tmrCheckTimer(Sender: TObject); begin if m_CheckTimerBusy then exit; m_CheckTimerBusy:=true; try PollForAndShowMeasurements; finally m_CheckTimerBusy:=false; end; end; what places would it be a bad practice to call Application.ProcessMessages? OnPaint routines springs to mind as something that wouldn't make sense. any general recommendations? i am surprised to see this kind of problem arise at this point in the development!

    Read the article

  • Interpreters: How much simplification?

    - by Ray
    In my interpreter, code like the following x=(y+4)*z echo x parses and "optimizes" down to four single operations performed by the interpreter, pretty much assembly-like: add 4 to y multiply <last operation result> with z set x to <last operation result> echo x In modern interpreters (for example: CPython, Ruby, PHP), how simplified are the "opcodes" for which are in end-effect run by the interpreter? Could I achieve better performance when trying to keep the structures and commands for the interpreter more complex and high-level? That would be surely a lot harder, or?

    Read the article

  • How- XLST Transformation

    - by Yuan Ray
    Just wanted to ask on how to get the author names in the given xml sample below and put an attribut of eq="yes". EQ means Equal Contributors. This is the XML. <ArticleFootnote Type="Misc"> <Para>John Doe and Jane Doe are equal contributors.</Para> </ArticleFootnote> This should be the output in other form of XML. <AuthorGroups> <Authors eq="yes">John Doe</Authors> <Authors eq="yes">Jane Doe</Authors> </AuthorGroups> Assuming that JOhn Doe and Jane Doe are already defined in the list of authors but after the transformation, author tag should have the attribute eq="yes". Please help as I don't know much writing in xlst. Thanks in advance.

    Read the article

  • release vs setting-to-nil to free memory

    - by Dan Ray
    In my root view controller, in my didReceiveMemoryWarning method, I go through a couple data structures (which I keep in a global singleton called DataManager), and ditch the heaviest things I've got--one or maybe two images associated with possibly twenty or thirty or more data records. Right now I'm going through and setting those to nil. I'm also setting myself a boolean flag so that various view controllers that need this data can easily know to reload. Thusly: DataManager *data = [DataManager sharedDataManager]; for (Event *event in data.eventList) { event.image = nil; event.thumbnail = nil; } for (WondrMark *mark in data.wondrMarks) { mark.image = nil; } [DataManager sharedDataManager].cleanedMemory = YES; Today I'm thinking, though... and I'm not actually sure all that allocated memory is really being freed when I do that. Should I instead release those images and maybe hit them with a new alloc and init when I need them again later?

    Read the article

  • overwrite existing entity via bulkloader.Loader

    - by Ray Yun
    I was going to CSV based export/import for large data with app engine. My idea was just simple. First column of CSV would be key of entity. If it's not empty, that row means existing entity and should overwrite old one. Else, that row is new entity and should create new one. I could export key of entity by adding key property. class FrontExporter(bulkloader.Exporter): def __init__(self): bulkloader.Exporter.__init__(self, 'Front', [ ('__key__', str, None), ('name', str, None), ]) But when I was trying to upload CSV, it had failed because bulkloader.Loader.generate_key() was just for "key_name" not "key" itself. That means all exported entities in CSV should have unique 'key_name' if I want to modify-and-reupload them. class FrontLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Front', [ ('_UNUSED', lambda x: None), ('name', lambda x: x.decode('utf-8')), ]) def generate_key(self,i,values): # first column is key keystr = values[0] if len(keystr)==0: return None return keystr I also tried to load key directly without using generate_key(), but both failed. class FrontLoader(bulkloader.Loader): def __init__(self): bulkloader.Loader.__init__(self, 'Front', [ ('Key', db.Key), # not working. just create new one. ('__key__', db.Key), # same... So, how can I overwrite existing entity which has no 'key_name'? It would be horrible if I should give unique name to all entities..... From the first answer, I could handle this problem. :) def create_entity(self, values, key_name=None, parent=None): # if key_name is None: # print 'key_name is None' # else: # print 'key_name=<',key_name,'> : length=',len(key_name) Validate(values, (list, tuple)) assert len(values) == len(self._Loader__properties), ( 'Expected %d columns, found %d.' % (len(self._Loader__properties), len(values))) model_class = GetImplementationClass(self.kind) properties = { 'key_name': key_name, 'parent': parent, } for (name, converter), val in zip(self._Loader__properties, values): if converter is bool and val.lower() in ('0', 'false', 'no'): val = False properties[name] = converter(val) if key_name is None: entity = model_class(**properties) #print 'create new one' else: entity = model_class.get(key_name) for key, value in properties.items(): setattr(entity, key, value) #print 'overwrite old one' entities = self.handle_entity(entity) if entities: if not isinstance(entities, (list, tuple)): entities = [entities] for entity in entities: if not isinstance(entity, db.Model): raise TypeError('Expected a db.Model, received %s (a %s).' % (entity, entity.__class__)) return entities def generate_key(self,i,values): # first column is key if values[0] is None or values[0] in ('',' ','-','.'): return None return values[0]

    Read the article

  • Facebook requests 3 post_authorize/post_remove. How can I stop it?

    - by Ray Yun
    When user authorize or remove application, Facebook always request post_authorize or post_remove callback 3 times. Only I throws HTTP 500 error, it stop calling them. Yeah, it would be easy to ignore subsequent requests when I successfully handled that. So this maybe academic question. Is there any method to stop facebook requests with http status code??? :)

    Read the article

  • Why am I getting this warning about my app delegate and CLLocationManageDelegate?

    - by Dan Ray
    Observe this perfectly simple UIViewController subclass method: -(IBAction)launchSearch { OffersSearchController *search = [[OffersSearchController alloc] initWithNibName:@"OffersSearchView" bundle:nil]; EverWondrAppDelegate *del = [UIApplication sharedApplication].delegate; [del.navigationController pushViewController:search animated:YES]; [search release]; } On the line where I get *del, I am getting a compiler warning that reads, Type 'id <UIApplicationDelegate>' does not conform to the 'CLLocationManagerDelegate' protocol. In fact, my app delegate DOES conform to that protocol, AND what I'm doing here has nothing at all to do with that. So what's up with that message? Secondary question: sometimes I can get to my navigationController via self.navigationController, and sometimes I can't, and have to go to my app delegate's property to get it like I'm doing here. Any hint about why that is would be very useful.

    Read the article

  • Visual Studio 2008 Solution Explorer Randomly Expands Folders

    - by Ray
    VS 2008 is randomly opening sub-folders for me. Sometimes just a few, sometimes every sub-folder in my project or solution. This happens even when I am not using it - last night when I knoocked off, my solution explorer was closed up tight - this morning, one large project had dozens of sub-folders open. This is not a matter of restoring a previously saved state - most of the folders that get opened are not part of the project, and I have never looked at them with VS. I have downloaded and installed the PowerCommands add-in, and it lets me collapse everything nicely. But I don't want to have to do this several times per day - it closes up folders that I want to be open as well. So, does anyone know why this happens and how to stop it? I found this question from a few months ago which is about the same as this one, but was not answered. I am hoping someone has figured out a solution.

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >