Daily Archives

Articles indexed Tuesday December 28 2010

Page 4/34 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • how can i acess a variable outside of an if statement in java

    - by themanepalli
    i have defined a variable inside an if statement and I am trying to access it outside of that if statement now. now the error is saying that it cannot find the symbol which is because its being defined as an intance variable, is there a way i can change it so i can access it outside the variable? heres the code if((e.getSource()==userOrder2)&& (orderType==1)) { String buyO= userOrder2.getText(); int buyOrder= Integer.parseInt(buyO); //variable im trying to access } // trying to use buyOrder in a different if statement if(orderType==1 && (stockPrice <= buyOrder)) { orderResult.setText("The Stock" + (stockName2.getText()) + "was bought at" + stockPrice); }

    Read the article

  • Rails always include (join) on initialize

    - by Seth
    Hello, I have a User model as illustrated below: class User < ActiveRecord belongs_to :college belongs_to :class_level end I want to ALWAYS join with those other two tables returning one simplified User object. How do I accomplish this in my User model. I'm aware that I can do this in another model: class Foo < ActiveRecord has_many :users, :include => [:college, :class_level] end But I want to do this in my User model, so Foo.users will either be eager loaded OR be joined already. Is there a way to create an initialize this in the User model?

    Read the article

  • Algorithm to split an array into N groups based on item index (should be something simple)

    - by serg
    I feel that it should be something very simple and obvious but just stuck on this for the last half an hour and can't move on. All I need is to split an array of elements into N groups based on element index. For example we have an array of 30 elements [e1,e2,...e30], that has to be divided into N=3 groups like this: group1: [e1, ..., e10] group2: [e11, ..., e20] group3: [e21, ..., e30] I came up with nasty mess like this for N=3 (pseudo language, I left multiplication on 0 and 1 just for clarification): for(i=0;i<array_size;i++) { if(i>=0*(array_size/3) && i<1*(array_size/3) { print "group1"; } else if(i>=1*(array_size/3) && i<2*(array_size/3) { print "group2"; } else if(i>=2*(array_size/3) && i<3*(array_size/3) print "group3"; } } But what would be the proper general solution? Thanks.

    Read the article

  • design a large scale network for an organization

    - by Essam
    hello.i am so new to networking i want to design a large scale network for an organization with HQ and two branches. i want to use class A address for that.my questions are: if i am using the network address 30.0.0.0 for the whole organization how can it be different from another organization company or whatever which is using the same address in another country? now i have the three locations for this organization,so i need 5 subnets [one for the HQ,two for branch A and branch B , one for connecting A to HQ and one for connecting branch B with HQ since i will use central DHCP server at the HQ,is that(number of subnetting) right? is it advisable to use class A or class B for this organization it term of address that will be wasted (lets say it is a university with two branches in two different states)?! that is all your help is highly appropriated.

    Read the article

  • Java, let CookieHandler work on only one instance.

    - by user435657
    Hi all, I don't know how CookieHandler works system wide, I did view the source of CookieHandler but found no more information except the get/set methods. Where do TCP/HTTP connections use instance of CookieHandler, which I set by CookieHandler.setDefault(...) Which source file I should refer to? URLConnection & HttpURLConnection don't seem have things to do with it. Help, thanks in advance.

    Read the article

  • How can developers use a similar tracking link to Google's results page?

    - by Peter Jones
    I've read heaps of pages of people trying to implement some kind of tracking system similar to the way Google reroutes search link. Eg: Search "Facebook" in Google, open in a new window, and the link changes to something like: "http://www.google.com.au/url?sa=t&source=web&cd=1&ved=0CBkQFjAA&url=http%3A%2F%2Fwww.facebook.com%2F&rct=j&q=Facebook&ei=sksZTZexJobJccXnxZYK&usg=AFQjCNHTTNi-O4Qgrg6kvGVfKJuRqbuOKw&cad=rja" I'm guessing Google tracks that click and then redirects to the actual site by reading the url parameter. What I wanted to know is if there was a simple way that you can make this kind of functionality work using an onclick event - just change the link href after being clicked to redirect? There's a few threads, but from what I could find, nobody has actually succeeded without problems or limitations. Thanks in advance.

    Read the article

  • Question with "extern" in C

    - by why
    When programming, I would like to split one large file(which contains main function) to many small files, so there is one common case: functions in small files can modify the var from main file, so i think extern is very useful! for instance: in main.c extern int i = 100; in small.c extern int i; fprintf(stdout, "var from main file: %d\n", i); I just want to know is my understanding right?

    Read the article

  • What's the difference between => , ()=>, and Unit=>

    - by Malvolio
    I'm trying to represent a function that takes no arguments and returns no value (I'm simulating the setTimeout function in JavaScript, if you must know.) case class Scheduled(time : Int, callback : => Unit) doesn't compile, saying " `val' parameters may not be call-by-name" case class Scheduled(time : Int, callback : () => Unit) compiles, but has to be invoked strangely, instead of Scheduled(40, { println("x") } ) I have to do this Scheduled(40, { () => println("x") } ) What also works is class Scheduled(time : Int, callback : Unit => Unit) but is invoked in an even-less-sensible way Scheduled(40, { x : Unit => println("x") } ) (What would a variable of type Unit be?) What I want of course is a constructor that can be invoke the way I would invoke it if it were an ordinary function: Scheduled(40, println("x") ) Give baby his bottle!

    Read the article

  • How could I send live video stream to remote server from my phone !!!

    - by poc
    Hello , I have a problem about streaming my video to server in real-time from my phone. that is , let my phone be a IP Camera , and server can watch the live video from my phone I have googled many many solutions, but there is no one can solve my problem. I use MediaRecorder to record . it can save video file in the SD card correctly. then , I refered this page and used some method as followings skt = new Socket(InetAddress.getByName(hostname),port); pfd =ParcelFileDescriptor.fromSocket(skt); mediaRecorder.setOutputFile(pfd.getFileDescriptor()); now it seems I can send the video stream while recording however, I wrote a receiver-side program to receive the video stream from Android , but it doesn't work . is there any error? I can receive file , but I can not open the video file . I guess the problem may caused by file format ? there are outline of my code. in android side Socket skt = new Socket(hostIP,port); ParcelFileDescriptor pfd =ParcelFileDescriptor.fromSocket(skt); .... .... mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); mediaRecorder.setOutputFile(pfd.getFileDescriptor()); ..... mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); ..... mediaRecorder.start(); in receiver side (my ACER notebook) // anyway , I don't think the file extentions will do any effect File video = new File (strDate+".3gpp"); FileOutputStream fos; try { fos = new FileOutputStream(video); byte[] data = new byte[1024]; int count =-1; while( (count = fin.read(data,0,1024) ) !=-1) { fos.write(data,0,count); fos.flush(); } fos.close(); fin.close(); I confused a long time.... thanks in advance

    Read the article

  • SSH with Perl using file handles, not Net::SSH

    - by jorge
    Before I ask the question: I can not use cpan module Net::SSH, I want to but can not, no amount of begging will change this fact I need to be able to open an SSH connection, keep it open, and read from it's stdout and write to its stdin. My approach thus far has been to open it in a pipe, but I have not been able to advance past this, it dies straight away. That's what I have in mind, I understand this causes a fork to occur. I've written code accordingly for this fork (or so I think). Below is a skeleton of what I want, I just need the system to work. #!/usr/bin/perl use warnings; $| = 1; $pid = open (SSH,"| ssh user\@host"); if(defined($pid)){ if(!$pid){ #child while(<>){ print; } }else{ select SSH; $| = 1; select STDIN; #parent while(<>){ print SSH $_; while(<SSH>){ print; } } close(SSH); } } I know, from what it looks like, I'm trying to recreate "system('ssh user@host')," that is not my end goal, but knowing how to do that would bring me much closer to the end goal. Basically, I need a file handle to an open ssh connection where I can read from it the output and write to it input (not necessarily straight from my program's STDIN, anything I want, variables, yada yada) This includes password input. I know about key pairs, part of the end goal involves making key pairs, but the connection needs to happen regardless of their existence, and if they do not exist it's part of my plan to make them exist.

    Read the article

  • An INSERT conditioned on COUNT

    - by Anders Feder
    How can I construct a MySQL INSERT query that only executes if the number of rows satisfying some condition already in the table is less than 20, and fails otherwise? That is, if the table has 18 rows satisfying the condition, then the INSERT should proceed. If the table has 23 rows satisfying the condition, then the INSERT should fail. For atomicity, I need to express this in a single query, so two requests can not INSERT at the same time, each in the 'belief' that only 19 rows satisfy the condition. Thank you.

    Read the article

  • iPhone: How many instances of AVAudioPlayer should I have for multiple sounds?

    - by foreyez
    So I'm using AvAudioPlayer to play multiple wav files. About 20 different sounds (each about 1 sec long), and you can think of each being played on a button press. Also I don't need them all to play simultaneously, i.e., one plays and you press another button to play another one (which stops the currently played one). What I'm wondering, should I have multiple instances of AVAudioPlayer (20 of them) and then preload the audio files, or should I just use one instance of AvAudioPlayer and each time a button is pressed, initialize the AvAudioPlayer with the sound url (or would this be too slow?) Thanks in advance!

    Read the article

  • Can't find .js file in my mainBundle?!

    - by Nic Hubbard
    This is driving me crazy as I cannot figure out what in the world is going on. I load up files form you main bundle all the time, xml files, html files, etc. But, now I am trying to get the contents of a javascript file but it can never find it. I am using: NSData *jsData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"global" ofType:@"js"]]; if (jsData) { NSLog(@"%@", jsData); } else { NSLog(@"Can't find file"); return; } Even checking the [[NSBundle mainBundle] pathForResource:@"global" ofType:@"js"] string returns null. My globaly.js file is in my Resources folder, the exact location where my other files are location that work totally fine using the above method. Why can't it find my js file?

    Read the article

  • Best practices for JQuery namespaces + general purpose utility functions

    - by Armchair Bronco
    What are some current "rules of thumb" for implementing JQuery namespaces to host general purpose utility functions? I have a number of JavaScript utility methods scattered in various files that I'd like to consolidate into one (or more) namespaces. What's the best way to do this? I'm currently looking at two different syntaxes, listed in order of preference: //****************************** // JQuery Namespace syntax #1 //****************************** if (typeof(MyNamespace) === "undefined") { MyNamespace = {}; } MyNamespace.SayHello = function () { alert("Hello from MyNamespace!"); } MyNamespace.AddEmUp = function (a, b) { return a + b; } //****************************** // JQuery Namespace syntax #2 //****************************** if (typeof (MyNamespace2) === "undefined") { MyNamespace2 = { SayHello: function () { alert("Hello from MyNamespace2!"); }, AddEmUp: function (a, b) { return a + b; } }; } Syntax #1 is more verbose but it seems like it would be easier to maintain down the road. I don't need to add commas between methods, and I can left align all my functions. Are there other, better ways to do this?

    Read the article

  • Open browser window with formed URL after posting a PHP form

    - by Gotjosh
    So here's the question. I have this php form that collects some data, after posting the data gets parsed an URL is constructed. After this URL is constructed, I'd like to open a new browser window for the user with this newly constructed URL. How can I actually accomplish this? Is this something that can only be done with javascript? If so... How? I already have the code in place and i've tested it works that construct the URL after posting the form, now it's just a matter of opening a new window with the URL.

    Read the article

  • Multithreading for loop while maintaining order

    - by David
    I started messing around with multithreading for a CPU intensive batch process I'm running. Essentially I'm trying to condense multiple single page tiffs into single PDF documents. This works fine with a foreach loop or standard iteration but can be very slow for several 100 page documents. I tried the following based on a some examples I found to use multithreading and it has significant performance improvements however it obliterates the page order instead of 1,2,3,4 it will be 1,3,4,2,6,5 on what thread completes first. My question is how would I utilize this technique while maintaining the page order and if I can will it negate the performance benefit of the multithreading? Thank you in advance. PdfDocument doc = new PdfDocument(); string mail = textBox1.Text; string[] split = mail.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); int counter = split.Count(); // Source must be array or IList. var source = Enumerable.Range(0, 100000).ToArray(); // Partition the entire source array. var rangePartitioner = Partitioner.Create(0, counter); double[] results = new double[counter]; // Loop over the partitions in parallel. Parallel.ForEach(rangePartitioner, (range, loopState) => { // Loop over each range element without a delegate invocation. for (int i = range.Item1; i < range.Item2; i++) { f_prime = split[i].Replace(" " , ""); PdfPage page = doc.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XImage image = XImage.FromFile(f_prime); double x = 0; gfx.DrawImage(image, x, 0); } });

    Read the article

  • rgl.snapshot() No Longer Works

    - by bill_080
    I just upgraded R and rgl to the following versions. Now, rgl.snapshot() no longer works. It worked in previous versions. Is there a way around this? R version 2.12.1 (2010-12-16) rgl version 0.92.798 > library(rgl) > x<-rnorm(100) > y<-rnorm(100) > z<-rnorm(100) > r<-0.2 > p <- plot3d(x, y, z, axes=FALSE, box=FALSE, radius=r, type='s', + xlab="", ylab="", zlab="", col=rainbow(100)) > rgl.snapshot("C:\\Temp\\pic.png", fmt="png", top=TRUE ) Error in rgl.snapshot("C:\\Temp\\pic.png") : pixmap save format not supported in this build

    Read the article

  • Auto-complete/suggestion popup menu in GtkTextView

    - by Tyler
    I'm trying to create a system that will allow me to respond to the current text and auto-complete/suggest what should come next. For example if the user starts to type "Batm" then the system would respond with a menu showing the full completed word "Batman". Think of an IDE like Eclipse or Visual Studio and you get the idea. I understand how to create a popup menu in Gtk+ but what I don't understand is the following: How do I grab the word that the user is currently typing from a GtkTextView (or SourceView) so that I can do a lookup and offer suggestions? How do I position the menu in such a way that it sits next to the current text item (like it would in an IDE)? If anyone could offer suggestions or even a link to a tutorial or example on how to do this correctly I would be forever grateful. As always thanks for you help! Programming language: C

    Read the article

  • ASP.NET: Serializing and deserializing JSON objects

    - by DigiMortal
    ASP.NET offers very easy way to serialize objects to JSON format. Also it is easy to deserialize JSON objects using same library. In this posting I will show you how to serialize and deserialize JSON objects in ASP.NET. All required classes are located in System.Servicemodel.Web assembly. There is namespace called System.Runtime.Serialization.Json for JSON serializer. To serialize object to stream we can use the following code. var serializer = new DataContractJsonSerializer(typeof(MyClass)); serializer.WriteObject(myStream, myObject); To deserialize object from stream we can use the following code. CopyStream() is practically same as my Stream.CopyTo() extension method. var serializer = new DataContractJsonSerializer(typeof(MyClass));   using(var stream = response.GetResponseStream()) using (var ms = new MemoryStream()) {     CopyStream(stream, ms);     results = serializer.ReadObject(ms) as MyClass; } Why I copied data from response stream to memory stream? Point is simple – serializer uses some stream features that are not supported by response stream. Using memory stream we can deserialize object that came from web.

    Read the article

  • Looking at desktop virtualization, but some users need 3D support. Is HP Remote Graphics a viable solution?

    - by Ryan Thompson
    My company is looking at desktop virtualization, and are planning to move all of the desktop compute resources into the server room or data center, and provide users with thin clients for access. In most cases, a simple VNC or Remote Desktop solution is adequate, but some users are running visualizations that require 3D capability--something that VNC and Remote Desktop cannot support. Rather than making an exception and providing desktop machines for these users, complicating out rollout and future operations, we are considering adding servers with GPUs, and using HP's Remote Graphics to provide access from the thin client. The demo version appears to work acceptably, but there is a bit of a learning curve, it's not clear how well it would work for multiple simultaneous sessions, and it's not clear if it would be a good solution to apply to non-3D sessions. If possible, as with the hardware, we want to deploy a single software solution instead of a mishmash. If anyone has had experience managing a large installation of HP Remote Graphics, I would appreciate any feedback you can provide.

    Read the article

  • Xen Windows Guest spawn doesn't spawn a vnc display

    - by Henrik P. Hessel
    I'm using this HVM File to create a new guest kernel = "/usr/lib/xen-3.2-1/boot/hvmloader" builder='hvm' memory = 4096 # Should be at least 2KB per MB of domain memory, plus a few MB per vcpu. shadow_memory = 64 name = "hessel-windows2008" vif = [ 'ip=188.40.xx.xx,mac=00:16:3E:C1:8F:CE' ] acpi = 1 apic = 1 disk = [ 'file:/home/xen/disks/hessel/win2008/win2008.img,hda,w', 'file:/home/xen/isopool/win2008_32.iso,hdc:cdrom,r' ] device_model = '/usr/lib/xen/bin/qemu-dm' #----------------------------------------------------------------------------- # boot on floppy (a), hard disk (c) or CD-ROM (d) # default: hard disk, cd-rom, floppy boot="dc" sdl=0 vnc=1 vncdisplay=1 vnclisten="0.0.0.0" vncconsole=1 vncpasswd='howtoforge' stdvga=0 serial='pty' usbdevice='tablet' The guest is created without an error. But no vnc display is created. Any ideas, how to fix that? prometheus:~# netstat -ant Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:615 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN tcp 0 232 188.40.xx.xx:8080 195.36.75.26:54032 ESTABLISHED tcp 0 0 188.40.xx.xx:8080 195.36.75.26:53085 ESTABLISHED tcp6 0 0 :::8080 :::* LISTEN tcp6 0 0 :::53 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 ::1:6010 :::* LISTEN

    Read the article

  • Google DNS Same Entry Different Results

    - by Henrik P. Hessel
    Why is this happening? The Rootserver returns a wrong entry I fixed containing 5269.XXX.com. instead of 5269 XXX.com. Macbook @ Home ; <<>> DiG 9.6.0-APPLE-P2 <<>> @8.8.8.8 srv _xmpp-server._tcp.XXX.com. ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18412 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;_xmpp-server._tcp.XXX.com. IN SRV ;; ANSWER SECTION: _xmpp-server._tcp.XXX.com. 64328 IN SRV 10 0 5269 XXX.com. ;; Query time: 21 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Tue Dec 28 03:16:45 2010 ;; MSG SIZE rcvd: 86 Rootserver ; <<>> DiG 9.6-ESV-R1 <<>> @8.8.8.8 srv _xmpp-server._tcp.XXX.com. ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27240 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;_xmpp-server._tcp.XXX.com. IN SRV ;; ANSWER SECTION: _xmpp-server._tcp.XXX.com. 52139 IN SRV 0 10 0 5269.XXX.com. ;; Query time: 7 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Tue Dec 28 03:23:23 2010 ;; MSG SIZE rcvd: 91

    Read the article

  • Trackpad Drag lock pissing me off with Windows 7

    - by rockinthesixstring
    This is driving me insane and I've scowered the web for two days trying to fix this. I just picked up an Apple Magic Trackpad to be used exclusively on a Windows 7 PC (not apple with bootcamp). I found a nice driver that got it working right away, but when I'm moving the cursor around the screen, often it will begin "highlighting" text, or picking up and dragging things I don't want it to. I looked in the "regedit" where people are saying there is binary that can be changed, however the driver I installed doesn't use the binary being suggested. Can anyone suggest a better driver for my situation or a way to disable the drag lock that is driving me so nuts? I don't mind not being able to lift my finger when dragging, it's a far better compromise than having the insane feature.

    Read the article

  • Windows XP Blue-Screens And Reboots Instantly On Boot-Up

    - by ashes999
    My computer was running perfectly until yesterday; my internet suddenly died. Being wireless, I decided to reboot; now the computer doesn't boot. It shows the "Starting Windows" screen (safe mode loads several drivers), then it suddenly blue-screens and immediately reboots (I cannot read the blue-screen contents at all). I've tried safe-mode (with and without networking); no dice. I booted another HD with another XP install and ran scandisk on my HDs; no bad sectors, and even with auto-repair, it didn't fix the problem. Now what? What are my options to fix the broken XP install? I'm thinking: 1) Remove wireless card 2) Run XP install CD and repair installation 3) ???

    Read the article

  • Can't access certain specific IP/domain on Windows 7

    - by jfrobishow
    Been banging my head on the wall for some time now. I have a fresh install of Windows 7 - Ultimate ~x86. Some IPs can't resolve properly, it doesn't matter if I try using Firefox, Chrome or IE I end up with a domain not found (server not found, etc.) I am behind a router, all the other computers aren't affected only this Win 7 machine. It's only certain sites. e.g. xkcd.com, facebook's cdn, google group. Things I have tried: flushdns ipconfig renew Disable IP v6 on the NIC Double checked that the computer was in the right timezone @ the right time. Reinstall the NIC driver. Again 90% of the sites will work but not the major one :P help!!!

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >