pattern

Refactor Regex Pattern - Java

Hello All, I have the following aaaa_bb_cc string to match and written a regex pattern like \\w{4}+\\_\\w{2}\\_\\w{2} and it works. Is there any simple regex which can do this same ? ...

How do you code up a pattern matching code block in scala?

How do you code a function that takes in a block of code as a parameter that contains case statements? For instance, in my block of code, I don't want to do a match or a default case explicitly. I am looking something like this myApi { case Whatever() => // code for case 1 case SomethingElse() => // code for case 2 } And insid...

Factory Method pattern and public constructor

Hi, Im making a factory method that returns new instances of my objects. I would like to prevent anyone using my code from using a public constructor on my objects. Is there any way of doing this? How is this typically accomplished: public abstract class CarFactory { public abstract ICar CreateSUV(); } public class MercedesFactory :...

Best Practice, objects design ASP.NET MVC

Hello Stackoverflow I have a code design question that have been torbeling me for a while, you see I’m doing a refactoring of my website Cosplay Denmark, a site where cospalyers can upload images of them self in their costumes. The original site was done in php, Zend MVC, but my refactoring is being done in ASP.NET MVC 2. If you take t...

How to structure web application with part of it being secured (SSL)

What is the common pattern to structure web application where part of it has to be secured. So lets say I have page_a and page_b which do not need to be secured, although should display login information (login fields or login details once user logged in). This web app. also would have secured pages (admin, checkout or similar) secure_pa...

XSD string pattern independent of leading/trailing space

I have a XSD simple type that should match UUIDs: <simpleType name="UuidT"> <restriction base="string"> <pattern value="[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}" /> </restriction> </simpleType> It correctly matches the following content: <!-- valid --> <Uuid>12345678-1234-5678-9012-123456789012</Uu...

Complex pattern replacement using PHP preg_replace function ignoring quoted strings

Consider the following string: this is a STRING WHERE some keywords ARE available. 'i need TO format the KEYWORDS from the STRING' In the above string keywords are STRING and WHERE Now i need to get an output as follows: this is a <b>STRING</b> <b>WHERE</b> some keywords ARE available. 'i need TO format the KEYWORDS from the ...

Protection of acces with Auto-Implemented Properties in C#

A simple example. A have a class TDMReader which is a buldier of TDMFile objects and I am using Auto Implemented Properties f.e. public string Name { get; set; } public Group[] Groups { get; set; } What I want to do is to make setter accessible only for TDMReader methods. In...

Mediator Pattern for trivial messages ?

Hi, Is it a good programming practice to use the mediator pattern for trivial messages (show an image viewer window etc.) ? Mediator.NotifyColleagues(Messages.DISPLAY_IMAGE, image); instead of just using frmImageViewer.Show(image); I use the mediator program in my program a lot and was wondering how much is too much. Regards, ...

BlockingQueue decorator that logs removed objects

I have a BlockingQueue implementation that's being used in a producer-consumer situation. I would like to decorate this queue so that every object that's taken from it is logged. I know what the straightforward implementation would look like: simply implement BlockingQueue and accept a BlockingQueue in the constructor to which all of the...

Are there any libraries for parsing "number expressions" like 1,2-9,33- in Java

Hi, I don't think it is hard, just tedious to write: Some small free (as in beer) library where I can put in a String like 1,2-9,33- and it can tell me whether a given number matches that expression. Just like most programs have in their print range dialogs. Special functions for matching odd or even numbers only, or matching every numb...

iphone registration and authentication pattern

Hi I am looking for a stable (and Apple compliant) registration and authentication design pattern between an iphone device and a server. Ideally the registration and authentication would not involve the user and be a background process. So far I've found 3 primitives for doing components of this: UDID UUID SBFormattedPhoneNumber ...

Count number of occurrences of a pattern in a file (even on same line)

When searching for number of occurrences of a string in a file, I generally use: grep pattern file | wc -l However, this only finds one occurrence per line, because of the way grep works. How can I search for the number of times a string appears in a file, regardless of whether they are on the same or different lines? Also, what if I...

Adaptor Pattern

What are the practical uses of Adaptor Pattern? ...

Locking an android phone (lock pattern or similar)

Since LOCK_PATTERN_ENABLED was moved to Settings.Secure in Froyo my app can no longer lock the screen... Does anyone know a workaround for this? Any way that my app can instantly lock the screen? No matter if its the autolock pattern or some kind of custom lock screen... ...

Accessing the Identity object in a MVC repository

Hi, I have a pretty generic repository that does basic CRUD for many of my business entities. The entities enherit form a generic object that has a few fields I maintain for all objects. eg. ModifiedBy, CreatedBy, CreatedDate, ModifiedDate. These fields ModifiedBy and CreatedBy will always be set before any update/save. My questions is...

TDD with Strategy Pattern

I'm trying to implement the strategy pattern using TDD. Each strategy item implements an interface. What's the best way to do this with TDD? Do you have to create a test fixture for each implementation of the interface testing the same methods but on each implementation? Any articles detailing the approach to take would be gratefully w...

C# ProgressBar design pattern

Hi, I'm working on a database upgrader application. The upgrader updates the schema of a database ( adds new columns, renames columns , adds new tables, new views to an existing database by executing SQL statements ). When a user wants to upgrade from version 1.0 to 2.0 , "Upgrader" objects are taken from an object factory and the "Exec...

How do I separate business logic and database calls from a WCF web service?

This question may have been asked before, but I'm looking for a different answer than what I've seen. Our website is in ASP.NET and we use the model-view-presenter pattern to get business logic out of the markup codebehind. Is there an accepted pattern for web services for getting business logic out of the codebehind? It seems like pu...

Any way in C++ for a base class to diallow virtual methods in all derived classes?

Part of our system uses memory shared between processes who do not share a common ancestor. We place C++ objects in this shared memory. Methods on these objects are either inline in the headers or out of line in object libraries that get linked into the respective processes. An error frequently made by new comers to the system is to i...