Daily Archives

Articles indexed Sunday January 9 2011

Page 26/29 | < Previous Page | 22 23 24 25 26 27 28 29  | Next Page >

  • C# Regex.IsMatch returns true when it shouldn't?

    - by James Cadd
    I'm attempting to match a string that can contain any number of numeric characters or a decimal point using the following regex: ([0-9.])* Here's some C# code to test the regex: Regex regex = new Regex("([0-9.])*"); if (!regex.IsMatch("a")) throw new Exception("No match."); I expect the exception to be thrown here but it isn't - am I using the Regex incorrectly or is there an error in the pattern? EDIT: I'd also like to match a blank string.

    Read the article

  • Linux signals with extra information parameter

    - by Tester
    I was to have some extra information in the callback to sa_sigaction handler, it does not seems possible. So I was wondering if you could suggest me alternatives. Basic requirements: Function A raises an signal/event with a pointer to a struct Handler function tackles the event. The handler function would only be called on an event and a loop to wait for the event, as in select() , is undesirable. TIA

    Read the article

  • Should not a tail-recursive function also be faster?

    - by Balint Erdi
    I have the following Clojure code to calculate a number with a certain "factorable" property. (what exactly the code does is secondary). (defn factor-9 ([] (let [digits (take 9 (iterate #(inc %) 1)) nums (map (fn [x] ,(Integer. (apply str x))) (permutations digits))] (some (fn [x] (and (factor-9 x) x)) nums))) ([n] (or (= 1 (count (str n))) (and (divisible-by-length n) (factor-9 (quot n 10)))))) Now, I'm into TCO and realize that Clojure can only provide tail-recursion if explicitly told so using the recur keyword. So I've rewritten the code to do that (replacing factor-9 with recur being the only difference): (defn factor-9 ([] (let [digits (take 9 (iterate #(inc %) 1)) nums (map (fn [x] ,(Integer. (apply str x))) (permutations digits))] (some (fn [x] (and (factor-9 x) x)) nums))) ([n] (or (= 1 (count (str n))) (and (divisible-by-length n) (recur (quot n 10)))))) To my knowledge, TCO has a double benefit. The first one is that it does not use the stack as heavily as a non tail-recursive call and thus does not blow it on larger recursions. The second, I think is that consequently it's faster since it can be converted to a loop. Now, I've made a very rough benchmark and have not seen any difference between the two implementations although. Am I wrong in my second assumption or does this have something to do with running on the JVM (which does not have automatic TCO) and recur using a trick to achieve it? Thank you.

    Read the article

  • Developing Qt applications in Unix systems using Qt Creator

    - by Jake Petroules
    I'm developing a Qt application in Linux using Qt Creator (2.1 RC). I've created 2 projects, and used the wizard to add the library project to the application project. However when I run it, I receive the error: /home/jakepetroules/silverlock/silverlock-build-desktop/desktop/silverlock: error while loading shared libraries: libsilverlocklib.so.1: cannot open shared object file: No such file or directory Is there some qmake variable I can set so that Qt Creator will set up the environment properly to run? It's quite annoying to have to copy all the files to another directory with a launcher script just to be able to test the build. On Windows it works perfectly - Qt Creator automatically adds the directories containing the DLLs to the PATH when it runs your application (where running it from Explorer would say DLL not found). Mac OS X is even worse, having to run install_name_tool on everything... So how can I set up my qmake files so everything works right from the run button in Qt Creator? Kind of hard to debug without this ability, too.

    Read the article

  • two php arrays - sort one array with the value order of another

    - by Tisch
    Hi there, I have two PHP arrays like so: Array of X records containing the ID of Wordpress posts (in a particular order) Array of Wordpress posts The two arrays look something like this: Array One (Sorted Custom Array of Wordpress Post IDs) Array ( [0] => 54 [1] => 10 [2] => 4 ) Array Two (Wordpress Post Array) Array ( [0] => stdClass Object ( [ID] => 4 [post_author] => 1 ) [1] => stdClass Object ( [ID] => 54 [post_author] => 1 ) [2] => stdClass Object ( [ID] => 10 [post_author] => 1 ) ) I would like to sort the array of wordpress posts with the order of the ID's in the first array. I hope this makes sense, and thanks in advance of any help. Tom edit: The server is running PHP Version 5.2.14

    Read the article

  • How can I traverse a reverse generic relation in a Django template?

    - by user569139
    I have the following class that I am using to bookmark items: class BookmarkedItem(models.Model): is_bookmarked = models.BooleanField(default=False) user = models.ForeignKey(User) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() And I am defining a reverse generic relationship as follows: class Link(models.Model): url = models.URLField() bookmarks = generic.GenericRelation(BookmarkedItem) In one of my views I generate a queryset of all links and add this to a context: links = Link.objects.all() context = { 'links': links } return render_to_response('links.html', context) The problem I am having is how to traverse the generic relationship in my template. For each link I want to be able to check the is_bookmarked attribute and change the add/remove bookmark button according to whether the user already has it bookmarked or not. Is this possible to do in the template? Or do I have to do some additional filtering in the view and pass another queryset?

    Read the article

  • Python client / server question

    - by AustinM
    I'm working on a bit of a project in python. I have a client and a server. The server listens for connections and once a connection is received it waits for input from the client. The idea is that the client can connect to the server and execute system commands such as ls and cat. This is my server code: import sys, os, socket host = '' port = 50105 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) print("Server started on port: ", port) s.listen(5) print("Server listening\n") conn, addr = s.accept() print 'New connection from ', addr while (1): rc = conn.recv(5) pipe = os.popen(rc) rl = pipe.readlines() file = conn.makefile('w', 0) file.writelines(rl[:-1]) file.close() conn.close() And this is my client code: import sys, socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host = 'localhost' port = input('Port: ') s.connect((host, port)) cmd = raw_input('$ ') s.send(cmd) file = s.makefile('r', 0) sys.stdout.writelines(file.readlines()) When I start the server I get the right output, saying the server is listening. But when I connect with my client and type a command the server exits with this error: Traceback (most recent call last): File "server.py", line 21, in <module> rc = conn.recv(2) File "/usr/lib/python2.6/socket.py", line 165, in _dummy raise error(EBADF, 'Bad file descriptor') socket.error: [Errno 9] Bad file descriptor On the client side, I get the output of ls but the server gets screwed up.

    Read the article

  • WPF Textbox "normal" text input

    - by Ash Rowe
    G'day, I'm not sure if this is a problem relevant to only me or if anyone else has this issue also. None the less, I'll try and describe what is going on here. I have a few textbox's, default style, etc. I set an explicit maxwidth and maxheight to prevent resize when the text exceeds the default width of the textbox. The issue is that the text wraps to the next line, but I only want single line. So I set maxlines to 1 and textwrapping to NoWrap. That's fine. Now the carat and typed text disappears under the edges of the textbox when the width is exceeded and the only way I can get the carat and newly typed text back into view is by pressing the left and right arrows. Coming from MFC and using textboxes all the time with HTML, I would have thought the default behaviour would be to have the textbox content scroll with the carat or am I missing something here? Thank you, Ash

    Read the article

  • translating ROI code in c#

    - by sayyad
    Hi, I am trying to translate this code in c# using emgucv. I have some questions.Could yome body help me line by line. cvSetImageROI(img1, cvRect(10, 15, 150, 250)); I have four points (PoinstF). Should I calculate rectangle or there is some way with four points. CvInvoke.cvSetImageROI(img1, ------------(how can I declare cvReCt(10, 15, 150, 250)); //c# IplImage *img2 = cvCreateImage(cvGetSize(img1), img1-depth, img1-nChannels); //c# Image img2; // i supose i needn't to allocate memory.//c# cvCopy(img1, img2, NULL); CvInvoke.cvCopy(img1, img2, IntPtr.Zero);//c# cvResetImageROI(img1); shoul i ResetImageROI.//c# thanx and best regards,

    Read the article

  • UIWebView: webViewDidStartLoad/webViewDidFinishLoad delegate methods not called when loading certain URLs

    - by Dia
    I have basic web browser implemented using a UIWebView. I've noticed that for some pages, none of the UIWebViewDelegate methods are called. An example page in which this happens is: http://www.youtube.com/user/google. Here are the steps to reproduce the issue (make sure you insert NSLog calls in your controller's UIWebViewDelegate methods): Load the above youtube URL into the UIWebView [notice that here, the UIWebViewDelegate methods do get called when the page loads] Touch the "Uploads" category on the page Touch any video in that category [issue: notice that a new page is loaded, but none of the UIWebView delegates are called] I know that this is not an issue of UIWebView's delegate not being set properly, since the delegate methods do get invoked when loading other links (e.g. if you try clicking on a link that takes you outside of youtube, you'll notice the delegate methods getting called). My gut feeling initially was that it might be because the page is loaded using AJAX, which may not invoke the delegate method. But then when I checked Safari, it did not exhibit this problem, so it must be something on my side. I've also noticed that Three20's TTWebController has the exact same issue as I'm having. But the problem that arises from this issue is that without the delegate methods called, I'm unable to update the UI to enable/disable the back and forward browsing buttons when new requests are loaded. And idea why this is happening or how can I work around it to update the UI when a new request is made?

    Read the article

  • Trouble making login page?

    - by Ken
    Okay, so I want to make a simple login page. I've created a register page successfully, but i can't get the login thing down. login.php: <?php session_start(); include("mainmenu.php"); $usrname = mysql_real_escape_string($_POST['usrname']); $password = md5($_POST['password']); $con = mysql_connect("localhost", "root", "g00dfor@boy"); if(!$con){ die(mysql_error()); } mysql_select_db("users", $con) or die(mysql_error()); $login = "SELECT * FROM `users` WHERE (usrname = '$usrname' AND password = '$password')"; $result = mysql_query($login); if(mysql_num_rows($result) == 1 { $_SESSION = true; header('Location: indexlogin.php'); } else { echo = "Wrong username or password." ; } ?> indexlogin.php just echoes "Login successful." What am I doing wrong? Oh, and just FYI- my database is "users" and my table is "data".

    Read the article

  • C# - Dictionary with generic array as value

    - by alhazen
    In my class, I want to use a dictionary with the following declaration: Dictionary<string, T[]> Since the operations of my class are exactly the same for all generic types, I do not wish to define my class as generic (which means I would have to create a separate instance of my class for each generic type I insert into the dictionary ?). One alternative I'm attempting is to use Dictionary<string, object> instead: public void Add<T>(string str, T value) { // Assuming key already exists var array = (T[]) dictionary[str]; array[0] = value; } However, when iterating over the dictionary, how do I cast the object value back to an array ? foreach(string strKey in dictionary.Keys) { var array = (T[]) dictionary[strKey]; // How to cast here ? //... array[0] = default(T); } Thanks.

    Read the article

  • Mercurial commit only tip

    - by kiw
    In my setup I have a central Hg repo to which I'm pushing my local changes. Say in my local clone I have a series of local commits and then I want to push the changes to the central repo. How can I push only the final state without including all of the "small" local commits that I made? I want this because sometimes I dont want to pollute the central repo's history with all of the small local commits that I made.

    Read the article

  • Resource File Links

    - by EzaBlade
    When you create a Silverlight Business Application you get a Silverlight application and a Web application. In the Web/Resources folder of the Silverlight app there are links to the files in the Resources folder of the Web app. These links are exactly like the files they link to in that they are heirarchical with the Resource.Designer.cs file shown as a code-behind file for the Resource.resx file When I try to link to a Resource file in this way I only get the .resx file unless I link to the .Designer.cs file separately. However in this case the Designer.cs file is then shown as a standard code file and not related to the .resx file. Does anyone know how to do this linking correctly?

    Read the article

  • java template design

    - by Sean Nguyen
    Hi, I have this class: public class Converter { private Logger logger = Logger.getLogger(Converter.class); public String convert(String s){ if (s == null) throw new IllegalArgumentException("input can't be null"); logger.debug("Input = " + s); String r = s + "abc"; logger.debug("Output = " + s); return r; } public Integer convert(Integer s){ if (s == null) throw new IllegalArgumentException("input can't be null"); logger.debug("Input = " + s); Integer r = s + 10; logger.debug("Output = " + s); return r; } } The above 2 methods are very similar so I want to create a template to do the similar things and delegate the actual work to the approriate class. But I also want to easily extends this frame work without changing the template. So for example: public class ConverterTemplate { private Logger logger = Logger.getLogger(Converter.class); public Object convert(Object s){ if (s == null) throw new IllegalArgumentException("input can't be null"); logger.debug("Input = " + s); Object r = doConverter(); logger.debug("Output = " + s); return r; } protected abstract Object doConverter(Object arg); } public class MyConverter extends ConverterTemplate { protected String doConverter(String str) { String r = str + "abc"; return r; } protected Integer doConverter(Integer arg) { Integer r = arg + 10; return r; } } But that doesn't work. Can anybody suggest me a better way to do that? I want to achieve 2 goals: 1. A template that is extensible and does all the similar work for me. 2. I ant to minimize the number of extended class. Thanks,

    Read the article

  • Automatically registering "commands" for a command line program in python

    - by seandavi
    I would like to develop a command-line program that can process and give "help" for subcommands. To be concrete, say I have a single script called "cgent" and I would like to have subcommands "abc", "def", and "xyz" execute and accept the rest of the sys.args for processing by optparse. cgent abc [options] cgent help abc .... All of this is straightforward if I hard-code the subcommand names. However, I would like to be able to continue to add subcommands by adding a class or module (?). This is similar to the idea that is used by web frameworks for adding controllers, for example. I have tried digging through pylons to see if I can recreate what is done there, but I have not unravelled the logic. Any suggestions on how to do this? Thanks, Sean

    Read the article

  • Algorithm Question

    - by Ravi
    Hi, I am trying to find a O (n) algorithm for this problem but unable to do so even after spending 3 - 4 hours. The brute force method times out (O (n^2)). I am confused as to how to do it ? Does the solution requires dynamic programming solution ? http://acm.timus.ru/problem.aspx?space=1&num=1794 In short the problem is this: There are some students sitting in circle and each one of them has its own choice as to when he wants to be asked a question from a teacher. The teacher will ask the questions in clockwise order only. For example: 5 3 3 1 5 5 This means that there are 5 students and : 1st student wants to go third 2nd student wants to go third 3rd student wants to go first 4th student wants to go fifth 5th student wants to go fifth. The question is as to where should teacher start asking questions so that maximum number of students will get the turn as they want. For this particular example, the answer is 5 because 3 3 1 5 5 2 3 4 5 1 You can see that by starting at fifth student as 1st, 2 students (3 and 5) are getting the choices as they wanted. For this example the answer is 12th student : 12 5 1 2 3 6 3 8 4 10 3 12 7 because 5 1 2 3 6 3 8 4 10 3 12 7 2 3 4 5 6 7 8 9 10 11 12 1 four students get their choices fulfilled. Thanks Ravi

    Read the article

  • Jquery Accordion and multiple slideshows

    - by Dipesh Parmar
    I've been using a lot of slideshows recently on my sites and one thing thats puzzled me is using more than one slideshow per page. I'm currently working on my own site, experimenting with Jquery Accordion. I've managed to adopt a very simple javascript slideshow, see below: http://dvpwebdesign.com/test/accordion/blank.html However i'm unable to either incorporate or use a different multiple slideshow plugin. I dont need slideshow navigation, so the The Cycle plugin works really well and i know you can use multiple slideshows. But if i either use Cycle alongside the current javascript slideshow, or only use the Cycle slideshow to avoid any possible conflict, the Accordion menu stops working. I just cant see what i am doing wrong, can anyone help?

    Read the article

  • jquery datepicker and aspx TextBox visible problem

    - by senzacionale
    $(".inputTypeDate").datepicker({ dateFormat: "dd.mm.yy", changeMonth: true, changeYear: true }); <asp:TextBox ID="txtBirthday" runat="server" CssClass="inputTypeDate" Visible="false" ValidationGroup="urgent"></asp:TextBox> in aspx we have some component set to Visible="false" then we change visibility to true. But jquery datepicker calendar does not work in this component. If Visible="true" by default then works. Why and how to fix that. I think that problem is in changing visibility.

    Read the article

  • Apache Lucene: Is Relevance Score Always Between 0 and 1?

    - by Eamorr
    Greetings, I have the following Apache Lucene snippet that's giving me some nice results: int numHits=100; int resultsPerPage=100; IndexSearcher searcher=new IndexSearcher(reader); TopScoreDocCollector collector=TopScoreDocCollector.create(numHits,true); Query q=parser.parse(queryString); searcher.search(q,collector); ScoreDoc[] hits=collector.topDocs(0*resultsPerPage,resultsPerPage).scoreDocs; Results r=new Results(); r.length=hits.length; for(int i=0;i<hits.length;i++){ Document doc=searcher.doc(hits[i].doc); double distanceKm=getGreatCircleDistance(lucene2double(doc.get("lat")), lucene2double(doc.get("lng")), Double.parseDouble(userLat), Double.parseDouble(userLng)); double newRelevance=((1/distanceKm)*Math.log(hits[i].score)/Math.log(2))*(0-1); System.out.println(hits[i].doc+"\t"+hits[i].score+"\t"+doc.get("content")+"\t"+"Km="+distanceKm+"\trlvnc="+String.valueOf(newRelevance)); } What I want to know, is hits[i].score always between 0 and 1? It seems that way, but I can't be sure. I've even checked the Lucene documentation (class ScoreDocs) to no avail. You'll see I'm calculating the log of the "newRelevance" value, which is based on hits[i].score. I need hits[i].score to be between 0 and 1, because if it is below zero, I'll get an error; above 1 and the sign will change from negative to positive. I hope some Lucene expert out there can offer me some insight. Many thanks,

    Read the article

  • What kind of hosting is used for *tube sites?

    - by playcat
    Hello, I'm not sure if this is the right place for this question, and will be happy to remove the Q if needed. When a site grows from a just-a-fun project to a site with bigger load of visitor, and you want to enable them to upload videos, you might find yourself in a need of a better hosting, including dedicated server and a no-limit web traffic (or some reasonable limit). So, if people can upload their videos, and if page has around 1000-10000 visitors per day, what kind of hosting is there to choose from? What is needed in that case? Thx

    Read the article

  • How do I know if my disks are being hit with too much IO reads or writes or both?

    - by Mark F
    Hi All, So I know a bit about disk I/O and bottlenecks relating to this especially when relating to databases. But how do I really know what the max IO numbers will be for my disks? What metric might be available to me for working out roughly (but needs to be a good approximation) of how much capacity (if you will) have I got left available in I/O. I've seen it before where things are bubbling along nicely and then all of a sudden, everything screams to a halt, and it ends up being an IO bound problem. Is there a better way to predict when IO is reaching its limits? This article was interesting but not giving the answer I desire. "http://serverfault.com/questions/61510/linux-how-can-i-see-whats-waiting-for-disk-io". So is my best bet surrounding just looking at 'CPU IO WAIT'? There must be a more reactive method for this? Best, M

    Read the article

  • Automatically copy files out of directory

    - by wizard
    I had a user's laptop stolen recently during shipping and it was setup with windows live sync. The thief or buyer's kids took some photos of themselves and they were synced to the user's my documents. I had just finished moving the users files out of the synced my documents folder when I noticed this. Later they took some more photos and a video. I wrote up a batch script to copy files out synced directory every 5 minutes into a dated directory. In the end I ended up with a lot of copies of the same few files. Ignoring what windows livesync offers (at the time there was no way to undelete files - I've moved onto dropbox so this ins't really an issue for me) what's the best way to preserve changes and files from a directory? I'm interested in windows solutions but if you know of a good way on a *nix please go ahead and share.

    Read the article

  • /var/run/utmp is getting large and slowing my server down

    - by Travis
    I removed it and touched an empty verison a few weeks ago and noticed a big upswing in performance for my server. The file was 400+ MB. I've been keeping an eye on it since and I'm noticing it is growing fairly quickly. I tailed the file and I'm seeing a lot of "TTYXXLOGIN" entries. Should I be concerned? Is there a way to minimize it's logging? Should I logrotate it and forget about it? Thanks in advance.

    Read the article

  • Why do people tell me not to use VLANs for security?

    - by jtnire
    Hi Everyone, As per title, why do people tell me not to use VLANs for security purposes? I have a network, where a have a couple of VLANS. There is a firewall between the 2 VLANs. I am using HP Procurve switches and have made sure that switch-to-switch links accept tagged frames only and that host ports don't accept tagged frames (They are not "VLAN Aware"). I've also made sure that the native VLAN (PVID) of the trunk links are not the same as either of the 2 host VLANs. I've also enabled "Ingress Filtering". Furthermore, I've made sure that host ports are only members of a single VLAN, which is the same as the PVID of the respective port. The only ports which are members of multiple VLANs are the trunk ports. Can someone please explain to me why the above isn't secure? I believe I've addressed the double tagging issue.. Thanks

    Read the article

< Previous Page | 22 23 24 25 26 27 28 29  | Next Page >