pattern

How to spot and analyse similar patterns like Excel does?

You know the functionality in Excel when you type 3 rows with a certain pattern and drag the column all the way down Excel tries to continue the pattern for you. For example Type... test-1 test-2 test-3 Excel will continue it with: test-4 test-5 test-n... Same works for some other patterns such as dates and so on. I'm trying...

Multi-line Pattern and tag search

Hello I'm trying to make a pattern for tags, but the sub method just replace the first char and 3 at the end of the line, im trying to replace all tags on the line and with multiline p=re.compile('<img=([^}]*)>([^}]*)</img>', re.S) p.sub(r'[img=\1]\2[/img]','<img="test">dsad</img> <img="test2">dsad2</img>') output: '**[**img="test">dsa...

Pattern for fast copy in C

Hi, I once saw a programming pattern (not design), how to implement a fast copy of buffers. It included an interleaved loop and switch. The thing was, it copied 4 bytes most of the time, only the last few bytes of the buffer were copied using smaller datatypes. Can someone tell me the name of it? It's named after a person. It's done in...

Pattern to create class instances by integer id?

I am reading a Stream, which provides an identifier (a simple int). Depending on the int different data follows, which i need to turn into objects. So far i created classes for each object type, and each class provides a read(InputStream input)-method which reads whatever data there is to be read for that kind of object (all object class...

Runtime dependency injection with Spring

My current project is leveraging Spring, and our architect has decided to let Spring manage Services, Repositories and Factory objects, but NOT domain objects. We are closely following domain driven design. The reasoning behind not using spring for domain objects is primarily that spring only allows static dependency injection. What i me...

Singleton Pattern in .Net is not possible?

Hi Guys I have a very interesting situation , i have figured out that Singleton pattern is not all possible with .net framework (Any version) look at this code below namespace SingletonPattern { class Singleton { private static readonly Singleton instance = new Singleton(); private static int mcount = 0; private ...

Generic pattern algorithms (language agnostic)

I'm sorry to ask such a vague and generic question, but I need to write a set of tools that will aid people in creating 2D and 3D geometric patterns. Does anyone know any good online resources that discuss pattern logic and algorithms (Wikipedia call it tesselations)? Much obliged, David ...

How do I generate integer partitions?

I have a list of numbers like 1,2,3 and I want to find all the combination patterns that sum up to a particular number like 5. For example: Sum=5 Numbers:1,2,3 Patterns: 1 1 1 1 1 1 1 1 2 1 1 3 1 2 2 2 3 You're allowed to repeat numbers as far as they don't go over your sum. Which way would be best to program this? ...

Java observer and observable

Can anyone explain why the update method on printobserver is not being called when I click the button on this JFrame? import java.awt.BorderLayout; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.net.InetAddress; import java.net....

C# approach for a simple plugin/service provider model? (different code depending on...)

Hi what's the recoomended approach in C# when one wants to implement a simple plugin approach? So basically I have a processing loop that I want different behavior to occrur depending on what the user selected. Let's say there are two places in the processing code for which logic (code)has to be different depending upon user input. ...

Visitor Pattern in Ruby, or just use a Block?

Hey there, I have read the few posts here on when/how to use the visitor pattern, and some articles/chapters on it, and it makes sense if you are traversing an AST and it is highly structured, and you want to encapsulate the logic into a separate "visitor" object, etc. But with Ruby, it seems like overkill because you could just use blo...

Custom Django admin URL + changelist view for custom list filter by Tags

In django admin I wanted to set up a custom filter by tags (tags are introduced with django-tagging) I've made the ModelAdmin for this and it used to work fine, by appending custom urlconf and modifying the changelist view. It should work with URLs like: http://127.0.0.1:8000/admin/reviews/review/only-tagged-vista/ But now I get 'inval...

Search for Binary Pattern in C (Read buffered binary file)

Hey there. I'm trying to write a small program that will read the four following bytes after the last occurrence of "0xFF 0xC0 0x00 0x11" which can be converted easily to binary or decimal. The purpose is that the 2-5 bytes following the last occurrence of that hex pattern represent the width and height of a JPEG file. #include <stdio.h...

Regex pattern to return text from within brackets..

Hi, i am looking for a regex pattern that will return me the contents of the first set of brackets in a string. Eg - text text text text (hello) text (hello2) (hello3) text ..will return "hello" does anyone know what the pattern looks like for c#? ...

regex in textpad

I'm trying to use textpad to search for a regular expression in several files. it's a simple pattern but it doesn't work in textpad. It works fine in Visual Studio. Anyone have any ideas? searching for: hosted.mysite.com or host.mysite.com using (hosted|host).mysite.com ...

Repository Pattern and Linq to sql

I 'm trying to implement user authentication and authorization using roles table, user table and a xref table having userid, roleid. For implementing generic repoistory to update role, insert role, add user, add user to role, update user, update user role, authenticate user, add user session to audit etc do i have write seperate functi...

What is the most elegant way of shell sorting (comb / diminishing increment sorting) in C#?

Hi SO, Is there a better way to shell sort using C#? // array of integers to hold values private int[] a = new int[100]; // number of elements in array private int count; // Shell Sort Algorithm public void sortArray() { int i, j, increment, temp; increment = 3; while( increment > 0 ) { for( i=0; i < count; i++ ) {...

Generate pattern (and/or regex) automated from input

Heyho, I've got a big bunch of loglines (more or less without documentation) and need to parse the lines. The parsing itself won't be a big problem, but first I need to know how many different kinds of lines are inside the files. Besides the fact that I've got really different lines like short errors, up to bigger lines which are only di...

Javascript: best Singleton pattern

I'm using this pattern for singletons, in the example the singleton is PlanetEarth: var NAMESPACE = function () { var privateFunction1 = function () { privateFunction2(); }; var privateFunction2 = function () { alert('I\'m private!'); }; var Constructors = {}; Constructors.PlanetEarth = function () { privateFunction1(); ...

C# matrix sparsity pattern visualization

Hi! Are there some implementations of sparse matrices visualization in C# ? I know that spy function do such thing in matlab, but didn't find any implementations in C#. Regards ...