monkeypatching

MonkeyPatching: PrimeFaces widgets extend/override

≯℡__Kan透↙ 提交于 2019-12-30 07:17:11
问题 I'm currently using (it's working fine) PrimeFaces.widget.OverlayPanel.prototype._old_init = PrimeFaces.widget.OverlayPanel.prototype.init; PrimeFaces.widget.OverlayPanel.prototype.init = function(cfg) { this._old_init(cfg); this.align(); } but I'd like to use something more readable and 'jQuery-ish' like this completely invented unrealistic code: PrimeFaces.widget.OverlayPanel.patch( { init: function(cfg) { super.init(cfg); this.align(); }, show: function() { console.log('blah blah blah');

monkey patching vs class_eval?

社会主义新天地 提交于 2019-12-30 03:59:06
问题 class String def hello "world" end end String.class_eval { def world "hello" end } "a".world => "hello" "b".hello => "world" They seems to do the same thing -- adding a method to a existing class. So what's the difference? 回答1: With class_eval you can do more dynamic things: >> met = "hello" #=> "hello" >> String.class_eval "def #{met} ; 'hello' ; end" #=> nil >> "foo".hello #=> "hello" 回答2: class_eval do conceptually class reopening (or monkey patching). There are mostly syntactic

Conjugate transpose operator “.H” in numpy

五迷三道 提交于 2019-12-29 04:38:27
问题 It is very convenient in numpy to use the .T attribute to get a transposed version of an ndarray . However, there is no similar way to get the conjugate transpose. Numpy's matrix class has the .H operator, but not ndarray. Because I like readable code, and because I'm too lazy to always write .conj().T , I would like the .H property to always be available to me. How can I add this feature? Is it possible to add it so that it is brainlessly available every time numpy is imported? (A similar

Is “monkey patching” really that bad? [closed]

馋奶兔 提交于 2019-12-28 09:18:30
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago . Some languages like Ruby and JavaScript have open classes which allow you to modify interfaces of even core classes like numbers, strings, arrays, etc. Obviously doing so could confuse others who are familiar with the API but is there a good reason to avoid it otherwise,

How can I modify the XMLHttpRequest responsetext received by another function?

▼魔方 西西 提交于 2019-12-28 03:38:13
问题 I am trying to modify the responseText received by a function that I cannot modify. This function creates a XMLHttpRequest that I can attach to, but I have been unable to "wrap" the responseText in a way that allows me to modify the content before the original function receives it. Here's the full original function: function Mj(a, b, c, d, e) { function k() { 4 == (m && 'readyState' in m ? m.readyState : 0) && b && ff(b) (m) } var m = new XMLHttpRequest; 'onloadend' in m ? m.addEventListener(

Why the amount of greenlets will impact the elapsed time of the responses

独自空忆成欢 提交于 2019-12-24 18:53:22
问题 I'm using Python coroutine library gevent and monkey patch to increase the concurrency of http requests. But I noticed the elapsed time of the responses increased while the concurrency increased. Below the sample code: import gevent from gevent import monkey import requests monkey.patch_all(thread=False) def action(): resp = requests.get("https://www.google.com") if resp.status_code == 200: print resp.elapsed.total_seconds() jobs = [] for i in range(100): jobs.append(gevent.spawn(action))

Add SQL 2014 support to activerecord-sqlserver-adapter

烂漫一生 提交于 2019-12-24 17:07:32
问题 We've be using the activerecord-sqlserver-adapter gem with sqlserver 2008 and everything works great. We just tried to deploy our Rails 3 app against a new sqlserver 2014 db and I get an error that says: Currently, only 2005, 2008, 2010, 2011, and 2012 are supported. We got back Microsoft SQL Server 2014 - 12.0.2000.8 (X64) A quick look at github shows that a small update was recently made to the sqlserver_adapter.rd to resolve this issue. I tried to update the gem and it turned into a bit of

How to mock a function, that is imported within an imported method from different module

烂漫一生 提交于 2019-12-23 09:01:36
问题 I got the following function to test: my_package.db_engine.db_functions.py: from ..utils import execute_cmd from my_package.db_engine.db_functions import dbinfo def dbinfo(db_name): params = (cmd_cfg.DB, add_pj_suffix(db_name)) cmd = get_db_cmd_string(cmd_cfg.DBINFO, params=params) cmd_result = execute_cmd(cmd) result_dict = map_cmd_output_to_dict(cmd_result) return result_dict This function takes the name of a database, then builds a command string from it and executes this command as

Retrieving address of native base class with ctypes

醉酒当歌 提交于 2019-12-23 07:07:34
问题 I want to be able to pass a certificate to Python's ssl library without requiring a temporary file. It seems that the Python ssl module cannot do that. To work around this problem I want to retrieve the underlying SSL_CTX struct stored in the ssl._ssl._SSLContext class from the native _ssl module. Using ctypes I could then manually call the respective SSL_CTX_* functions from libssl with that context. How to do that in C is shown here and I would do the same thing via ctypes. Unfortunately, I

Monkey patching ActiveResource::Errors

百般思念 提交于 2019-12-23 03:16:14
问题 I've come across an issue with ActiveResource that has been resolved and was trying to monkey patch it into my application without much luck. I've added a file in config/initializers/ containing the following: class ActiveResource::Errors < ActiveModel::Errors # https://github.com/rails/rails/commit/b09b2a8401c18d1efff21b3919ac280470a6eb8b def from_hash(messages, save_cache = false) clear unless save_cache messages.each do |(key,errors)| errors.each do |error| if @base.attributes.keys.include