Search Results

Search found 6715 results on 269 pages for 'preg match'.

Page 178/269 | < Previous Page | 174 175 176 177 178 179 180 181 182 183 184 185  | Next Page >

  • (newbie) type signature "Maybe a" doesn't like "Just [Event]"

    - by sisif
    i'm still learning Haskell and need help with the type inference please! using packages SDL and Yampa i get the following type signature from FRP.Yampa.reactimate: (Bool -> IO (DTime, Maybe a)) and i want to use it for: myInput :: Bool -> IO (DTime, Maybe [SDL.Event]) myInput isBlocking = do event <- SDL.pollEvent return (1, Just [event]) ... reactimate myInit myInput myOutput mySF but it says Couldn't match expected type `()' against inferred type `[SDL.Event]' Expected type: IO (DTime, Maybe ()) Inferred type: IO (DTime, Maybe [SDL.Event]) In the second argument of `reactimate', namely `input' In the expression: reactimate initialize input output process i thought "Maybe a" allows me to use anything, even a SDL.Event list? why is it expecting "Maybe ()" when the type signature is actually "Maybe a"? why does it want an empty tuple, or a function taking no arguments, or what is () supposed to be?

    Read the article

  • Regular Expression to capture the first <p> of HTML

    - by Program.X
    I have the following regular expression: (?:<(?<tag>\w*)>(?<text>.*)</\k<tag>>) I want it t grab the text within the first HTML element. eg. <p>This should capture</p>This shouldn't Works, but ... <p>This should capture</p><p>This shouldn't</p> Doesn't work. As you'd expect, it returns: This should capture</p><p>This shouldn't I'm racking my brains here. How can I just have it select the FIRST inner text? (I'm trying to be tag-agnostic, so <strong>This should match</strong> is equally appropriate, etc.)

    Read the article

  • Select rows where column LIKE dictionary word

    - by Gerve
    I have 2 tables: Dictionary - Contains roughly 36,000 words CREATE TABLE IF NOT EXISTS `dictionary` ( `word` varchar(255) NOT NULL, PRIMARY KEY (`word`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; Datas - Contains roughly 100,000 rows CREATE TABLE IF NOT EXISTS `datas` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `hash` varchar(32) NOT NULL, `data` varchar(255) NOT NULL, `length` int(11) NOT NULL, `time` int(11) NOT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `hash` (`hash`), KEY `data` (`data`), KEY `length` (`length`), KEY `time` (`time`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=105316 ; I would like to somehow select all the rows from datas where the column data contains 1 or more words. I understand this is a big ask, it would need to match all of these rows together in every combination possible, so it needs the best optimization. I have tried the below query, but it just hangs for ages: SELECT `datas`.*, `dictionary`.`word` FROM `datas`, `dictionary` WHERE `datas`.`data` LIKE CONCAT('%', `dictionary`.`word`, '%') AND LENGTH(`dictionary`.`word`) > 3 ORDER BY `length` ASC LIMIT 15 I have also tried something similar to the above with a left join, and on clause that specified the like statement.

    Read the article

  • String.split() - matching leading empty String prior to first delimiter?

    - by tehblanx
    I need to be able to split an input String by commas, semi-colons or white-space (or a mix of the three). I would also like to treat multiple consecutive delimiters in the input as a single delimiter. Here's what I have so far: String regex = "[,;\\s]+"; return input.split(regex); This works, except for when the input string starts with one of the delimiter characters, in which case the first element of the result array is an empty String. I do not want my result to have empty Strings, so that something like, ",,,,ZERO; , ;;ONE ,TWO;," returns just a three element array containing the capitalized Strings. Is there a better way to do this than stripping out any leading characters that match my reg-ex prior to invoking String.split? Thanks in advance!

    Read the article

  • Always get the correct datetime?

    - by Jesper Mansa
    I was wandering if there is a way/site/link whith the correct time? Not the servers datetime or the clients datetime. I'm using datetime to count down on my gaming site for when it is the users time to make a play. Users come from all ower the world so using the users client time would not match if its from the US to Europe. Then normally I would use the servers time, but somehow it skips 1.2 hours sometimes? I would like to make sure that everbody makes a timestamp from the same source and that source always is correct! Hoping for help and thanks in advance.

    Read the article

  • XSLT Exclude Specific Tags

    - by MMKD
    I have a problem i am trying to resolve in an XSLT but i an unable to find a solution. The example below is related to a payment system it is adding items to a basket then removing them. The out XML provides a audit trail of actions conducted on a basket. Senario: Add Item (Id 1) Add Item (Id 1) With a price change Void Item (Id 1) Void Item (Id 1) With a price change Add Item (Id 1) Add Item (Id 1) Expected Outcome Remove: Add Item (Id 1) Add Item (Id 1) With a price change Output XML Contains Void Item (Id 1) Void Item (Id 1) With a price change Add Item (Id 1) Add Item (Id 1) Input XML: <xml> <product void="false"> <sequence_number>1</sequence_number> <item_id>11111111</item_id> <price>12</price> </product> <product void="false"> <sequence_number>2</sequence_number> <item_id>11111111</item_id> <price>12</price> <price_change> <price>10</price> </price_change> </product> <product void="true"> <sequence_number>3</sequence_number> <item_id>11111111</item_id> <price>12</price> <price_change> <price>10</price> </price_change> </product> <product void="true"> <sequence_number>4</sequence_number> <item_id>11111111</item_id> <price>12</price> </product> <product void="false"> <sequence_number>5</sequence_number> <item_id>11111111</item_id> <price>12</price> </product> <product void="false"> <sequence_number>6</sequence_number> <item_id>11111111</item_id> <price>12</price> </product> </xml> Expected outcome: <xml> <product void="true"> <sequence_number>3</sequence_number> <item_id>11111111</item_id> <price>12</price> <price_change> <price>10</price> </price_change> </product> <product void="true"> <sequence_number>4</sequence_number> <item_id>11111111</item_id> <price>12</price> </product> <product void="false"> <sequence_number>5</sequence_number> <item_id>11111111</item_id> <price>12</price> </product> <product void="false"> <sequence_number>6</sequence_number> <item_id>11111111</item_id> <price>12</price> </product> </xml> XSLT <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="//product[@void='false']"> <xsl:if test="item_id != //product[@void='true']/item_id"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:if> </xsl:template> </xsl:stylesheet> The problem with this is that it is deleting all products that are not voided and have the same id and not taking into account the number of void items vs the number of none void items. If you have 1 void item it should only delete one product that is not voided but has exactly the same tags as itself

    Read the article

  • Jump to next page with qt_writeobject (embeded quicktime)

    - by Trikks
    Hi Im trying to script a website that will play a video, and when the video is done it should redirect to another page. However the instructions on apples website wont match. Any tips? Here is some of the code. <script language="JavaScript" type="text/javascript"> QT_WriteOBJECT('<?php echo $play_me; ?>','<?php echo $moduleWidth ?>','<?php echo $moduleHeight ?>','', 'enablejavascript','true', 'controller','false', 'bgcolor','000000', 'autoplay','true', 'cache','true', 'scale','tofit', 'qtnext1','<www.example.com> T<myself>' ); //'qtnext1','GOTO0' </script> Ideal would be if the link could be created with javascript, ie parent.location='www.example.com'; Thanks

    Read the article

  • Username correct, password incorrect?

    - by jonnnnnnnnnie
    In a login system, how can you tell if the user has entered the password incorrectly? Do you perform two SQL queries, one to find the username, and then one to find the username and matching (salted+hashed etc) password? I'm asking this because If the user entered the password incorrectly, I want to update the failed_login_attempts column I have. If you perform two queries wouldn't that increase overhead? If you did a query like this, how would you tell if the password entered was correct or not, or whether the username doesn't exist: SELECT * FROM author WHERE username = '$username' AND password = '$password' LIMIT 1 ( ^ NB: I'm keeping it simple, will use hash and salt, and will sanitize input in real one.) Something like this: $user = perform_Query() // get username and password? if ($user['username'] == $username && $user['password'] == $password) { return $user; } elseif($user['username'] == $username && $user['password'] !== $password) { // here the password doesn't match // update failed_login_attemps += 1 }

    Read the article

  • Cross vertion line matching.

    - by BCS
    I'm considering how to do automatic bug tracking and as part of that I'm wondering what is available to match source code line numbers (or more accurate numbers mapped from instruction pointers via something like addr2line) in one version of a program to the same line in another. (Assume everything is in some kind of source control and is available to my code) The simplest approach would be to use a diff tool/lib on the files and do some math on the line number spans, however this has some limitations: It doesn't handle cross file motion. It might not play well with lines that get changed It doesn't look at the information available in the intermediate versions. It provides no way to manually patch up lines when the diff tool gets things wrong. It's kinda clunky Before I start diving into developing something better: What already exists to do this? What features do similar system have that I've not thought of?

    Read the article

  • Adding anchors to h2 in text using python and regexp

    - by Oli
    I'm trying to add anchors to all h2's in my html, using python. This code will add those anchors, but I need to fill the name of the anchors too. Any idea if the name can be the number of the match in the loop or a slugified version of the text between the h2 tags? Here's the code so far: regex = '(?P<name><h2>.*?</h2>)' text = re.sub(regex, "<a name=''/>"+r"\g<name>", text)

    Read the article

  • Can somebody explain the difference between exceptions and errors (specific to PHP)?

    - by letseatfood
    I am having trouble figuring the best way to display errors to my clients. Should I use exceptions or errors? For example, if the user's login information does not match the database, should I throw new Exception('Login information is incorrect. Please try again.') and catch it with an exception handler using set_exception_handler()? Or, should I use trigger_error() to display an error message to the user? I think the main issue is that I cannot differentiate between errors and exceptions. I have read a lot of "answers" to this question on the internet and in some books, but it seems that people are really divided or aren't sure. Thanks!

    Read the article

  • dealing with IO vs pure code in haskell

    - by Drakosha
    I'm writing a shell script (my 1st non-example in haskell) which is supposed to list a directory, get every file size, do some string manipulation (pure code) and then rename some files. I'm not sure what i'm doing wrong, so 2 questions: How should i arrange the code in such program? I have a specific issue, i get the following error, what am i doing wrong? error: Couldn't match expected type [FilePath]' against inferred typeIO [FilePath]' In the second argument of mapM', namelyfileNames' In a stmt of a 'do' expression: files <- (mapM getFileNameAndSize fileNames) In the expression: do { fileNames <- getDirectoryContents; files <- (mapM getFileNameAndSize fileNames); sortBy cmpFilesBySize files } code: getFileNameAndSize fname = do (fname, (withFile fname ReadMode hFileSize)) getFilesWithSizes = do fileNames <- getDirectoryContents files <- (mapM getFileNameAndSize fileNames) sortBy cmpFilesBySize files

    Read the article

  • Perl: Greedy nature refuses to work

    - by faezshingeri
    I am trying to replace a string with another string, but the greedy nature doesn't seem to be working for me. Below is my code where "PERFORM GET-APLCY" is identified and replaced properly, but string "PERFORM GET-APLCY-SOI-CVG-WVR" and many other such strings are being replaced by the the replacement string for "PERFORM GET-APLCY". s/PERFORM $func[$i]\.?/# PERFORM $func[$i]\.\n $hash{$func[$i]}/g; where the full stop is optional during string match and replacement. Please help me understand what the issue could be. Thanks in advance, Faez

    Read the article

  • in_array() - help on what specifically would return true

    - by Kerri
    I am using in_array, and I'm trying to use it in a way where it will only return true if it's an exact match of one of the objects in the array, not just if it's "in" the array. e.g. 1. $sample_array = array('123', '234', '345'); 2. $sample_array = array('23', '34', '45'); in_array('23', $sample_array); In the above example, I would only want version 2 to return true, because it has the exact string, '23'. Version 1 returns true as well though, because the array contains instances of the string '23'. How would I get this to work so that only version 2 returns true? Am I even using the right function?

    Read the article

  • C++ enforce conditions on inherited classes

    - by user231536
    I would like to define an abstract base class X and enforce the following: a) every concrete class Y that inherits from X define a constructor Y(int x) b) it should be possible to test whether two Y objects are equal. For a, one not very good solution is to put a pure virtual fromInt method in X which concrete class will have to define. But I cannot enforce construction. For b), I cannot seem to use a pure virtual method in X bool operator == (const X& other) const =0; because in overridden classes this remains undefined. It is not enough to define bool operator == (const Y& other) const { //stuff} because the types don't match. How do I solve these problems?

    Read the article

  • c++ Sorting a vector based on values of other vector, or what's faster?

    - by pollux
    Hi, There are a couple of other posts about sorting a vector A based on values in another vector B. Most of the other answers tell to create a struct or a class to combine the values into one object and use std::sort. Though I'm curious about the performance of such solutions as I need to optimize code which implements bubble sort to sort these two vectors. I'm thinking to use a vector<pair<int,int>> and sort that. I'm working on a blob-tracking application (image analysis) where I try to match previously tracked blobs against newly detected blobs in video frames where I check each of the frames against a couple of previously tracked frames and of course the blobs I found in previous frames. I'm doing this at 60 times per second (speed of my webcam). Any advice on optimizing this is appreciated. The code I'm trying to optimize can be shown here: http://code.google.com/p/projectknave/source/browse/trunk/knaveAddons/ofxBlobTracker/ofCvBlobTracker.cpp?spec=svn313&r=313 Thanks

    Read the article

  • Python - alternative to list.remove(x)?

    - by Seafoid
    Hi, I wish to compare two lists. Generally this is not a problem as I usually use a nested for loop and append the intersection to a new list. In this case, I need to delete the intersection of A and B from A. A = [['ab', 'cd', 'ef', '0', '567'], ['ghy5'], ['pop', 'eye']] B = [['ab'], ['hi'], ['op'], ['ej']] My objective is to compare A and B and delete A intersection B from A, i.e., delete A[0][0] in this case. I tried: def match(): for i in A: for j in i: for k in B: for v in k: if j == v: A.remove(j) list.remove(x) throws a ValueError.

    Read the article

  • Regex whitespace and special characters

    - by Sam R.
    I have this regular expression: [^\\s\"']+|\"([^\"]*)\"|'([^']*)' which works for splitting a string by white spaces, and anything within a quotation is not delimited. However, I notice that if I put in a string that starts with "" no matches are found. How would I correct this? For example, if I enter " test 2". I want it to match to [, test, 2] Note: using java to compile the regex, here is some code Pattern pattern = Pattern.compile("[^\\s\"']+|\"([^\"]*)\"|'([^']*)'"); Matcher matcher = pattern.matcher(SomeString); while (matcher.find()){ String temp = matcher.group(); //... Do something ... } Thanks.

    Read the article

  • regular expression for validation not working

    - by Camran
    I have a "description textarea" inside a form where user may enter a description for an item. This is validated with javascript before the form beeing submitted. One of the validation-steps is this: else if (!fld.value.match(desExp)){ And desExp: var desExp = /^\s*(\w[^\w]*){3}.*$/gm; Now my problem, this works fine on all cases except for descriptions where the description BEGINS with a special character of the swedish language (å, ä, ö). This wont work: åäö hello world But this will: hello world åäö Any fixes? Thanks

    Read the article

  • haskell. words into binary numbers

    - by Katja
    I need to convert words into binary numbers. With a bit help of yours I got this blCo::String -> Integer blCo x = num2bin(lett2num x) blCo (x:xs) | x:xs = num2bin(lett2num x):blCo xs num2lett :: Int -> Char num2lett n | (n <= ord 'A') && (n <= ord 'Z') = chr(ord 'A'+ n - 1) | (n <= ord 'a') && (n <= ord 'Z') = chr(ord 'A'+ n - 1) num2bin :: Integer -> String num2bin n | n >= 0 = concatMap show (reverse ( n2b n)) | otherwise = error "num2bin: negative number" where n2b 0 = [] n2b n = n `mod` 2 : n2b (n `div` 2) he tells me a mistake.I dont undertsand it mistake: Couldn't match expected type `Char' against inferred type `String' In the first argument of `lett2num', namely `x' In the first argument of `num2bin', namely `(lett2num x)' In the expression: num2bin (lett2num x)

    Read the article

  • What happens if an asynchronous delegate call never returns?

    - by RichardHowells
    I found a decent looking example of how to call a delegate asynchronously with a timeout... http://www.eggheadcafe.com/tutorials/aspnet/847c94bf-4b8d-4a66-9ae5-5b61f049019f/basics-make-any-method-c.aspx. In summary it uses WaitOne with a timeout to determine if the call does not return before the timeout expires. I also know that you should have an EndInvoke to match each BeginInvoke. So what happens if the wait timeout expires? We (presumably) DON'T want to call EndInvoke as that will block. The code can go on to do 'other things', but have we leaked anything? Is there some poor thread someplace blocked waiting for a return that's never going to happen? Have we leaked some memory where the result-that-will-never-return was going to be placed?

    Read the article

  • regular expression

    - by Altariste
    Hi, I need to find all invocations of some logging macros in the code. The macro invocation is of the form: DEBUG[1-5] ( "methodName: the logged message", arguments) But the new versions of the macros are prepending the name of the method automatically, so my task is to write a Python script that will remove the duplicate function names specified already by the programmer. I'm using the sub function from the re module. I plan to substitute the part indicated by || signs below : ||DEBUG[1-5] ("methodName: || the logged message", arguments) with simply DEBUG[1-5](" The problem is following: To find the expressions I want to substitute, I use the following regular expression: ((DEBUG | INFO | all other macros names )[1-5]*)\s*\(\"\w+: But it doesn't match the whole expression ( from DEBUG right to the colon ), but only the macro name, that is for example DEBUG5. Is my expression wrong or there is some quirk in the Python regex processing? ( maybe the fact that I use the DEBUG[1-5] as a subgroup has something to do with this? ) Help from anyone more knowledgable than me appreciated :).

    Read the article

  • How can I receive percent encoded slashes with Django on App Engine?

    - by J. Frankenstein
    I'm using Django with Google's App Engine. I want to send information to the server with percent encoded slashes. A request like http:/localhost/turtle/waxy%2Fsmooth that would match against a URL like r'^/turtle/(?P<type>([A-Za-z]|%2F)+)$'. The request gets to the server intact, but sometime before it is compared against the regex the %2F is converted into a forward slash. What can I do to stop the %2Fs from being converted into forward slashes? Thanks!

    Read the article

  • Merge object from list by comparing one value

    - by Bala
    I have two List of Objects (one is master list and other is error list) and if there is a match of one value when compared two lists then merge all other error list values into mast list value (only one object). Other than iterating is there any other way to compare a value and then merge that object. Object is a Value object with some setters and getters. Appreciate your help. List<OrderVO> masterList; List<OrderVO> errorList; If errorList.OrderVO.getOrderID = masterList.OrderVO.getOrderID then masterList.OrderVO.merge(errorList.OrderVO) or copy all values of masterList.OrderVO.copy(errorList.OrderVO). Hoper this is clear

    Read the article

  • Equivalent of c# 'as' command in c++?

    - by Sam
    In c# you can use as to convert a type or get null: Object o = Whatever(); String s = o as String; Is there a similar easy way to achieve this in c++? I'm using Visual Studio 2010, if thats important. [update] Remember, there is a very important difference between casting and using as. Casting (at least in c#) will throw an exception if the type does not match: Object o = null; String s = (String)o; // will crash.

    Read the article

< Previous Page | 174 175 176 177 178 179 180 181 182 183 184 185  | Next Page >