patterns

How to detect links in a text ?

greetings all i have a text that may contain links something like: " hello..... visit us on http://www.google.com.eg, and for more info, please contact us on http://www.myweb.com/help" and i want to find and replace any link with the following link anyone knows how to do so ? and i have another question is that how any website li...

Why do we need immutable class?

I am unable to get what are the scenarios where we need an immutable class. Have you ever faced any such requirement? or can you please give us any real example where we should use this pattern. ...

Command pattern event fails cannot figure out why

I have a Menu control implemented on a ASPX page. I extended the MenuItem class so that when you create it you can pass in the command (initialized with its handler) so that when you click a specific MenuItem it automatically knows what event handler to go to. This allows me not to code a switch statement for the OnMenuItemClick logic. ...

Best approach for passing passwords to command line applications

What do you thing it will be the optimal method of passing passwords to different applications. Giving the password as a command line argument is not acceptable because this will be visible in logs - especially in an automation system. At this moment I'm considering two possibilities: providing the password in a file or temporary setti...

Python - what is the correct way to copy an object's attributes over to another?

I have two classes. They're almost identical, except for 2 attributes. I need to copy all the attributes over from one to the other, and I'm just wondering if there is a pattern or best practice, or if I should just basically do: spam.attribute_one = foo.attribute_one spam.attribute_two = foo.attribute_two ... and so on. ...

Microsoft patterns and Practices, Anyone?

I happend to go through the below site from one of the Stack over flow Questions. http://webclientguidance.codeplex.com/wikipage?title=Getting_Started_Feb_2008 Is this "One of the" way to create our web app from VS? I can create a Website,Web App,MVC web apps. now one more? man, its getting confusing. ...

Singletons vs. Application Context in Android?

Recalling this post enumerating several problems of using singletons and having seen several examples of Android applications using singleton pattern, I wonder if it's a good idea to use Singletons instead of single instances shared through global application state (subclassing android.os.Application and obtaining it through context.getA...

Which database patterns (ORM, DAO, Active Record, etc.) to use for small/medium projects?

I writing real estate web site with basic function for choosing and ordering realty. It is small/simple project, but I want to write it in way, so in future I, or other developers, can turn it into medium business app without rewriting it from scratch. So what kind of patterns could you advice me to use for dealing with database? For...

Readers/writers and decoupled persistence of derived classes

I'm refactoring a bunch of old code. My primary objective is to decouple the behavior from the database. The current implementation accesses the database directly which makes it hard to test and do things like implement caching layers etc... Up until this point I've been using a combination of dependency inversion and readers/writers ...

How would I implicitly call a method after having explicitly called another specific type of method

Lets say I have a bunch of methods in a class which call a Webservice and, as a result, I need to check the "response" of the Webservice each time one of these methods is called. But I don't want to do something like this: MethodA() // non web service related method MethodB() // Web service calling method if _response == OK then M...

Multiple Methods to call a WCF Service

Hey I have a class that handles all the interaction in my application with my WCF service and it seems that MSDN say that the use of Using)_ statement with WCF is bad - I can see why this is bad and agree with it (http://msdn.microsoft.com/en-us/library/aa355056.aspx) my problem is that their suggested method of implementation will me...

Single instance in the cluster with WF 4 and AppFabric

Hi, I am trying to do a single instance workflow with WF4 and AppFabric. I want just one instance of a workflow running in the cluster. I have tried a biztalk style: a method (CallService()) that creates the instance, and the same method in other receive activity (CallService()) that do not have the cancreateinstance checked. (I think...

Is there a good pattern for exposing a generic collection as readonly?

So I've got these classes that expose a collection of child objects. I don't want other classes adding or removing objects from collections because I need to wire into events in the child objects, so as they get added or removed I want to be able to do additional processing. But I really love the ease of manipulating generics internally...

Class Construction Techniques

I'd like to get some feedback on what people think of the following class construction techniques. If I'm in a situation where I have the choice of using either of the following: Initialise an object completely in the constructor, Initialise an object by way of it's public properties after the instance has been created. [removed blog...

how is the dom cached between functions in an object literal? (Javascript)

Ok I'm not sure the title of this post is the correct way to refer to what I mean and I'm pretty sure I already know the answer to this question but I just wanted some clarification. If I have an oject like this var myObj = { settings : { domObj = document.getElementById('elem1'); }, myFunc1 : function () { return this.do...

What is the name of this pattern or technique?

There are objects which need two other objects as parameters. This parameter objects may change during runtime. I use another object which holds the references to the parameter objects. These references are always up to date. All the other objects ask this objects for the current parameters. They don't have to be updated anymore. Onl...

Tiling patterns

I'm looking for efficient solution/algorithm for tiling : the layout of the decking tiles. We want to build system that will calculate the mutual placement of columns and beams (beams, joist) with support of irregular shape. Thank you in advance for any help. ...

String pattern/algorithm for PIN & PUK generated from MSIN

I wonder how mobile phone companies generate both PIN and PUK for their SIM cards? I have a large database of already generated codes, this database contains 3 columns: * MSIN : Mobile Subscriber Identification Number (10 digits) * PIN : Personal Identification Number (4 digits) * PUK : Personal Unblocking Code (8 digits) So far, may...

n-digit Pattern Matching in Lua

I'm new to Lua. Say i have a string "1234567890". I want to iterate over all possible 3 digit numbers. (ie 123,234,345,456....) for m in string.gmatch("1234567890","%d%d%d") do print (m) end But this gives me the output 123,456,789. What kind of Pattern should i be using? And secondly, a related question, how do i specify ...

Reference counting in Java

I have a system that keeps running out of disk space because that garbage collector doesn't free the objects that hold the file handles fast enough. (Files are created and deleted all the time, but since the process still has an open file handle, the OS keeps it on the disk). The objects are shared, so a simple try { ... } finally { clo...