While Sending Html Mails from my web application Recieved Mails contains Symbols like &ldquo,&rdquo, ‘ |
Check with another constructor for htmlView:
ContentType mimeType = new System.Net.Mime.ContentType("text/html");
var htmlView = AlternateView.CreateAlternateViewFromString(bodyMessage,
mimeType);
|
Override a private JS method in Yii Grid View |
IMHO, acceptable options is 1 or 3
1:
+ Uses the core functionality
+ Only one request for script
- You can break something
3:
+ Safety (did not break anything)
- Additional request
- Need to connect in each file
I would choose option number 1
|
How can I extend a module, override a method, and still call the overridden method? |
Why something so complicated ? You could something like this
module URI
def first_level_domain
host.split('.').last(2).join('.')
end
end
uri = URI.parse('http://subdomain.domain.com/section/page.html')
uri.first_level_domain
# => "domain.com"
|
Is there a way in javascript to give access to variable inside a prototype private (using the Module JS Pattern) method |
Nope. The two strategies are somewhat incompatible. Which is why private
properties are usually public, but prefixed with an underscore, when using
prototypes.
Namespace.Apple = function(p_color){
this._color = p_color;
};
Namespace.Apple.prototype.eat = function(){
console.log("I'm eating a " + this._color + " apple !")
};
This tells JS developers using this code that they should not mess with the
_color property, as it's for internal use.
That said, you have other big problems here...
Namespace.Apple = function(p_color){
var AppleInstance = this; //clarity..
AppleInstance.color = p_color;
return {
/**************
/ Public method
/**************/
//Here, we only return an access to the Method Eat
Eat : NameSpace.Apple.prototype.Eat
}
}
This do
|
private method in python |
Python doesn't have the concept of 'private' the way many other languages
do. It is built on the consenting adult principle that says that users of
your code will use it responsibly. By convention, attributes starting with
a single or double leading underscore will be treated as part of the
internal implementation, but they are not actually hidden from users.
Double underscore will cause name mangling of the attribute name though.
Also, I'd note for you that self is only special by convention, not by any
feature of the language. For instance methods, when called as members of
an instance, they are implicitly passed the instance as a first argument,
but in the implementation of the method itself, that argument can
technically be named any arbitrary thing you want. self is just the con
|
What does it mean for a private method to be only accessible from its own class in python? |
class Car(object):
def __reset_odometer(self):
pass
def reset(self):
self.__reset_odometer() # This is valid.
turbocar = Car()
turbocar.reset()
turbocar.__reset_odometer() # This is invalid. __reset_odometer is only
accessible from Car methods.
|
Is there a Python method to access all non-private and non-builtin attributes of a class? |
Actually, it would be unpythonic for such function to exists - because
"officially" there is no private or protected fields/properties in Python.
While it makes sense to throw away module attributes with leading
underscores (which are usually some implementation details) during import *
from some module*, it is not useful in context of any other object.
So, if you need to list only "public" methods/attributes of an object, just
iterate through result of dir and drop names with leading underscores.
* "during import * from some module'"
Usually it is not the best practice. Consider the next example:
module A has a1 and a2 defined
module B has b1 and b2 defined
This code in module C works as expected:
from A import a1, a2
from B import *
Imagine we add function a1 in module B. N
|
Can't override method (Flash Builder) - #1065 Variable Override is not defined |
I solved it myself, kind of an strange error, but oh well. I had to press
the cross icon that says "Remove Launch" and "Remove All Terminated
Launches" next to the stop icon in the console tab. I even restarted my PC,
tried project>clean, and restarted Flash Builder several times but only
that fixed it. I leave this here just in case anyone meets the same error.
|
why is there a need to override hashcode if I override equals method in java? |
Go to this link
The hashcode is used to maintain the contract and uniquely identify each
object in hashmap or hashtable.
|
python cannot call module method from staticmethod? |
Don't start names with double underscores. Any identifier found in a class
statement, starting with at least 2 underscores and ending with less than 2
underscores, gets _Classname prepended to it, where Classname is the name
of the class. This is supposed to provide limited support for private-ish
variables, but using it is often considered bad practice.
|
Why I cannot use python module concurrent.futures in class method? |
From the docs:
The ProcessPoolExecutor class is an Executor subclass that uses a pool
of processes to execute calls asynchronously. ProcessPoolExecutor uses
the multiprocessing module, which allows it to side-step the Global
Interpreter Lock but also means that only picklable objects can be
executed and returned.
Try a ThreadPoolExecutor
Update
I looked over your code again, the problem is that the function -
make_readdb - is a member of the class test. Can you refactor and pull this
function out?
|
Trying to override _beforeSave method and Magento calling both custom method and core method as well |
The same question was answered here. The main idea is that if you copied
the method from the original class, this line
parent::_beforeSave($customer) will call the original method.
You can replace that line with
Mage_Eav_Model_Entity_Abstract::_beforeSave($customer);
thanks @ProxiBlue for the idea.
|
How can I override private variable by passing it as a parameter in a class member function? |
In Java, all arguments are passed by value. That means that the value of
image1 cannot be changed in the called method; only the local copy of the
reference can be changed. You could do something like this:
@Override
protected void onResume() {
super.onResume();
image1 = onUpdate();
}
private ImageView onUpdate() {
ImageView image = new ImageView(this); // I would like to override
member variable image1
// update image parameters
return image;
}
|
Joomla module CSS override |
Both the selectors are completely different, what you are doing with this
joomla_tables is you target the table where joomla targets tr and td so you
need
.joomla_tables tr,
.joomla_tables td {
border: 0;
padding: 5px;
}
Now the above selector will select all tr and td which are nested inside
element having a class joomla_tables.
Joomla targets tr and td, you are targeting table, so using your selector,
it does get rid of the table border but you will still see it, as td has
the border, so just use the selector I provided and it will target the
elements perfectly.
For making it more stricter, you can use
table.joomla_tables tr,
table.joomla_tables td {
/* Styles goes here */
}
Note: tr don't have borders and paddings, it's the td which has
borders (It can have bord
|
Extend not override module in TypeScript |
You can do it with vars:
module library {
export var widget = function () {
//
}
}
module library{
if(library.widget){
return;
}
else{
library.widget = function(){
}
}
}
Try it.
|
Is it possible to override #initialize in a Ruby module? |
Would it satisfy to have a conditional call in Foo's initialize that only
calls an included method if it's present?
module Mo
def initialize_extra
puts "Hello from Mo"
end
end
class Foo
include Mo
def initialize
if defined? initialize_extra
initialize_extra
else
puts "Hello from Foo"
end
end
end
x = Foo.new
|
Node JS override standard module |
I feel obliged to strongly warn you against overriding native functions.
That being said, this will work:
main.js:
var fs = require('fs'),
oldReadFile = fs.readFile;
fs.readFile = function (filename, options, callback) {
console.log('hey!');
oldReadFile(filename, options, callback)
};
var other = require('./other');
other.test();
other.js:
var fs = require('fs');
exports.test = function () {
fs.readFile('./main.js', {encoding: 'utf8'}, function (err, data) {
console.log(err, data);
});
};
You'll need to wrap your user's script with your own to first override what
you want.
|
Override module in magento, no result |
Action controllers are instantiated and resolved differently than the other
main class types in Magento (blocks, helpers, and models):
Rewrite via config XML can be achieved but via a different mechanism and
convention
By intentional design PSR-0-like autoloading does not work for controller
classes in Magento.
It is necessary to add a separate module's controllers directory under the
overwritten module's frontName:
<frontend><!-- match to original module config -->
<routers>
<newsletter><!-- match to original module config-->
<args>
<modules>
<MageNS
before="Mage_Newsletter">MageNS_Module</MageNS>
<!--
The above points to app
|
How do I override an attr_accessor getter from a module? |
Are you sure you want the attr_accessor? Wouldn't an attr_writer suffice?
require 'active_support/all'
module HasUrl
extend ActiveSupport::Concern
included do
attr_writer :bar
end
def bar
0
end
end
class Foo
include HasUrl
end
p Foo.new.bar
Anyhow, if you really want to use attr_accessor, this should work:
require 'active_support/all'
module HasUrl
extend ActiveSupport::Concern
included do
attr_accessor :bar
define_method :bar do
0
end
end
end
class Foo
include HasUrl
end
p Foo.new.bar
|
Angular Module Private Members |
No, it is not possible to create "private" services in the current version
of AngularJS. There were some discussions about support for private
(module-scoped) services but it is not implemented.
As of today all the services exposed on a given module are visible to all
other modules.
|
Override Dagger Module in Robolectric Tests |
I suppose you are creating the object graph in Application.onCreate(). If
that's the case and if you're using Robolectric 2, you can create a test
application as explained here and create an object graph for your tests
with your test modules (prod and test application must inherit from the
same base class). For more info on this, you can have a look here. Hope it
helps.
|
Magento Override Community Controller from a local module |
Looks almost correct.
Try replacing
<Namespace_Mylocalmodule
before="Namespace_Mycommunitymodule">Namespace_Mylocalmodule_Mycommunitymodule</Namespace_Mylocalmodule>
by
<Namespace_Mylocalmodule
before="Namespace_Mycommunitymodule">Namespace_Mylocalmodule</Namespace_Mylocalmodule>
and the class name
Namespace_Mylocalmodule_Mycommunitymodule_IndexController by
Namespace_Mylocalmodule_IndexController as of its filename and folder if
needed.
|
Can I choose where to publish my NPM module - either to the public or a private repo? |
In the package.json file:
{
"publishConfig": {
"registry":"https://private.internal.registry.mycompany.local/"
}
}
The npmrc stuff is a bit tricky to manage. We're working on rewriting a
bunch of stuff so that all those configs will be scoped to a specific
registry, but it'll be a while before that's done.
|
How can I share module-private data between 2 files in Node? |
I'd like some vars from one file to be accessible from other file, but
not from the files external to the module
Yes, it is possible. You can load that other file into your module and hand
it over a privileged function that offers access to specific variables from
your module scope, or just hand it over the values themselves:
index.js:
var foo = 'some value';
module.exports.additional = require('./additional.js')(foo);
module.exports.extra = require('./extra.js')(foo);
extra.js:
module.exports = function(foo){
// some magic here
var bar = foo; // foo is the foo from index.js
// instead of assigning the magic to exports, return it
};
additional.js:
module.exports = function(foo){
// some magic here
var qux = foo; // foo is the foo from index.js again
// instead of a
|
Javascript revealing Module, return private field |
The "changename" function only updates the "name" property of the object;
it doesn't mess with the local variable called "name" that's present in the
closure, and it doesn't mess with "foo". Thus the "foo" property of the
object retains it's initial value no matter what you pass to "changename".
So step by step:
The variable "vm2" is initialized by that anonymous function. It's value is
an object with three properties.
The call to the "changename" function is made via the property reference on
"vm2". That will cause this to be bound to that object while "changename"
executes.
Inside "changename", the "name" property of the object referenced by this
(which is the "vm2" object) is updated to whatever value is passed as the
parameter.
Note that once "vm2" is initialized, nothing in that
|
Accessing Private Methods from Module Functions in Ruby |
If you want to call methods directly on the module (e.g., Party.pooper),
you have to define the methods using self
module Party
def self.pooper
enjoy
end
private
def self.enjoy
puts "wahoo!"
end
end
Party.pooper #=> wahoo!
Generally though, one primary purpose of modules is they are meant to be
added to a class using include or extend.
module Party
def pooper
enjoy
end
private
def enjoy
puts "wahoo!"
end
end
Here's an extend example that shows the module methods being added as class
methods
class Diaper
extend Party
end
Diaper.pooper #=> wahoo!
Here's an include example that shows the module methods being added as
instance methods
class Toilet
include Party
end
t = Toilet.new
t.pooper #=> wahoo!
|
How to mock the return of a public method called in a private method inSpring |
If you are trying to test Service, then you have to mock oracleDao as well
and make its getSubjectOracle() method return the String you want.
I'm assuming you aren't testing getSubject() but a method that calls
getSubject().
|
RSpec. How to test method with nested private method (mocking/stubbing)? |
I would just test the default method without regards to the fact that it
uses a private method to do its work. Figure out what the expected outputs
for given inputs are.
The primary reason I say this is that it makes your tests more robust. You
can change the internal workings of the default method, maybe even
eliminating the private method, without changing the test.
The only thing I would think about mocking is whatever the settings object
is in the private merge_op method. That object is effectively an input to
the default method.
|
Can I add a method to a requirejs module used as dependency in another module and have it available every time the module is loaded as dependency? |
Short answer:
Yes. The module needs to be an object/instance (not a class) and it will
work with requirejs.
Long answer:
When you require a module as a dependence for the first time Requirejs
generates an object, and for the next times you requires the module
Requirejs will return the object it generated the first time. So all the
times you require a module you get always the same reference of the object.
With
define([], function () {
var app = {
//my methods.
};
return app;
});
and
define(['app'], function (app) {
app.newMethod = function (){
// ...
};
});
you can use app like this:
define(['app'], function (app) {
app.newMethod();
});
But injecting methods from one object to an other is a really bad practice.
If you need something f
|
How to access Parameter Value of public method inside private method |
public partial class EditQuestionMaster : Form
{
DbHandling db = new DbHandling();
int qid; // here is the class variable
public EditQuestionMaster(int qid_value)
{
InitializeComponent();
this.qid = qid_value; // set the value here
string subNtop = db.GetEditSubNTopic(qid_value);
string[] subNtopData = subNtop.Split('~');
cmbSubject.Text = subNtopData[2];
}
private void button1_Click(object sender, EventArgs e)
{
qid // use it here
|
How to access method defined in a module inside another module in Ruby? |
You've define the method as an instance method. If you want to use the
method without an instance, it should be a class method on the module:
module A
module B
def self.whoa
puts 'Whoa!'
end
end
end
1.9.3p327 :009 > A::B.whoa
Whoa!
=> nil
|
How to resolve The method addView(View, int, LinearLayout.LayoutParams) of type YourLayout must override or implement a supertype method |
Change it to
addView(View child, int index, ViewGroup.LayoutParams params)
Looks like somehow you imported LinearLayout.LayoutParams instead of
ViewGroup.LayoutParams and ViewGroup does not have a method with a
signature like that.
ViewGroup.addView()
Make sure your method is using the right kind of LayoutParams
|
How to override prestashop's default front-office template and controller in module |
Modules can work like you ask only if there's an HOOK inside the
template/controller that allow you to run your customized function. Look if
you have a chance of hooking your module somewhere by watching on the list
showed inside
backoffice > modules > position
the Address controllers hasn't got any Hook if i recall well, so you have 3
ways to edit its functionality:
1) go for an (imho) horrible client-side modification, by an heavy usage of
jquery/ajax call to perform the action you need. Place the code by using a
module that only add your js script in the header by using the hookHeader()
function. Since this hook it's always called in all the site you can
exploit the missing hook in the address template.
2) add yourself an hook inside the Controller and the template by follow
|
Revealing Module Pattern adding submodule and accessing private functions |
Unless you are defining the submodule in the same lexical scope as the
parent module, and doing some kind of closure over the "parent" private
functions, you can't. You made the functions private, and so you need to
be able to see them to call them. And you can't see them when defining a
sub-module in a different place from the parent module. The only way you
will get your desired structure is like this:
var Module = (function () {
function B() {
console.log("B");
};
var Utils = (function () {
function C() {
B();
};
return {
C: C
}
})()
return {
Utils: Utils
};
})();
|
public const doesn't override private const function? |
make sure navmesh is const in the context of your call. But I would not
recommend const_cast it, you might read this
http://www.parashift.com/c++-faq/overview-const.html .
|
Import python module over the internet/multiple protocols or dynamically create module |
In principle, yes, but all of the tools built-in which kinda support this
go through the filesystem.
To do this, you're going to have to load the source from wherever, compile
it with compile, and exec it with the __dict__ of a new module. See below.
I have left the actually grabbing text from the internet, and parsing uris
etc as an exercise for the reader (for beginners: I suggest using requests)
In pep 302 terms, this would be the implementation behind a
loader.load_module function (the parameters are different). See that
document for details on how to integrate this with the import statement.
import imp
modulesource = 'a=1;b=2' #load from internet or wherever
def
makemodule(modulesource,sourcestr='http://some/url/or/whatever',modname=None):
#if loading from the internet, you'd
|
why is python argparse giving the help for imported module rather than current module? |
Your tone module defines an argument parser at the module level and prints
the help message as it parses your command line arguments
If you only want the parsing to take place if tone is being run as a
script, move the parser.parse_args() call to your __main__ test block:
if __name__ == '__main__':
# run as a script, not imported as a module
args = parser.parse_args()
|
Why does this method override inside a method fail? |
you cannot call the constructor in the later calls of your other overloaded
constructor.
the call to constructor of the same class or super class has to be the
first statement in the constructor.
and you have to call it by this() or super()
public Hello(int value){
this();
this.value=value;
title = "Hello";
}
|
python c api not able to import any module into the newly created module |
Resolved this in a different way :
The problem is that the __dict__ attribute of a module is read-only.
I am using the python/c api for 2.7.5. After using PyModule_New there was
no provisioning to execute any code into the __dict__ for imports in the
api. So I used a different approach.
I created a module using python code rather than the python/c api. Which
has the provision to to execute some code into a modules dictionary exec
'import sys' in mymod.__dict__.
The sys import provides the newly created module to have access to
sys.modules which has all the available modules. So when I do another
import, the program knows where to look up the path for the import. Here is
the code.
PyRun_SimpleString("import types,sys");
//create the new module in python
PyRun_SimpleString("mymod = t
|
Python: where is the method listdir because there is no "def listdir()" in module os.py? |
The listdir method is actually implemented in a C module, and is imported
dynamically depending on the operating system environment. You can see the
imports near the top of os.py, in blocks like this :
if 'posix' in _names:
name = 'posix'
linesep = '
'
from posix import *
Then the file posixmodule.c in the Python source has the POSIX
implementation of listdir :
https://github.com/python-git/python/blob/master/Modules/posixmodule.c#L2068
(and likewise for other OSes).
|