Search Results

Search found 107 results on 5 pages for 'decorators'.

Page 3/5 | < Previous Page | 1 2 3 4 5  | Next Page >

  • Is there a name for this functional programming construct/pattern?

    - by dietbuddha
    I wrote a function and I'd like to find out if it is an implementation of some functional programming pattern or construct. I'd like to find out the name of this pattern or construct (if it exists)? I have a function which takes a list of functions and does this to them: wrap(fn1, fn2, fn3, fn4) # returns partial(fn4, partial(fn3, partial(fn2, fn1))) There are strong similarities to compose, reduce, and other fp metaprogramming constructs, since the functions are being arranged together and returned as one function. It also has strong similarities to decorators and Python context managers since it provides a way to encapsulate pre and post execution behaviors in one function. Which was the impetus for writing this function. I wanted the ability that context managers provide, but I wanted to be able to have it defined in one function, and to be able to layer function after function on top.

    Read the article

  • Python twisted Reactor class

    - by anijhaw
    What is the significance of the decorators @reactor.callWhenRunning, @results_deferred.addCallback @results_deferred.addErrback. Also what are deferred strings, for example in the twisted.internet.utils.getProcessOutput() returns a deferred string what exactly is happening here? I am new to twisted hence this might be a very simple question but reading twisted documentation did not help me much

    Read the article

  • Add some html to Zend Forms

    - by bluedaniel
    Hello everyone, Im looking for a simple bit of code that will let me add the following html into my zend form: <div id="wmd-button-bar" class="wmd-panel"></div> Thats it, it needs to be above my 'method' element in the form but thats it. For such a simple action I cant find any methods that don't involve me learning rocket science (i.e Zend Decorators).

    Read the article

  • Java method missing (ala Ruby) for decorating?

    - by cibercitizen1
    Is there any technique available in Java for intercepting messages (method calls) like the method_missing technique in Ruby? This would allow coding decorators and proxies very easily, like in Ruby: :Client p:Proxy im:Implementation ------- ---------- ----------------- p.foo() -------> method_missing() do_something im.foo() ------------------> do_foo p.bar() --------> method_missing() do_something_more im.bar() -------------------> do_bar (Note: Proxy only has one method: method_missing())

    Read the article

  • Unmodifiable NavigableSet/NavigableMap in Java?

    - by Greg Mattes
    java.util.Collections has several unmodifiable methods that provide unmodifiable collection views by wrapping collections in decorators that prohibit mutation operations. Java 6 added support for java.util.NavigableSet and java.util.NavigableMap. I'd like to be able to have unmodifiable NavigableSets and NavigableMaps, but java.util.Collections#unmodifiableSortedSet(SortedSet) and java.util.Collections#unmodifiableSortedMap(SortedMap) are not sufficient because they do not support the operations that are particular to NavigableSet and NavigableMap. Are there de-facto implementations for unmodifiableNavigableSet and unmodifiableNavigableMap?

    Read the article

  • Good suggestions for learning OOP PHP

    - by Doug
    I've been trying to learn PHP OOP and have looked at multiple articles, but have yet to find a good resource for learning. I want to learn from the user of setters and getters, $this-, constructors, and so on...! Can anyone please suggest me something? I noticed MOST teachings leave out the explanation of $this-. I want to learn magic methods, decorators, encapsulation, etc... Feel free to suggest something that I haven't explicitly listed.

    Read the article

  • How do I use ViewScripts on Zend_Form File Elements?

    - by Sonny
    I am using this ViewScript for my standard form elements: <div class="field" id="field_<?php echo $this->element->getId(); ?>"> <?php if (0 < strlen($this->element->getLabel())) : ?> <?php echo $this->formLabel($this->element->getName(), $this->element->getLabel());?> <?php endif; ?> <span class="value"><?php echo $this->{$this->element->helper}( $this->element->getName(), $this->element->getValue(), $this->element->getAttribs() ) ?></span> <?php if (0 < $this->element->getMessages()->length) : ?> <?php echo $this->formErrors($this->element->getMessages()); ?> <?php endif; ?> <?php if (0 < strlen($this->element->getDescription())) : ?> <span class="hint"><?php echo $this->element->getDescription(); ?></span> <?php endif; ?> </div> Trying to use that ViewScript alone results in an error: Exception caught by form: No file decorator found... unable to render file element Looking at this FAQ revealed part of my problem, and I updated my form element decorators like this: 'decorators' => array( array('File'), array('ViewScript', array('viewScript' => 'form/field.phtml')) ) Now it's rendering the file element twice, once within my view script, and extra elements with the file element outside my view script: <input type="hidden" name="MAX_FILE_SIZE" value="8388608" id="MAX_FILE_SIZE" /> <input type="hidden" name="UPLOAD_IDENTIFIER" value="4b5f7335a55ee" id="progress_key" /> <input type="file" name="upload_file" id="upload_file" /> <div class="field" id="field_upload_file"> <label for="upload_file">Upload File</label> <span class="value"><input type="file" name="upload_file" id="upload_file" /></span> </div> Any ideas on how to handle this properly with a ViewScript?

    Read the article

  • Decorator Module Standard

    - by Kyle Terry
    I was wondering if it's frowned upon to use the decorator module that comes with python. Should I be creating decorators using the original means or is it considered okay practice to use the module?

    Read the article

  • Decorator Design Pattern Use With Service Objects (wSingleton)

    - by Dustin
    I'm working on a project where I need to add some functionality to a service object and using a decorator to add it in seems like a good fit. However, I've only ever used decorators with simple beans, never on a singleton like a service object. Has anyone ever done this before and what are the pros and cons? In this case I don't think creating a subclass will work so a decorator seems to be a good fit. What are your thoughts on doing this?

    Read the article

  • Streaming HTTP response, flushing to the browser

    - by synic
    I've got a view like the following: from django.views.decorators.http import condition def stream(): for i in range(0, 40): yield " " * 1024 yield "%d" % i time.sleep(1) @condition(etag_func=None): def view(request): return HttpResponse(stream(), mimetype='text/html') However, it definitely doesn't seem to be streaming at all. All the data is dumped at once, at the end, after about 40 seconds. How can I get it to flush correctly?

    Read the article

  • Koans, now available in Python flavor

    - by Greg Malcolm
    Recently a Python developer friend with whom I was pair programming with suggested that I show him how to write a little Ruby. I responded by telling him to check out Ruby Koans as a starting point. However I wanted to try that in reverse at the same time with me learning some Python. I did a bit of googling, and sure enough someone had started writing some Python Koans. It just needed finishing... So, a few weeks later Python Koans is now complete and ready for action! It is available through Mercurial on Bitbucket: http://bitbucket.org/gregmalcolm/python_koans/wiki/Home It is also mirrored on Github: http://wiki.github.com/gregmalcolm/python_koans/ Converting it was fairly easy. Aside from the differing philosophical approaches behind the two languages, Ruby and Python are fairly similar. We had to come up with completely new material for a few subjects like multiple inheritance and decorators, but for most features in Ruby there is something roughly comparable in Python. I highly recommend writing tests (or koans) as a means to lean a new language or framework. I've learned a lot from doing this.

    Read the article

  • Object oriented EDI handling in PHP

    - by Robert van der Linde
    I'm currently starting a new sub project where I will: Retrieve the order information from our mainframe Save the order information to our web-apps' database Send the order as EDI (either D01b or D93a) Receive the order response, despatch advice and invoice messages Do all kinds of fun things with the resulting datasets. However I am struggling with my initial class designs. The order information will be retrieved from the mainframe which will result in a "AOrder" class, this isn't a problem, I am not sure about how to mold this local object into an EDI string. Should I create EDIOrder/EDIOrderResponse/etc classes with matching decorators (EDIOrderD01BDecorator, EDIOrderD93ADecorator)? Do I need builder objects or can I do: // $myOrder is instance of AOrder $myOrder->toEDIOrder(); $decorator = new EDIOrderD01BDecorator($myOrder); $edi = $decorator->getEDIString(); And it'll have to work the other way around as well. Is the following code a good way of handling this problem or should I go about this differently? $ediString = $myEDIMessageBroker->fetch(); $ediOrderResponse = EDIOrderResponse::fromString($ediString); I'm just not so sure about how I should go about designing the classes and interactions between them. Thanks for reading and helping.

    Read the article

  • Adaptive Case Management Modeling with CMMN by Jessica Ray

    - by JuergenKress
    A new version of Oracle BPM Suite 11.1.1.7 with Adaptive Case Management (ACM) is now available, so what will that mean for requirements gathering? BPM project requirements can be documented using Business Process Model and Notation (BPMN 2.0). For ACM, there is a new notation in the works. It is called Case Management Model and Notation (CMMN). For now, this notation isn’t included as a modeling tool in the new version of Oracle BPM Suite 11.1.1.7 with ACM, but it is possible that a modeling tool could be included in a future release. What is CMMN? CMMN is a standard intended to capture the common elements that Case Management Products use, the same way that BPMN is a standard for BPM products (such as Oracle BPM). CMMN is created by the Object Management Group (OMG) and is still in the beta version. In April 2014, OMG released the second beta version the CMMN 1.0, and the most recent version is available here. CMMN captures some of the elements that are commonly used when talking about ACM such as Cases, Milestones, and Tasks. It also introduces some elements that you may not automatically hear when talking about ACM such as Stages, Events, and Decorators. Here is a quick summary at a few (but not all) of the elements of CMMN taken from the CMMN spec. A Few CMMN Elements Read the complete article here SOA & BPM Partner Community For regular information on Oracle SOA Suite become a member in the SOA & BPM Partner Community for registration please visit www.oracle.com/goto/emea/soa (OPN account required) If you need support with your account please contact the Oracle Partner Business Center. Blog Twitter LinkedIn Facebook Wiki Technorati Tags: Jessica Ray,Avio,Adaptive Case Management,ACM,CMMN,SOA Community,Oracle SOA,Oracle BPM,Community,OPN,Jürgen Kress

    Read the article

  • Decorator not calling the decorated instance - alternative design needed

    - by Daniel Hilgarth
    Assume I have a simple interface for translating text (sample code in C#): public interface ITranslationService { string GetTranslation(string key, CultureInfo targetLanguage); // some other methods... } A first simple implementation of this interface already exists and simply goes to the database for every method call. Assuming a UI that is being translated at start up this results in one database call per control. To improve this, I want to add the following behavior: As soon as a request for one language comes in, fetch all translations from this language and cache them. All translation requests are served from the cache. I thought about implementing this new behavior as a decorator, because all other methods of that interface implemented by the decorater would simple delegate to the decorated instance. However, the implementation of GetTranslation wouldn't use GetTranslation of the decorated instance at all to get all translations of a certain language. It would fire its own query against the database. This breaks the decorator pattern, because every functionality provided by the decorated instance is simply skipped. This becomes a real problem if there are other decorators involved. My understanding is that a Decorator should be additive. In this case however, the decorator is replacing the behavior of the decorated instance. I can't really think of a nice solution for this - how would you solve it? Everything is allowed, even a complete re-design of ITranslationService itself.

    Read the article

  • Is my gedit-latex-plugin working properly?

    - by arroy_0209
    I have installed gedit-latex-plugin(0.2 rc3) to be used with gedit(2.30.3) in ubuntu 10.04. If I use the command gedit file.tex& in terminal the file is opened and it seems everything works fine but in the terminal, lots of comments appear, some of which are: 2012-03-31 22:14:27,263 DEBUG resources - Initializing resource locating 2012-03-31 22:14:27,361 DEBUG Preferences - not found 2012-03-31 22:14:27,373 DEBUG JobManager - Created JobManager instance 147209196 2012-03-31 22:14:27,379 DEBUG GeditLaTeXPlugin - activate 2012-03-31 22:14:27,379 DEBUG WindowContext - init 2012-03-31 22:14:27,444 DEBUG GeditWindowDecorator - _init_tab_decorators: initialized 0 decorators 2012-03-31 22:14:27,511 DEBUG GeditWindowDecorator - active_tab_changed 2012-03-31 22:14:27,511 DEBUG GeditWindowDecorator - ---------- ADJUST: None 2012-03-31 22:14:27,513 DEBUG GeditWindowDecorator - No window-scope views for this extension 2012-03-31 22:14:27,513 DEBUG GeditWindowDecorator - _set_selected_bottom_view: 0 2012-03-31 22:14:27,514 DEBUG GeditWindowDecorator - _set_selected_side_view: 0 2012-03-31 22:14:27,539 DEBUG GeditWindowDecorator - tab_added 2012-03-31 22:14:27,952 DEBUG GeditTabDecorator - loaded 2012-03-31 22:14:27,964 DEBUG GeditTabDecorator - _adjust_editor: URI has changed 2012-03-31 22:14:27,965 DEBUG LaTeXCompletionHandler - init 2012-03-31 22:14:27,966 DEBUG LanguageModelFactory - Pickled object found: /home/abcd/.gnome2/gedit/plugins/GeditLaTeXPlugin/latex.pkl 2012-03-31 22:14:28,075 DEBUG CompletionDistributor - init 2012-03-31 22:14:28,078 DEBUG WindowContext - Created view LaTeXOutlineView 2012-03-31 22:14:28,078 DEBUG WindowContext - Created view IssueView 2012-03-31 22:14:28,079 DEBUG LaTeXEditor - init(file:///home/abcd/dir1/file1.tex) 2012-03-31 22:14:28,079 DEBUG LaTeXEditor - Parsing document... 2012-03-31 22:14:28,080 DEBUG IssueView - init 2012-03-31 22:14:28,082 DEBUG IssueView - init finished 2012-03-31 22:14:28,092 INFO LaTeXEditor - LaTeXParser.parse: 0.010000 2012-03-31 22:14:28,092 DEBUG LaTeXEditor - Parsed 1599 bytes of content 2012-03-31 22:14:28,093 DEBUG LaTeXOutlineView - set_outline 2012-03-31 22:14:28,093 DEBUG LaTeXOutlineView - init 2012-03-31 22:14:28,097 DEBUG LaTeXValidator - validate 2012-03-31 22:14:28,098 DEBUG LanguageModel - set_newcommands: 2012-03-31 22:14:28,102 DEBUG LaTeXEditor - Parsing finished 2012-03-31 22:14:28,105 DEBUG GeditWindowDecorator - ---------- ADJUST: .tex 2012-03-31 22:14:28,119 DEBUG GeditWindowDecorator - _set_selected_bottom_view: 0 2012-03-31 22:14:28,120 DEBUG GeditWindowDecorator - _set_selected_side_view: 0 I am not sure if the gedit-latex-plugin is working properly or is it facing some problem. Why are there so many debug messages? Can anybody please suggest what I should do?

    Read the article

  • Testing sample code in python modules

    - by Andrew Walker
    I'm in the process of writing a python module that includes some samples. These samples aren't unit-tests, and they are too long and complex to be doctests. I'm interested in best practices for automatically checking that these samples run. My current project layout is pretty standard, except that there is an extra top level makefile that has build, install, unittest, coverage and profile targets, that delegate responsibility to setup.py and nose as required. projectname/ Makefile README setup.py samples/ foo-sample foobar-sample projectname/ __init__.py foo.py bar.py tests/ test-foo.py test-bar.py I've considered adding a sampletest module, or adding nose.tools.istest decorators to the entry-point functions of the samples, but for a small number of samples, these solutions sound a bit ugly. This question is similar to http://stackoverflow.com/questions/301365/automatically-unit-test-example-code, but I assume python best practices will differ from C#

    Read the article

  • What is your strategy to avoid dynamic typing errors in Python (NoneType has no attribute x)?

    - by Koen Bok
    Python is one of my favorite languages, but I really have a love/hate relationship with it's dynamicness. Apart from the advantages, it often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. Over time I got better predicting where these could pop up and adding explicit type checking, but because I'm only human I miss one occasionally and then some end-user finds it. So I'm interested in your strategy to avoid these. Do you use type-checking decorators? Maybe special object wrappers? Please share...

    Read the article

  • What is your strategy to avoid dynamic typing errors in Python (NoneType has not attribute x)?

    - by Koen Bok
    Python is one of my favorite languages, but I really have a love/hate relationship with it's dynamicness. Apart from the advantages, it often results in me forgetting to check a type, trying to call an attribute and getting the NoneType (or any other) has no attribute x error. A lot of them are pretty harmless but if not handled correctly they can bring down your entire app/process/etc. Over time I got better predicting where these could pop up and adding explicit type checking, but because I'm only human I miss one occasionally and then some end-user finds it. So I'm interested in your strategy to avoid these. Do you use type-checking decorators? Maybe special object wrappers? Please share...

    Read the article

  • What does Ruby have that Python doesn't, and vice versa?

    - by Lennart Regebro
    There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody choosing, as they might not have the same tastes in development as I do. It would therefore be interesting to list the differences, objectively. So no "Python's lambdas sucks". Instead explain what Ruby's lambdas can do that Python's can't. No subjectivity. Example code is good! Don't have several differences in one answer, please. And vote up the ones you know are correct, and down those you know are incorrect (or are subjective). Also, differences in syntax is not interesting. We know Python does with indentation what Ruby does with brackets and ends, and that @ is called self in Python. UPDATE: This is now a community wiki, so we can add the big differences here. Ruby has a class reference in the class body In Ruby you have a reference to the class (self) already in the class body. In Python you don't have a reference to the class until after the class construction is finished. An example: class Kaka puts self end self in this case is the class, and this code would print out "Kaka". There is no way to print out the class name or in other ways access the class from the class definition body in Python. All classes are mutable in Ruby This lets you develop extensions to core classes. Here's an example of a rails extension: class String def starts_with?(other) head = self[0, other.length] head == other end end Ruby has Perl-like scripting features Ruby has first class regexps, $-variables, the awk/perl line by line input loop and other features that make it more suited to writing small shell scripts that munge text files or act as glue code for other programs. Ruby has first class continuations Thanks to the callcc statement. In Python you can create continuations by various techniques, but there is no support built in to the language. Ruby has blocks With the "do" statement you can create a multi-line anonymous function in Ruby, which will be passed in as an argument into the method in front of do, and called from there. In Python you would instead do this either by passing a method or with generators. Ruby: amethod { |here| many=lines+of+code goes(here) } Python: def function(here): many=lines+of+code goes(here) amethod(function) Interestingly, the convenience statement in Ruby for calling a block is called "yield", which in Python will create a generator. Ruby: def themethod yield 5 end themethod do |foo| puts foo end Python: def themethod(): yield 5 for foo in themethod: print foo Although the principles are different, the result is strikingly similar. Python has built-in generators (which are used like Ruby blocks, as noted above) Python has support for generators in the language. In Ruby you could use the generator module that uses continuations to create a generator from a block. Or, you could just use a block/proc/lambda! Moreover, in Ruby 1.9 Fibers are, and can be used as, generators. docs.python.org has this generator example: def reverse(data): for index in range(len(data)-1, -1, -1): yield data[index] Contrast this with the above block examples. Python has flexible name space handling In Ruby, when you import a file with require, all the things defined in that file will end up in your global namespace. This causes namespace pollution. The solution to that is Rubys modules. But if you create a namespace with a module, then you have to use that namespace to access the contained classes. In Python, the file is a module, and you can import its contained names with from themodule import *, thereby polluting the namespace if you want. But you can also import just selected names with from themodule import aname, another or you can simply import themodule and then access the names with themodule.aname. If you want more levels in your namespace you can have packages, which are directories with modules and an __init__.py file. Python has docstrings Docstrings are strings that are attached to modules, functions and methods and can be introspected at runtime. This helps for creating such things as the help command and automatic documentation. def frobnicate(bar): """frobnicate takes a bar and frobnicates it >>> bar = Bar() >>> bar.is_frobnicated() False >>> frobnicate(bar) >>> bar.is_frobnicated() True """ Python has more libraries Python has a vast amount of available modules and bindings for libraries. Python has multiple inheritance Ruby does not ("on purpose" -- see Ruby's website, see here how it's done in Ruby). It does reuse the module concept as a sort of abstract classes. Python has list/dict comprehensions Python: res = [x*x for x in range(1, 10)] Ruby: res = (0..9).map { |x| x * x } Python: >>> (x*x for x in range(10)) <generator object <genexpr> at 0xb7c1ccd4> >>> list(_) [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] Ruby: p = proc { |x| x * x } (0..9).map(&p) Python: >>> {x:str(y*y) for x,y in {1:2, 3:4}.items()} {1: '4', 3: '16'} Ruby: >> Hash[{1=>2, 3=>4}.map{|x,y| [x,(y*y).to_s]}] => {1=>"4", 3=>"16"} Python has decorators Things similar to decorators can be created in Ruby, and it can also be argued that they aren't as necessary as in Python.

    Read the article

  • Can I call sitemesh struts tags from a decorator in freemarker?

    - by fool4jesus
    I know if you are using JSPs, you can call struts tags defined the normal way from a decorator, like this: <html> <body> <decorator:body /> </body> </html> but in the examples I always see using freemarker decorators, they will instead say: <html> <body> ${body} </body> </html> Is this the only way to include the pieces of the page from the decorator, or is it possible to use the same taglibs? To test it, I put sitemesh-decorator.tld into WEB-INF/lib and tried just using <@decorator.body /> but no joy there. I think I'm missing something here, but I'm not sure what it is.

    Read the article

  • Any thoughts on A/B testing in Django based project?

    - by Maddy
    We just now started doing the A/B testing for our Django based project. Can I get some information on best practices or useful insights about this A/B testing. Ideally each new testing page will be differentiated with a single parameter(just like Gmail). mysite.com/?ui=2 should give a different page. So for every view I need to write a decorator to load different templates based on the 'ui' parameter value. And I dont want to hard code any template names in decorators. So how would urls.py url pattern will be?

    Read the article

< Previous Page | 1 2 3 4 5  | Next Page >