Search Results

Search found 6569 results on 263 pages for 'specification pattern'.

Page 98/263 | < Previous Page | 94 95 96 97 98 99 100 101 102 103 104 105  | Next Page >

  • Translate This git_parse_function to zsh?

    - by yar
    I am using this function in Bash function parse_git_branch { git_status="$(git status 2> /dev/null)" pattern="^# On branch ([^${IFS}]*)" if [[ ! ${git_status}} =~ "working directory clean" ]]; then state="*" fi # add an else if or two here if you want to get more specific if [[ ${git_status} =~ ${pattern} ]]; then branch=${BASH_REMATCH[1]} echo "(${branch}${state})" fi } but I'm determined to use zsh. While I can use this perfectly as a shell script (even without a shebang) in my .zshrc the error is a parse error on this line if [[ ! ${git_status}}... What do I need to do to get it ready for zshell? Note: I realize the answer could be "go learn zsh syntax," but I was hoping for a quick hand with this if it's not too difficult.

    Read the article

  • Preg_replace regex, newlines, connection resets

    - by bob_the_destroyer
    I have mixed html, custom code, and regular text I need to examine and change frequently on several, long wiki pages. I'm working with a proprietary wiki-like application and have no control over how the application functions or validates user input. The layout of pages that users add must follow a very specific standard layout and always include very specific text in only certain places - a standard which frequently changes. If users add pages that are so far out of the standard, they will be deleted. The fact that all this is obviously a complete waste of time when alternative platforms to do exactly what's needed here exist is already understood. I've built a PHP based API to automate this post-validation and frequent restandardization process for me. I've been able set up regex patterns to handle all this mixed text, and they all work fine for handling single lines. The problem I have is this: Poorly formed regex against long text with line breaks can lead to unexpected results, such as connection resets. I have no access to server-side logs to troubleshoot. How do I overcome this? This is just one example of what I currently have: {column} and {section} tags I'm searching for below can have any number of attributes, and wrap any text. {section} may or may not exist and may or may not be one or more lines under {column}, but it has to be wrapped inside {column}. {column} itself may or may not exist, and if it doesn't, I don't care. I want to grab the inner section contents and wrap it in an html div tag. I can't recall the exact pattern I'm using offhand at the moment, but it's close enough... $pattern = "/\{column:id=summary([|]?([a-zA-Z0-9-_ ]+[:][a-zA-Z0-9-_ ]+[ ]?))\}(.*)({section([|]([a-zA-Z0-9-_ ]+[:][a-zA-Z0-9-_ ]+[ ]?))\}(.*)\{section\}(.*))?{column\}/s"; $replacement = "{html}<div id='summary'$7</div{html}"; $text = preg_replace($pattern, $replacement, $subject); Handling the {column} and {section} attributes and passing only valid HTML parameters to the new html div or a subtext of it is itself a challenge, but my main focus above right now is getting that (.*) value within {section} above without causing a connection reset. Any pointers?

    Read the article

  • How can I find out a servlet's URL?

    - by Geo
    Let's say I have this in my web.xml: <servlet> <description></description> <display-name>MainServ</display-name> <servlet-name>MainServ</servlet-name> <servlet-class>MainServ</servlet-class> </servlet> <servlet-mapping> <servlet-name>MainServ</servlet-name> <url-pattern>/MainServ</url-pattern> </servlet-mapping> Imagine I'm in that servlet's doGet method. Is there anyway of getting at the /MainServ value?

    Read the article

  • Refactoring thick client legacy application

    - by Paul
    I am working on a fat client legacy C++ application which has a lot of business logic mixed in with the presentation side of things. I want to clean things out and refactor the code out completely, so there is a clear seperation of concerns. I am looking at MVC or some other suitable design pattern in order to achieve this. I would like to get recommendations from people who have walked this road before - Do I use MVP or MVC (or another pattern)? What is/are the best practices for undertaking something like this (i.e. useful steps/checks) ?

    Read the article

  • Elegantly Handle Repetitive Property Code in C#

    - by Eric J.
    The language shortcut public string Code { get; set; } saves a bit of typing when defining trivial properties in C#. However, I find myself writing highly repetitive, not-quite-as-trivial property code that still follows a clear pattern e.g. public string Code { get { return code; } set { if (code != value) { code = value; NotifyPropertyChanged("Code"); } } } I can certainly define a Visual Studio snippet to reduce typing. However, if I need to add something to my pattern, I have to go back and change quite a bit of existing code. Is there a more elegant approach? Is a snippet the best way to go?

    Read the article

  • Explain the code: c# locking feature and threads

    - by Mendy
    I used this pattern in a few projects, (this snipped of code is from CodeCampServer), I understand what it does, but I'm really interesting in an explanation about this pattern. Specifically: Why is the double check of _dependenciesRegistered. Why to use lock (Lock){}. Thanks. public class DependencyRegistrarModule : IHttpModule { private static bool _dependenciesRegistered; private static readonly object Lock = new object(); public void Init(HttpApplication context) { context.BeginRequest += context_BeginRequest; } public void Dispose() { } private static void context_BeginRequest(object sender, EventArgs e) { EnsureDependenciesRegistered(); } private static void EnsureDependenciesRegistered() { if (!_dependenciesRegistered) { lock (Lock) { if (!_dependenciesRegistered) { new DependencyRegistrar().ConfigureOnStartup(); _dependenciesRegistered = true; } } } } }

    Read the article

  • How-to handle errors in Vim Script ?

    - by ereOn
    In my .vimrc file, I have the following function, which folds the licensing information on the top of some .hpp and .cpp files: " Skip license function! FoldLicense() if !exists("b:foldedLicense") let b:foldedLicense = 1 1;/\*\//fold endif endfunction au BufRead *.hpp call FoldLicense() au BufRead *.cpp call FoldLicense() This works well, but if I open a .cpp file which doesn't have any licensing information block, Vim complains that the pattern is not found. Fair enough, but is there a way so that he stops complaining and just does nothing if the pattern is not found ? Thanks !

    Read the article

  • How to define a url not found servlet mapping in web.xml?

    - by user246114
    Hi, I have a web app, I want to define my index.jsp file to be shown when the entered url is like: www.mysite.com www.mysite.com/ www.mysite.com/index.jsp but if any other url is entered, like: wwww.mysite.com/g I want a particular servlet to handle the request. In my web.xml file, I am doing this: <servlet> <servlet-name>ServletCore</servlet-name> <servlet-class>com.me.test.ServletCore</servlet-class> </servlet> <servlet-mapping> <servlet-name>ServletCore</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> so that is letting the ServletCore servlet pick up any url, but as expected it is taking over even the: www.mysite.com/index.jsp type urls. How can I define it in such a way to work how I want? Thank you

    Read the article

  • Why can I derived from a templated/generic class based on that type in C# / C++

    - by stusmith
    Title probably doesn't make a lot of sense, so I'll start with some code: class Foo : public std::vector<Foo> { }; ... Foo f; f.push_back( Foo() ); Why is this allowed by the compiler? My brain is melting at this stage, so can anyone explain whether there are any reasons you would want to do this? Unfortunately I've just seen a similar pattern in some production C# code and wondered why anyone would use this pattern.

    Read the article

  • benefit os having a factory for object creation?

    - by ajsie
    im trying to understand the factory design pattern. i dont understand why it's good to have a middleman between the client and the product (object that the client wants). example with no factory: $mac = new Mac(); example with a factory: $appleStore = new AppleStore(); $mac = $appleStore->getProduct('mac'); how does the factory pattern decouple the client from the product? could someone give an example of a future code change that will impact on example 1 negative, but positive in example 2 so i understand the importance of decoupling? thanks

    Read the article

  • How to test a regex password in Python?

    - by jCuga
    Using a regex in Python, how can I verify that a user's password is: At least 8 characters Must be restricted to, though does not specifically require any of: uppercase letters: A-Z lowercase letters: a-z numbers: 0-9 any of the special characters: @#$%^&+= Note, all the letter/number/special chars are optional. I only want to verify that the password is at least 8 chars in length and is restricted to a letter/number/special char. It's up to the user to pick a stronger / weaker password if they so choose. So far what I have is: import re pattern = "^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$" password = raw_input("Enter string to test: ") result = re.findall(pattern, password) if (result): print "Valid password" else: print "Password not valid"

    Read the article

  • C++ boost thread id and Singleton

    - by aaa
    hi. Sorry to flood so many questions this week. I assume thread index returned by thread.get_id is implementation specific. In case of the pthreads, is index reused? IE, if thread 0 runs and joins, is thread launched afterwords going to have a different ID? the reason I ask this is a need to implement Singleton pattern with a twist: each thread gets its own instance. I know it sounds very crazy, but threads control hardware (cuda) which does not permit device memory sharing. What is a good way to implement such pattern?

    Read the article

  • Please Describe Your Struggles with Minimizing Use of Global Variables

    - by MetaHyperBolic
    Most of the programs I write are relatively flowchartable processes, with a defined start and hoped-for end. The problems themselves can be complex but do not readily lean towards central use of objects and event-driven programming. Often, I am simply churning through great varied batches of text data to produce different text data. Only occasionally do I need to create a class: As an example, to track warnings, errors, and debugging message, I created a class (Problems) with one instantiation (myErr), which I believe to be an example of the Singleton design pattern. As a further factor, my colleagues are more old school (procedural) than I and are unacquainted with object-oriented programming, so I am loath to create things they could not puzzle through. And yet I hear, again and again, how even the Singleton design pattern is really an anti-pattern and ought to be avoided because Global Variables Are Bad. Minor functions need few arguments passed to them and have no need to know of configuration (unchanging) or program state (changing) -- I agree. However, the functions in the middle of the chain, which primarily control program flow, have a need for a large number of configuration variables and some program state variables. I believe passing a dozen or more arguments along to a function is a "solution," but hardly an attractive one. I could, of course, cram variables into a single hash/dict/associative array, but that seems like cheating. For instance, connecting to the Active Directory to make a new account, I need such configuration variables as an administrative username, password, a target OU, some default groups, a domain, etc. I would have to pass those arguments down through a variety of functions which would not even use them, merely shuffle them off down through a chain which would eventually lead to the function that actually needs them. I would at least declare the configuration variables to be constant, to protect them, but my language of choice these days (Python) provides no simple manner to do this, though recipes do exist as workarounds. Numerous Stack Overflow questions have hit on the why? of the badness and the requisite shunning, but do not often mention tips on living with this quasi-religious restriction. How have you resolved, or at least made peace with, the issue of global variables and program state? Where have you made compromises? What have your tricks been, aside from shoving around flocks of arguments to functions?

    Read the article

  • My Java regex isn't capturing the group

    - by Geo
    I'm trying to match the username with a regex. Please don't suggest a split. USERNAME=geo Here's my code: String input = "USERNAME=geo"; Pattern pat = Pattern.compile("USERNAME=(\\w+)"); Matcher mat = pat.matcher(input); if(mat.find()) { System.out.println(mat.group()); } why doesn't it find geo in the group? I noticed that if I use the .group(1), it finds the username. However the group method contains USERNAME=geo. Why?

    Read the article

  • running code when two events have triggered

    - by Evert
    This is mostly a language-agnostic question. If I'm waiting for two events to complete (say, two IO events or http requests), what is the best pattern to deal with this. One thing I can think of is the following (pseudo js example). request1.onComplete = function() { req1Completed = true; eventsCompleted(); } request2.onComplete = function() { req2Completed = true; eventsCompleted(); } eventsCompleted = function() { if (!req1Completed || !req2Completed) return; // do stuff } Is this the most effective pattern, or are there more elegant ways to solve this issue?

    Read the article

  • When [script] file download fails, how can I tell why?

    - by Bruce
    My web application sends me diagnostic info from the browser javascript telling me that a [script] tag I've injected has failed to download the associated .js file. I can't reproduce this locally, and there is no particular pattern to which file fails, or what the browser type is. There is a pattern to the geo location of the requests - Mexico and Brazil are always more frequent - so I'm guessing that perhaps the internet in general is just more flaky there, and it is just network issues causing the failures. I'd really like to know for sure, though. Is there any way to determine, from the browser javascript, whether the failure occurred because of an error returned by the server, from a network error, or from a protocol timeout? I don't care if the mechanism is browser-specific, since it seems likely that the same issue is causing the error on all browser types.

    Read the article

  • [AS 3.0] How to use the string.match method to find multiple occurrences of the same word in a strin

    - by Steven
    In Actionscript and Adobe Flex, I'm using a pattern and regexp (with the global flag) with the string.match method and it works how I'd like except when the match returns multiple occurrences of the same word in the text. In that case, all the matches for that word point only to the index for the first occurrence of that word. For example, if the text is "cat dog cat cat cow" and the pattern is a search for cat*, the match method returns an array of three occurrences of "cat", however, they all point to only the index of the first occurrence of cat when i use indexOf on a loop through the array. I'm assuming this is just how the string.match method is (although please let me know if i'm doing something wrong or missing something!). I want to find the specific indices of every occurrence of a match, even if it is of a word that was already previously matched. I'm wondering if that is just how the string.match method is and if so, if anyone has any idea what the best way to do this would be. Thanks.

    Read the article

  • What, *specifically*, makes DataMapper more flexible than ActiveRecord?

    - by Billy ONeal
    I'm comparing Doctrine 2 and Propel 1.5/1.6, and I'm looking in to some of the patterns they use. Doctrine uses the DataMapper pattern, while Propel uses the ActiveRecord pattern. While I can see that DataMapper is considerably more complicated, I'd assume some design flexibility comes from this complication. So far, the only legitimate reason I've found to use DataMapper over ActiveRecord is that DataMapper is better in terms of the single responsibility principle -- because the database rows are not the actual objects being persisted, but with Propel that doesn't really concern me because it's generated code anyway. So -- what makes DataMapper more flexible?

    Read the article

  • Instantiate a javascript module only one time.

    - by Cedric Dugas
    Hey guys, I follow a module pattern where I instantiate components, however, a lot of time a component will only be instantiate one time (example: a comment system for an article). For now I instantiate in the same JS file. but I was wondering if it is the wrong approach? It kind of make no sense to instantiate in the same file and always only once. But at the same time, if this file is in the page I want to have access to my module without instantiate from elsewhere, and IF I need another instance, I just create another from elsewhere... Here is the pattern I follow: ApplicationNamespace.Classname = function() { // constructor function privateFunctionInit() { // private } this.privilegedFunction = function() { // privileged privateFunction(); }; privateFunctionInit() }; ApplicationNamespace.Classname.prototype = { Method: function(){} } var class = new ApplicationNamespace.Classname(); What do you think, wrong approach, or is this good?

    Read the article

  • What is the sense of "Feature Oriented Programming" (FOP) in C++, and would it make sense in Java an

    - by ivan_ivanovich_ivanoff
    Hello! Sadly, I can't remember where I read it, but... ...in C++ you can derive a class from a template parameter. Im pretty sure it was called Feature Oriented Programming (FOP) and meant to be somehow useful. It was something like: template <class T> class my_class : T { // some very useful stuff goes here ;) } My questions about this: What is the sense of such pattern? Since this it not possible in Java / C#, how this pattern is achieved in these languages? Can it be expected to be implemented in Java / C# one day? (Well, first Java would need to get rid of type erasure) EDIT: I'm really not talking about generics in Java / C# (where you can't derive a class from a generic type parameter)

    Read the article

  • How can I fix this regex to allow a specific string?

    - by Sailing Judo
    This regex comes from Atwood and is used to filter out anchor tags with anything other than the href and a title: <a\shref="(\#\d+|(https?|ftp)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+)"(\stitle="[^"]+")?\s?> I need to allow am additional attribute that specifically matches: target="_blank". So the following url should be allowed: <a href="http://www.google.com" target="_blank"> I tried changing the pattern to these: <a\shref="(\#\d+|(https?|ftp)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+)"(\stitle="[^"]+")(\starget="_blank")?\s?> <a\shref="(\#\d+|(https?|ftp)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+)"(\stitle="[^"]+")(\starget=\"_blank\")?\s?> Clearly I don't know regex very well. How should the pattern be adjusted to allow the blank target and no other targets?

    Read the article

  • [GWT] StackLayoutPanel and MVP

    - by Stine
    Hello! Think there might be something about this MVP approach I have completely misunderstood. Currently I am struggling to apply the MVP pattern to the part of my application consisting of a StackLayoutPanel (accordion). To me it seems natural to have a presenter and a view per stack... but how do I allow the different presenters to react when the user switch the state of the stack panel? If someone could sketch an application of the MVP pattern in the case of an accordion application I would be really, really grateful! This is really getting on my nerves! ;D Thanks a lot from Stine :)

    Read the article

  • [FLEX] MVC: choosing a view at runtime

    - by Alberto M
    Hi all, I'm quite new to the MVC design-pattern, and I'm translating all of my old code. I want to move to this pattern because I can change my views according to my needs, but I'm finding difficult to do it at runtime. I found an excellent example of MVC, and all that I do is the following: <mx:ViewStack xmlns:mx="http://www.adobe.com/2006/mxml" resizeToContent="true" xmlns:views="MVC.views.*"> <views:HomeView id="Home"/> <views:SecondPage id="SecondPage "/> </mx:ViewStack> what if I wanted to change (whenever the Controller says so) one of the views, for example the SecondPage view? (Hope I made my point clear)

    Read the article

< Previous Page | 94 95 96 97 98 99 100 101 102 103 104 105  | Next Page >