Search Results

Search found 12 results on 1 pages for 'monkeypatching'.

Page 1/1 | 1 

  • Is monkeypatching considered good programming practice?

    - by vartec
    I've been under impression, that monkeypatching is more in quick and dirty hack category, rather than standard, good programming practice. While I'd used from time to time to fix minor issues with 3rd party libs, I considered it temporary fix and I'd submit proper patch to the 3rd party project. However, I've seen this technique used as "the normal way" in mainstream projects, for example in Gevent's gevent.monkey module. Has monkeypatching became mainstream, normal, acceptable programming practice? See also: "Monkeypatching For Humans" by Jeff Atwood

    Read the article

  • monkey patching time.time() in python

    - by user84584
    Hello guys, I've an application where, for testing, I need to replace the time.time() call with a specific timestamp, I've done that in the past using ruby (code available here: http://github.com/zemariamm/Back-to-Future/blob/master/back_to_future.rb ) However I do not know how to do this using Python. Any hints ? Cheers, Ze Maria

    Read the article

  • py2app prescripts

    - by yoav.aner
    The py2app documentation mentions prescripts, being run by __boot__.py prior to the main python script. I couldn't find a way to easily specify any prescript on the setup.py file or build process. I did however manage to 'hack' __boot__.py manually and add another _run(prescript) command before my main _run(main_script) and it seemed to work fine. It would however be much better using the standard py2app build process. What I'm essentially trying to do is monkey-patch my sites-packages.zip file prior to the main script being launched. The prescript essentially checks for updates on the server, and if there are any, downloads them, and then overwrites the site-packages.zip file. Much quicker than having to re-install the application from scratch. Any ideas?

    Read the article

  • To (monkey)patch or not to (monkey)patch, that is the question

    - by gsakkis
    I was talking to a colleague about one rather unexpected/undesired behavior of some package we use. Although there is an easy fix (or at least workaround) on our end without any apparent side effect, he strongly suggested extending the relevant code by hard patching it and posting the patch upstream, hopefully to be accepted at some point in the future. In fact we maintain patches against specific versions of several packages that are applied automatically on each new build. The main argument is that this is the right thing to do, as opposed to an "ugly" workaround or a fragile monkey patch. On the other hand, I favor practicality over purity and my general rule of thumb is that "no patch" "monkey patch" "hard patch", at least for anything other than a (critical) bug fix. So I'm wondering if there is a consensus on when it's better to (hard) patch, monkey patch or just try to work around a third party package that doesn't do exactly what one would like. Does it have mainly to do with the reason for the patch (e.g. fixing a bug, modifying behavior, adding missing feature), the given package (size, complexity, maturity, developer responsiveness), something else or there are no general rules and one should decide on a case-by-case basis ?

    Read the article

  • Ruby: add custom properties to built-in classes

    - by dreftymac
    Question: Using Ruby it is simple to add custom methods to existing classes, but how do you add custom properties? Here is an example of what I am trying to do: myarray = Array.new(); myarray.concat([1,2,3]); myarray._meta_ = Hash.new(); # obviously, this wont work myarray._meta_['createdby'] = 'dreftymac'; myarray._meta_['lastupdate'] = '1993-12-12'; ## desired result puts myarray._meta_['createdby']; #=> 'dreftymac' puts myarray.inspect() #=> [1,2,3] The goal is to construct the class definition in such a way that the stuff that does not work in the example above will work as expected. Update: (clarify question) One aspect that was left out of the original question: it is also a goal to add "default values" that would ordinarily be set-up in the initialize method of the class. Update: (why do this) Normally, it is very simple to just create a custom class that inherits from Array (or whatever built-in class you want to emulate). This question derives from some "testing-only" code and is not an attempt to ignore this generally acceptable approach.

    Read the article

  • Ruby: add custom properties to built-in classes

    - by dreftymac
    Question: Using Ruby it is simple to add custom methods to existing classes, but how do you add custom properties? Here is an example of what I am trying to do: myarray = Array.new(); myarray.concat([1,2,3]); myarray._meta_ = Hash.new(); # obviously, this wont work myarray._meta_['createdby'] = 'dreftymac'; myarray._meta_['lastupdate'] = '1993-12-12'; ## desired result puts myarray._meta_['createdby']; #=> 'dreftymac' puts myarray.inspect() #=> [1,2,3] The goal is to construct the class definition in such a way that the stuff that does not work in the example above will work as expected. Update: (clarify question) One aspect that was left out of the original question: it is also a goal to add "default values" that would ordinarily be set-up in the initialize method of the class. Update: (why do this) Normally, it is very simple to just create a custom class that inherits from Array (or whatever built-in class you want to emulate). This question derives from some "testing-only" code and is not an attempt to ignore this generally acceptable approach.

    Read the article

  • Monkeypatch a model in a rake task to use a method provided by a plugin?

    - by gduquesnay.mp
    During some recent refactoring we changed how our user avatars are stored not realizing that once deployed it would affect all the existing users. So now I'm trying to write a rake task to fix this by doing something like this. namespace :fix do desc "Create associated ImageAttachment using data in the Users photo fields" task :user_avatars => :environment do class User # Paperclip has_attached_file :photo ... <paperclip stuff, styles etc> end User.all.each do |user| i = ImageAttachment.new i.photo_url = user.photo.url user.image_attachments << i end end end When I try running that though I'm getting undefined method `has_attached_file' for User:Class I'm able to do this in script/console but it seems like it can't find the paperclip plugin's methods from a rake task.

    Read the article

  • C# monkey patching - is it possible?

    - by Adal
    Is it possible to write a C# assembly which when loaded will inject a method into a class from another assembly? If yes, will the injected method be available from languages using DLR, like IronPython? namespace IronPython.Runtime { public class Bytes : IList<byte>, ICodeFormattable, IExpressionSerializable { internal byte[] _bytes; //I WANT TO INJECT THIS METHOD public byte[] getbytes() { return _bytes; } } } I need that method, and I would like to avoid recompiling IronPython if possible.

    Read the article

  • Convert Google Analytics cookies to Local/Session Storage

    - by David Murdoch
    Google Analytics sets 4 cookies that will be sent with all requests to that domain (and ofset its subdomains). From what I can tell no server actually uses them directly; they're only sent with __utm.gif as a query param. Now, obviously Google Analytics reads, writes and acts on their values and they will need to be available to the GA tracking script. So, what I am wondering is if it is possible to: rewrite the __utm* cookies to local storage after ga.js has written them delete them after ga.js has run rewrite the cookies FROM local storage back to cookie form right before ga.js reads them start over Or, monkey patch ga.js to use local storage before it begins the cookie read/write part. Obviously if we are going so far out of the way to remove the __utm* cookies we'll want to also use the Async variant of Analytics. I'm guessing the down vote was because I didn't ask a question. DOH! My questions are: Can it be done as described above? If so, why hasn't it been done? I have a default HTML/CSS/JS boilerplate template that passes YSlow, PageSpeed, and Chrome's Audit with near perfect scores. I'm really looking for a way to squeeze those remaining cookie bytes from Google Analytics in browsers that support local storage.

    Read the article

  • Lua + SWIG Monkey Patching

    - by Tom J Nowell
    I have used SWIG to bind a set of classes to lua. The problem comes if I want to start monkey patching. e.g. game.GetEnemies1 = game.GetEnemies2 does not work as expected. The behaviour after that line is still consistent with the original GetEnemies1 not GetEnemies2. how do I combat this problem?

    Read the article

1