pattern

Database migration pattern for Java?

Im working on some database migration code in Java. Im also using a factory pattern so I can use different kinds of databases. And each kind of database im using implements a common interface. What I would like to do is have a migration check that is internal to the class and runs some database schema update code automatically. The actu...

Efficient mass string search problem.

The Problem: A large static list of strings is provided. A pattern string comprised of data and wildcard elements (* and ?). The idea is to return all the strings that match the pattern - simple enough. Current Solution: I'm currently using a linear approach of scanning the large list and globbing each entry against the pattern. My Que...

Aggregate Pattern and Performance Issues

Hello, I have read about the Aggregate Pattern but I'm confused about something here. The pattern states that all the objects belonging to the aggregate should be accessed via the Aggregate Root, and not directly. And I'm assuming that is the reason why they say you should have a single Repository per Aggregate. But I think this ad...

Ranking based string matching algorithm..for Midi Music

i am working on midi music project. What i am trying to do is:- matching the Instrument midi track with the similar instrument midi track... for example Flute track in a some midi music is matched against the Flute track in some other music midi file... After matching ,the results should come ranking wise according to their similarity....

Looking for ideas for a simple pattern matching algorithm to run on a microcontroller

I'm working on a project to recognize simple audio patterns. I have two data sets, each made up of between 4 and 32 note/duration pairs. One set is predefined, the other is from an incoming data stream. The length of the two strongly correlated data sets is often different, but roughly the same "shape". My goal is to come up with some s...

Need a design pattern for representing multiple information sources

I'm building a Java application that retrieves information from differing information sources. I'm using a sensor, a set of RecordStores and a few online web services. In the basic application all these resources are loaded by default. Some of these sources are directly read in a separate thread (load database, read sensor etc.). From ...

regular expression to match any string but at least 3 characters

sorry am not a regex expert. but my request is simple, i need to match any string that has at least 3 or more characters that are matching So for instance, we have the string "hello world" and matching it with the following: "he" => false // only 2 characters "hel" => true // 3 characters match found thansk in advance. ...

How do I select all parenting items based on a given node's attribute in php's xPath?

Thanks to AakashM, he led me in the right direction. For the question below, this is the xPath expression that led me the right way: "//channel/item[category[@domain='http://www.somelink.com/?category=4']]" Original post: I have an XML feed that looks something like this (excerpt): <channel> <title>Channel Name</title> <link>Lin...

Socket server with multiple clients, sending messages to many clients without hurting liveliness

I have a small socket server, and I need to distribute various messages from client-to-client depending on different conditionals. However I think I have a small problem with livelyness in my current code, and is there anything wrong in my approach: public class CuClient extends Thread { Socket socket = null; ObjectOutputStream out; ...

Design Pattern for "Context Sensitive" Right Click Menu

Hi, What is a design pattern I can use for generating "context-sensitive" right click menus ? I have in mind a "Windows Explorer"-like application where a user can right click on a folder and get a list of menu items but right click on a drive and get a totally different list. What design pattern should I use ? Would the factory design...

Elegent way to collapse or expand sub-sequences of a list in Python?

I want to collapse or expand sub-sequences of a list e.g. ['A', 'B', 'D', 'E', 'H'] -> ['AB', 'DE', 'H'] and vice versa EDIT: the example above may cause misunderstanding. the following is better: e.g. ['foo', 'bar', 'wtf'] <-> ['baz', 'wtf'] currently I wrote some ugly code like: while True: for i, x in enumerate(s): if x ==...

Unix: replace every odd | with \left| and every even | with \right|

An enormous equation. You need to add \left| on the left side of corresponding |. The corresponding | you need to replace with \right|. Equation \begin{equation} | \Delta w_{0} | = \frac{|w_{0}|}{2} \left( |\frac{\Delta g}{g}|+|\frac{\Delta (\Delta r)}{\Delta r}| + |\frac{\Delta r}{r}| +|\frac{\Delta L}{L}| \right) \end{equation} [Pr...

Another design-related C++ question

Hi! I am trying to find some optimal solutions in C++ coding patterns, and this is one of my game engine - related questions. Take a look at the game object declaration (I removed almost everything, that has no connection with the question). // Abstract representation of a game object class Object : public Entity, IRenderable...

get particular string using regex java

i want to know how to get the string from group of string String j = "<a ............> hai</a>"; i want to get the string of tag of <a ...> ... </a> thanks and advance ...

Matching Line Boundaries in a Regular Expression (Pattern.MULTILINE/(?m)) is broken in Java?

The example on http://www.exampledepot.com/egs/java.util.regex/Line.html gives false for me twice but should'nt! Why? CharSequence inputStr = "abc\ndef"; String patternStr = "abc$"; // Compile with multiline enabled Pattern pattern = Pattern.compile(patternStr, Pattern.MULTILINE); Matcher matcher = pattern.matcher(inputStr); boolean ma...

Java RegEx Pattern not matching (works in .NET)

Below is an example that is producing an exception in Java (and not matching the input). Perhaps I misunderstood the JavaDoc, but it looks like it should work. Using the same pattern and input in C# will produce a match. import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void main(Str...

makefile pattern rules: single wildcard, multiple instances in prerequisite

Hi all, hopefully this is a basic question about make pattern rules: I want to use a wildcard more than once in a prerequisite for a rule, i.e. in my Makefile I have data/%P1.m: $(PROJHOME)/data/%/ISCAN/%P1.RAW @echo " Writing temporary matlab file for $*" # do something data/%P2.m: $(PROJHOME)/data/%/ISCAN/AGP2.RAW ...

Apply PHP regex replace on a multi-line repeated pattern

Let's say I have this input: I can haz a listz0rs! # 42 # 126 I can haz another list plox? # Hello, world! # Welcome! I want to split it so that each set of hash-started lines becomes a list: I can haz a listz0rs! <ul> <li>42</li> <li>126</li> </ul> I can haz another list plox? <ul> <li>Hello, world!</li> <li>Welcome!...

Are there any design guides, tutorials or patterns for designing DSLs?

I am not looking for frameworks or tools, but for advice how to get from a rough idea to a nice DSL. ...

Is there a Pattern in Scala that add a method to an Array object?

Is there a Pattern in Scala that can add a method to an Array object? I am thinking of the implicit conversion of Int to RichInt. But that can't be done as Array is a final class. ...