Daily Archives

Articles indexed Sunday January 2 2011

Page 8/27 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Complexity of subset product

    - by threenplusone
    I have a set of numbers produced using the following formula with integers 0 < x < a. f(x) = f(x-1)^2 % a For example starting at 2 with a = 649. {2, 4, 16, 256, 636, 169, 5, 25, 649, 576, 137, ...} I am after a subset of these numbers that when multiplied together equals 1 mod N. I believe this problem by itself to be NP-complete (based on similaries to Subset-Sum problem). However starting with any integer (x) gives the same solution pattern. Eg. a = 649 {2, 4, 16, 256, 636, 169, 5, 25, 649, 576, 137, ...} = 16 * 5 * 576 = 1 % 649 {3, 9, 81, 71, 498, 86, 257, 500, 135, 53, 213, ...} = 81 * 257 * 53 = 1 % 649 {4, 16, 256, 636, 169, 5, 25, 649, 576, 137, 597, ...} = 256 * 25 * 137 = 1 % 649 I am wondering if this additional fact makes this problem solvable faster? Or if anyone has run into this problem previously or has any advice?

    Read the article

  • Special characters stripped by mySQL/PHP JSON

    - by Will Gill
    Hi, I have a simple PHP script to extract data from a mySQL database and encode it as JSON. The problem is that special characters (for example German ä or ß characters) are stripped from the JSON response. Everything after the first special character for any single field is just stripped. The fields are set to utf8_bin, and in phpMyAdmin the characters display correctly. The PHP script looks like this: <?php header("Content-type: application/json; charset=utf-8"); $con = mysql_connect('database', 'username', 'password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("sql01_5789willgil", $con); $sql="SELECT * FROM weightevent"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $events = array(); while($row = mysql_fetch_array($result)) { $eventid = $row['eventid']; $userid = $row['userid']; $weight = $row['weight']; $sins = $row['sins']; $gooddeeds = $row['gooddeeds']; $date = $row['date']; $event = array("eventid"=>$eventid, "userid"=>$userid, "weight"=>$weight, "sins"=>$sins, "gooddeeds"=>$gooddeeds, "date"=>$date); array_push($events, $event); } $myJSON = json_encode($events); echo $myJSON; mysql_close($con); ?> Sample output: [{"eventid":"2","userid":"1","weight":"70.1","sins":"Weihnachtspl","gooddeeds":"situps! lots and lots of situps!","date":"2011-01-02"},{"eventid":"3","userid":"2","weight":"69.9","sins":"A second helping of pasta...","gooddeeds":"I ate lots of salad","date":"2011-01-01"}] -- in the first record the value for field 'sins' should be "Weihnachtsplätzchen". thanks very much!

    Read the article

  • Calling from C# to C function which accept a struct array allocated by caller

    - by lifey
    I have the following C struct struct XYZ { void *a; char fn[MAX_FN]; unsigned long l; unsigned long o; }; And I want to call the following function from C#: extern "C" int func(int handle, int *numEntries, XYZ *xyzTbl); Where xyzTbl is an array of XYZ of size numEntires which is allocated by the caller I have defined the following C# struct: [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Ansi)] public struct XYZ { public System.IntPtr rva; [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 128)] public string fn; public uint l; public uint o; } and a method: [System.Runtime.InteropServices.DllImport(@"xyzdll.dll", CallingConvention = CallingConvention.Cdecl)] public static extern Int32 func(Int32 handle, ref Int32 numntries, [MarshalAs(UnmanagedType.LPArray)] XYZ[] arr); Then I try to call the function : XYZ xyz = new XYZ[numEntries]; for (...) xyz[i] = new XYZ(); func(handle,numEntries,xyz); Of course it does not work. Can someone shed light on what I am doing wrong ?

    Read the article

  • Retain cycle on `self` with blocks

    - by Jonathan Sterling
    I'm afraid this question is pretty basic, but I think it's relevant to a lot of Objective-C programmers who are getting into blocks. What I've heard is that since blocks capture local variables referenced within them as const copies, using self within a block can result in a retain cycle, should that block be copied. So, we are supposed to use __block to force the block to deal directly with self instead of having it copied. __block typeof(self) bself = self; [someObject messageWithBlock:^{ [bself doSomething]; }]; instead of just [someObject messageWithBlock:^{ [self doSomething]; }]; What I'd like to know is the following: if this is true, is there a way that I can avoid the ugliness (aside from using GC)?

    Read the article

  • BufferedReader no longer buffering after a while?

    - by BobTurbo
    Sorry I can't post code but I have a bufferedreader with 50000000 bytes set as the buffer size. It works as you would expect for half an hour, the HDD light flashing every two minutes or so, reading in the big chunk of data, and then going quiet again as the CPU processes it. But after about half an hour (this is a very big file), the HDD starts thrashing as if it is reading one byte at a time. It is still in the same loop and I think I checked free ram to rule out swapping (heap size is default). Probably won't get any helpful answers, but worth a try. OK I have changed heap size to 768mb and still nothing. There is plenty of free memory and java.exe is only using about 300mb. Now I have profiled it and heap stays at about 200MB, well below what is available. CPU stays at 50%. Yet the HDD starts thrashing like crazy. I have.. no idea. I am going to rewrite the whole thing in c#, that is my solution. Here is the code (it is just a throw-away script, not pretty): BufferedReader s = null; HashMap<String, Integer> allWords = new HashMap<String, Integer>(); HashSet<String> pageWords = new HashSet<String>(); long[] pageCount = new long[78592]; long pages = 0; Scanner wordFile = new Scanner(new BufferedReader(new FileReader("allWords.txt"))); while (wordFile.hasNext()) { allWords.put(wordFile.next(), Integer.parseInt(wordFile.next())); } s = new BufferedReader(new FileReader("wikipedia/enwiki-latest-pages-articles.xml"), 50000000); StringBuilder words = new StringBuilder(); String nextLine = null; while ((nextLine = s.readLine()) != null) { if (a.matcher(nextLine).matches()) { continue; } else if (b.matcher(nextLine).matches()) { continue; } else if (c.matcher(nextLine).matches()) { continue; } else if (d.matcher(nextLine).matches()) { nextLine = s.readLine(); if (e.matcher(nextLine).matches()) { if (f.matcher(s.readLine()).matches()) { pageWords.addAll(Arrays.asList(words.toString().toLowerCase().split("[^a-zA-Z]"))); words.setLength(0); pages++; for (String word : pageWords) { if (allWords.containsKey(word)) { pageCount[allWords.get(word)]++; } else if (!word.isEmpty() && allWords.containsKey(word.substring(0, word.length() - 1))) { pageCount[allWords.get(word.substring(0, word.length() - 1))]++; } } pageWords.clear(); } } } else if (g.matcher(nextLine).matches()) { continue; } words.append(nextLine); words.append(" "); }

    Read the article

  • Adding dynamic data to a table

    - by user559780
    I've the following table in my application. I've a ajax request which will fetch the results to be shown in the table. How add these results to the table with out overridding the header every time? <table id="itemList"> <td>Name</td> <td>Price</td> <td>Quantity</td> <td>Total</td> </table> Then the ajax data is as shown below var items = [ { Name: "Apple", Price: "80", Quantity : "3", Total : "240" }, { Name: "Orance", Price: "50", Quantity : "4", Total : "200" }, { Name: "Banana", Price: "20", Quantity : "8", Total : "160" }, { Name: "Cherry", Price: "250", Quantity : "10", Total : "2500" } ]; Now I'm trying something like this but it is not working var rows = ""; $.each(items, function(){ rows += "<tr><td>" + this.Name + "</td><td>" + this.Price + "</td><td>" + this.Quantity + "</td><td>" + this.Total + "</td></tr>"; }); $( "#itemList" ).text('<tr><td>Name</td><td>Price</td><td>Quantity-</td><td>Total</td></tr>' + rows );

    Read the article

  • How to make a bootable USB drive out of a bootable DVD or CD

    - by Svish
    Is there a "universal" way of how you can make a bootable USB drive out of a bootable dvd or cd? What makes a USB drive bootable? What makes a dvd and cd bootable? For example there is a program called UNetBootin which can make bootable USB drives, but seems like it only works with various linux distributions. (Tried it with a Win7 image and the SystemRescueCD, which didn't work so well...). Main reason I ask is that I have a Support DVD which came with an Asus EEE, and it of course doesn't have an external dvd drive. So I am curious if I can sort of move that dvd over to a USB drive so that I can use it without buying one. Not asking just specifically about this one case though, I am curious to know a bit more about this in general. So, if you have a general bootable DVD or CD (Or a DVD or CD image for that matter), could be linux distro, windows install disk, support disks, etc., is it possible to "move" it over to a USB drive and make that work like the DVD or CD did? (Being bootable and all).

    Read the article

  • Have a set a cgi scripts shared by multiple domains

    - by rpat
    Goal: Have multiple domains share a set of cgi(perl) scripts Environment: Apache 2.0 on a dedicated Cent OS server. (Apache configuration files generated by cPanel) I have dozens of domains on the dedicated server. The domains set up by cPanel under VirtualHost section. I have almost no knowledge of Apache. Most of what I do is taken care of by cPanel. I would like to put a set of scripts under one directory (perhaps under / or /opt ) and for each of the domains, under the individual cgi-bin, I would like to create a symbolic link to this common directory. This way I am hoping to avoid having to keep a copy of scripts for every domain. Since Apache config files are generated by cPanel, I would not like to manually make changes to those. Beside, I could mess things up. I see that cPanel recommends use of include files rather than changing the httpd.conf Perhaps I need to have the following of symbolic links enabled in the cgi-bin directory and allow the web server user execute the scripts not owned by it. May be I am making things more complicated than they are. I would be glad to use any other means to achieve my goal. Thanks in advance for your help. *I asked this on stackoverflow and some one suggested that I could ask this on serverfault.

    Read the article

  • 64 bit vs 32 bit

    - by user53864
    When I was doing my course MCSA, I'm taught the following: With a 32-bit processor only 32-bit operating system can be installed. with a 64-bit processor both 32-bit & 64-bit operating system can be installed It's said 64-bit os cannot be installed on a 32-bit processor. I just want to make sure the above points because recently I'm asked to installed Windows Server 2008 R2 Enterprize and while installation it showed only x64 and it simply installed it. I was thinking all the computers in my office having a 32-bit processor. If so how it could be possible to install a x64 bit os on a 32-bit processor? or I'm wrong with the 1st point or the processor may be of 64-bit(I don't know how to check). I'm confused... One thing what I know the benefits of 64-bit over 32-bit is faster operation. If anyone could tell me other benefits, it could be helpful for me. Thanks!

    Read the article

  • Bittorrent surveillance/monitoring

    - by Flamewires
    Is there any tool to sniff bittorrent traffic and reassemble data about the torrent? Im looking for file names, peers, tracker address, local IP, etc. This is purely for academic interest in which all parties would be willing participants and therefore please dont upvote responses that talk merely about legal issues with using this kind of approach on a production network. I also am assuming that the torrent connections are unencrypted. Thanks

    Read the article

  • Iphone 3GS to laptop Syncing

    - by Chris
    I use my Iphone calender to store all my appointments and customer information etc rather than my Outlook calender on my laptop most of the time. To the best of my knowledge I have never lost any info before, but after syncing the two devices today my calender is now empty on both. I had thought that syncing would mean taking the information on both devices, amalgamating it and populating both devices with the same info? Two questions: a) Is there anyway of retrieving the lost information? (or am I sunk?) b) Is there any way of averting such disaster in the future? Whilst I suspect that "Read the manual - Idiot!" would be the correct response, any help really is greatly appreciated!

    Read the article

  • Batch edit (not rename) file properties in windows

    - by Jay
    I have a large directory of downloaded shareware. I keep track of what i have by individually editing the properties of each program. However, some of the programs are multipart .rar types. And i have at least a few hundred programs so far. I am looking for a utility that will let me batch edit file properties such as Title, Author, Summary, and Comments, so I don't have to edit each file or file part individually. Windows doesn't let me do this in Explorer. Powerdesk has a proprietary system, but it isn't preserved when moving or copying files. Any Suggestions?

    Read the article

  • Data validation best practices: how can I better construct user feedback?

    - by Cory Larson
    Data validation, whether it be domain object, form, or any other type of input validation, could theoretically be part of any development effort, no matter its size or complexity. I sometimes find myself writing informational or error messages that might seem harsh or demanding to unsuspecting users, and frankly I feel like there must be a better way to describe the validation problem to the user. I know that this topic is subjective and argumentative. StackOverflow might not be the proper channel for diving into this subject, but like I've mentioned, we all run into this at some point or another. There are so many StackExchange sites now; if there is a better one, feel free to share! Basically, I'm looking for good resources on data validation and user feedback that results from it at a theoretical level. Topics and questions I'm interested in are: Content Should I be describing what the user did correctly or incorrectly, or simply what was expected? How much detail can the user read before they get annoyed? (e.g. Is "Username cannot exceed 20 characters." enough, or should it be described more fully, such as "The username cannot be empty, and must be at least 6 characters but cannot exceed 30 characters."?) Grammar How do I decide between phrases like "must not," "may not," or "cannot"? Delivery This can depend on the project, but how should the information be delivered to the user? Should it be obtrusive (e.g. JavaScript alerts) or friendly? Should they be displayed prominently? Immediately (i.e. without confirmation steps, etc.)? Logging Do you bother logging validation errors? Internationalization Some cultures prefer or better understand directness over subtlety and vice-versa (e.g. "Don't do that!" vs. "Please check what you've done."). How do I cater to the majority of users? I may edit this list as I think more about the topic, but I'm genuinely interest in proper user feedback techniques. I'm looking for things like research results, poll results, etc. I've developed and refined my own techniques over the years that users seem to be okay with, but I work in an environment where the users prefer to adapt to what you give them over speaking up about things they don't like. I'm interested in hearing your experiences in addition to any resources to which you may be able to point me.

    Read the article

  • Aren't there compilers better at telling the programmer what's wrong in a code ?

    - by jokoon
    I have worked a little while with the Microsoft compiler from Visual C++ but I worked a long time with G++, and I remember often having bad times understanding what was wrong in my code with the former. Beside binary code generation and optimisation, I think this is a very important feature of a C++ compiler: giving the programmer a clue that makes him understand as fast as possible what is wrong with his/her code. I can understand some programmers understand programming as some sort of "competition" to make less errors, but to me that's a counter productive opinion. I once tried Clang compiler for C from the LLVM thingie, I didn't use it for a long time, but I was impressed on how explicit and easy to understand the error messages were. What are your experiences, and how do you think this matters ? Some WIP of C++ Clang: http://clang.llvm.org/cxx_status.html

    Read the article

  • How to login after modifying ~/.profile wrongly

    - by Jasper Loy
    I did something very silly a few weeks ago. I wanted to add a path so that the OS could find some manually installed executable. Instead of typing 'PATH=xxx:$PATH;export PATH' at the end of the ~/.profile file where xxx is the directory in which the executable lies, I accidentally typed 'PATH=xxx;export PATH'. After I logged out I was unable to login anymore as I probably messed up the whole PATH variable and reinstalled the whole thing. My question is: is there a way of rectifying the situation if I happen to add the path wrongly (hopefully not!) in future?

    Read the article

  • What can I change/investigate where the install does not complete?

    - by tunist
    I have already successfully installed Ubuntu 10.10 on my laptop and it works fine. I attempted to get my desktop PC to dual boot Windows and Ubuntu but found that neither the 32 or 64 bit install images will boot/install successfully. The startup script locks on 'initializing core #2' (or 1 or 3).. once I saw it say 'ok' at the end but it still locks there. I have tried to change the boot sequence by inserting 'debug' and 'acpi-off' into txt.cfg in both isolinux and syslinux folders but no changes were obvious during the boot.. as far as it got. The pc is built with an abit IP35 motherboard and nvidia 8600GT gfx card. Does anyone have any suggestion of what else I can change to get the install working?

    Read the article

  • System displays "File system maintenance error, press ctrl+d" while booting

    - by user3215
    In my office I've Ubuntu 8.10 desktop installed and it's running for a long time. When ever the system is started, I'll get a file system maintenance error and something it's prompted for the root password or (press ctrl+d to continue). After pressing Ctrl+D the system normally boots up. I could not resolve this issue for a long time and I think something should be done in the fstab file. I'm not sure to do anything and expecting the experts here to help to perfectly fix this. Any help is appreciated. Thanks!

    Read the article

  • Starting a guest session from the login screen

    - by Odd-rationale
    I was wondering what is the best way to start the guest session from the login screen (GDM). Currently, I created a new user called 'ubuntu-guest' (has to be something other than 'guest'). Then added the following script to the Startup Applications. #!/bin/bash /usr/share/gdm/guest-session/guest-session-launch & /usr/bin/gnome-session-save --logout The problem with this method, is that when you log in as 'ubuntu-guest', you have to start up two gnome sessions: one for 'ubuntu-guest' and one for the actual guest account. Please let me know if you have any other better ideas. Thanks!

    Read the article

  • How do i start Game programming in windows phone xna?

    - by Ankit Rathod
    Hello, I am very much interested in Game programming in Xna. However during my college days i did not take Physics or Maths. Does that mean i can't create games in xna? I just know basics of trignometry. Can you all point me to few links where i can learn xna as well as the basic stuff of Maths that is bound to be required in most of the games? Are all game programmers excellent in Maths and Physics ? Thanks in advance :)

    Read the article

  • Attempted to read or write protected memory

    - by Interfector
    I have a sample ASP.NET MVC 3 web application that is following Jonathan McCracken's Test-Drive Asp.NET MVC (great book , by the way) and I have stumbled upon a problem. Note that I'm using MVCContrib, Rhino and NUnit. [Test] public void ShouldSetLoggedInUserToViewBag() { var todoController = new TodoController(); var builder = new TestControllerBuilder(); builder.InitializeController(todoController); builder.HttpContext.User = new GenericPrincipal(new GenericIdentity("John Doe"), null); Assert.That(todoController.Index().AssertViewRendered().ViewData["UserName"], Is.EqualTo("John Doe")); } The code above always throws this error: System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt. The controller action code is the following: [HttpGet] public ActionResult Index() { ViewData.Model = Todo.ThingsToBeDone; ViewBag.UserName = HttpContext.User.Identity.Name; return View(); } From what I have figured out, the app seems to crash because of the two assignements in the controller action. However, I cannot see how there are wrong!? Can anyone help me pinpoint the solution to this problem. Thank you.

    Read the article

  • What is the best book in client server programming ?

    - by Nayef
    What is the best "new" book in client server programming with C#? I mean principles of inter-network architecture and communication protocols. Open systems and interoperability. Case studies of particular protocols from network layer and above. Socket programming. Remoting. Selected examples of networked client-server applications such as e-mail, news, file-transfer, HTTP. Client-Server Programming Project(s). Using APIs. Software tools and environments.

    Read the article

  • Help with active record relations

    - by Christian Fazzini
    class CreateActivities < ActiveRecord::Migration def self.up create_table :activities do |t| t.references :user t.references :media t.integer :artist_id t.string :type t.timestamps end end def self.down drop_table :activities end end class Fan < Activity belongs_to :user, :counter_cache => true end class Activity < ActiveRecord::Base belongs_to :user belongs_to :media belongs_to :artist, :class_name => 'User', :foreign_key => 'artist_id' end class User < ActiveRecord::Base has_many :activities has_many :fans end I tried changing my activity model too, without any success: class Activity < ActiveRecord::Base has_many :activities, :class_name => 'User', :foreign_key => 'user_id' has_many :activities, :class_name => 'User', :foreign_key => 'artist_id' end One thing to note. Activity is an STI. Fan inherits from Activity. In console, I do: # Create a fan object. User is a fan of himself fan = Fan.new => #<Fan id: nil, user_id: nil, media_id: nil, artist_id: nil, type: "Fan", comment: nil, created_at: nil, updated_at: nil> # Assign a user object fan.user = User.first => #<User id: 1, genre_id: 1, country_id: 1, .... # Assign an artist object fan.artist_id = User.first.id => 1 # Save the fan object fan.save! => true Activity.last => #<Fan id: 13, user_id: 1, media_id: nil, artist_id: 1, type: "Fan", comment: nil, created_at: "2010-12-30 08:41:25", updated_at: "2010-12-30 08:41:25"> Activity.last.user => #<User id: 1, genre_id: 1, country_id: 1, ..... But... Activity.last.artist => nil Why is Activity.last.artist returning nil?

    Read the article

  • Bluetooth in Java Mobile: Handling connections that go out of range

    - by Albus Dumbledore
    I am trying to implement a server-client connection over the spp. After initializing the server, I start a thread that first listens for clients and then receives data from them. It looks like that: public final void run() { while (alive) { try { /* * Await client connection */ System.out.println("Awaiting client connection..."); client = server.acceptAndOpen(); /* * Start receiving data */ int read; byte[] buffer = new byte[128]; DataInputStream receive = client.openDataInputStream(); try { while ((read = receive.read(buffer)) > 0) { System.out.println("[Recieved]: " + new String(buffer, 0, read)); if (!alive) { return; } } } finally { System.out.println("Closing connection..."); receive.close(); } } catch (IOException e){ e.printStackTrace(); } } } It's working fine for I am able to receive messages. What's troubling me is how would the thread eventually die when a device goes out of range? Firstly, the call to receive.read(buffer) blocks so that the thread waits until it receives any data. If the device goes out of range, it would never proceed onward to check if meanwhile it has been interrupted. Secondly, it would never close the connection, i.e. the server would not accept the device once it goes back in range. Thanks! Any ideas would be highly appreciated! Merry Christmas!

    Read the article

  • javascript keypress function: case-insensitive a-z, numbers and a few special chars?

    - by user239831
    hey guys, $('.s').keyup(function(e) { if (!/[A-Za-z0-9]/.test(String.fromCharCode(e.which))) { return false; } I wonder what is the best regex solution for my application. I have an ajax-based search that should just trigger the search when actual characters are pressed like a-Z (upper and lowercase), numbers and maybe a questionmark, a dash(hyphen), and an exclamation mark. Also the spacebar should be enabled. Otherwise the ajax search would be triggered as well if the shift-, option, or control-key, is pressed. What's the easiest regex pattern to understand here? thank you for your help

    Read the article

  • image loading information with jquery

    - by Pradyut Bhattacharya
    Hi I have a page which has a img holder with the html: - <img src="someimage.jpeg" alt="image" class="show_image"/> Now i m updating the image with jquery using the code... $('.show_image').attr('src', 'anotherimage.jpeg'); Now its working fine but i want to show the users the image is being loaded and may wait as the image size may be huge... Is there any method in jquery to get the information of percent loaded(bytes read/remaining) or if the image load is complete... Also how can i place a div over the image placeholder such that the div can fade the image(opacity:0.8) and add some text over the div as loading or something thanks

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >