我正在使用C模块扩展我的Python程序,该模块使用GstPhotography接口进行GStreamer.我的C模块编译得很好,但是当我尝试从Python运行它时,我收到此错误:
$python Program.py
Traceback (most recent call last):
File "Program.py", line 10, in <module>
import MyPythonClass
File "/path/MyPythonClass.py", line 19, in <module>
import my_c_module
ImportError: /path/my_c_module.so: undefined symbol: gst_photography_get_type
Run Code Online (Sandbox Code Playgroud)
我不太确定这意味着什么,因为我从不在my_c_module.cpp中使用gst_photography_get_type - 它是在GstPhotography源代码中实现的函数.
我可能会偏离正轨,但我想知道是否可以使用JQuery 预过滤器功能并在Ajax Success中分析响应数据,并根据我返回的JSON中某些元素的存在有条件地转发到error我的ajax调用中的事件处理程序(错误消息).
如果这是为页面中的任何ajax函数全局设置的话会很好.
也许这不是解决这个问题的最好方法; 如果有人有其他想法,请告诉我!
预滤器:
//only run prefilter on ajax calls expecting JSON back in response, would this
//be the right way to do this?
$.ajaxPrefilter( "json", function( options, originalOptions, jqXHR ) {
jqXHR.success(function(data, textStatus, jXHR) {
if( hasErrors(data) ) {
//forward to error event handler?
}
});
});
Run Code Online (Sandbox Code Playgroud)
Ajax调用:
$.ajax({
type: "POST",
data: {
theData: "someData"
},
url: theUrl,
dataType: 'json',
cache: false,
success: function (data, textStatus, jqXHR) {
//do stuff on …Run Code Online (Sandbox Code Playgroud) 我正在使用Ruby v1.9.2和Ruby on Rails v3.2.2 gem.我有以下模块
module MyModule
extend ActiveSupport::Concern
included do
def self.my_method(arg1, arg2)
...
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想为类方法 添加别名my_method.所以,我说了以下(不工作)代码:
module MyModule
extend ActiveSupport::Concern
included do
def self.my_method(arg1, arg2)
...
end
# Note: the following code doesn't work (it raises "NameError: undefined
# local variable or method `new_name' for #<Class:0x00000101412b00>").
def self.alias_class_method(new_name, old_name)
class << self
alias_method new_name, old_name
end
end
alias_class_method :my_new_method, :my_method
end
end
Run Code Online (Sandbox Code Playgroud)
换句话说,我想在Module某种程度上扩展这个类,以便添加一个alias_class_method可用的方法MyModule.但是,我想让它工作 …
假设有一个类,其所有构造函数都声明为private.
例如.:
public class This {
private This () { }
public someMethod( ){
// something here
}
// some more-- no other constructors
}
Run Code Online (Sandbox Code Playgroud)
据我所知,将所有构造函数设为私有类似于将"This"类声明为final - 这样它就无法扩展.
但是,我得到的Eclipse消息给我的印象是这是可能的 - 一个全构造函数 - 私有类可以扩展.看看这个:
当我尝试用类似的东西扩展这个类
public class That extends This {
...
}
Run Code Online (Sandbox Code Playgroud)
Eclipse给出了一个错误:" 隐式超级构造函数This()对默认构造函数不可见.必须定义一个显式构造函数. "
当我定义自己的构造函数时:
public class That extends This {
That () {..}
...
}
Run Code Online (Sandbox Code Playgroud)
这次我得到:" 隐式超级构造函数This()对于默认构造函数是不可见的.必须显式调用另一个构造函数. "
有没有办法绕过这个 - 扩展一个所有构造函数都是私有的类?
如果有,怎么样?
如果不是,那么阻止一个类被i扩展的区别是什么?)使它的构造函数变为私有,以及ii.将它定义为final?
注意:我看到Java中的构造函数可以是私有的吗?在其他一些讨论中.
我试图通过一种额外的方法扩展Laravel的Auth Guard类,所以我能够Auth::myCustomMethod()在最后调用.
在文档部分扩展框架之后,我一直坚持如何正确地执行此操作,因为Guard类本身没有自己的IoC绑定,我可以覆盖它.
这是一些代码,展示了我正在尝试做的事情:
namespace Foobar\Extensions\Auth;
class Guard extends \Illuminate\Auth\Guard {
public function myCustomMethod()
{
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
现在我应该如何注册Foobar\Extensions\Auth\Guard要使用的扩展类而不是原始类,Illuminate\Auth\Guard所以我能够以Auth::myCustomMethod()与例如相同的方式调用Auth::check()?
一种方法是替换中的Auth别名,app/config/app.php但我不确定这是否真的是解决这个问题的最佳方法.
顺便说一句:我正在使用Laravel 4.1.
我正在扩展MongoCollection类,我收到了这条消息.
Db\Mongo\Collection :: save()的声明应该与MongoCollection :: save()的声明兼容
据我所知,这通常是一个婴儿车宣言未命中赛.
Php.net说,婴儿车是:
public mixed save(array | object $ a [,array $ options = array()])
我已尝试以下所有方法来解决此问题:
public function save(array &$a, array $options = array())
public function save($a, array $options = array())
public function save(&$a, array $options = array())
public function save($a, $options = array())
public function save($a = array(), $options = array())
Run Code Online (Sandbox Code Playgroud)
还有很多其他人,我似乎无法匹配这种类型.
有没有人对如何解决这个错误有任何想法?你如何将一个婴儿车声明为数组对象?
我正在尝试扩展HashServiceProviderlaravel 5中的默认Bcrypt ,以改为使用SHA1加密.
使用这个问题的答案:如何在Laravel 4中使用SHA1加密而不是BCrypt?和http://laravel.com/docs/5.0/extending#container-based-extension上的官方文档,我设法编写以下代码:
在app/Providers/ShaHashServiceProvider.php中
use App\ShaHasher;
use Illuminate\Hashing\HashServiceProvider;
class ShaHashServiceProvider extends HashServiceProvider {
public function boot()
{
parent::boot();
$this->app->bindShared('hash', function()
{
return new ShaHasher();
});
}
}
在app/ShaHasher.php中
use Illuminate\Contracts\Hashing\Hasher as HasherContract;
class ShaHasher implements HasherContract {
public function make($value, array $options = array()) {
$value = env('SALT', '').$value;
return sha1($value);
}
public function check($value, $hashedValue, array $options = array()) {
return $this->make($value) === $hashedValue;
}
public … 故事:我正在尝试从C到Python的接口,以便为现有的Python代码使用更快的C计算速度.我已经取得了一些成功,也通过NumPy数组 - 但现在似乎有一个问题,我无法解决它.这是代码:
#define FORMAT_VALUE_T "d"
char format_buffer[32];
typedef struct
{
PyObject_HEAD
PyArrayObject *invmat;
unsigned order;
value_t weight, *buffer;
} Det;
typedef double value_t;
typedef struct
{
PyObject_HEAD
Det *det;
value_t *row, *covs, ratio, star;
} DetAppendMove;
static int append_init(DetAppendMove *self, PyObject *args, PyObject *kwds)
{
value_t star, *temp;
PyArrayObject *row, *col;
PyObject *result = Py_BuildValue("(i)",1);
Det *dete;
snprintf(format_buffer, sizeof(format_buffer), "%s%s", "O!O!O!", FORMAT_VALUE_T);
if (PyArg_ParseTuple(args, format_buffer, &DetType, &dete, &PyArray_Type, &row, &PyArray_Type, &col, &star))
{
self->det = dete;
temp = (value_t*)self->det->buffer; …Run Code Online (Sandbox Code Playgroud) 我正在进行坦克游戏,为了避免冗余,我正在进行课程扩展.我的MenuPanel看起来像这个atm(我只编写了对问题很重要的代码)(knop = dutch for button)
public class MenuPanel extends JPanel implements ActionListener
{
private JButton playKnop, highScoreKnop, quitKnop, HTPKnop;
private ImageIcon play, HS, quit, HTP;
private Tanks mainVenster;
public MenuPanel(Tanks mainVenster)
{
this.mainVenster = mainVenster;
this.setLayout(null);
int x = 95;
int width = 200;
int height = 50;
play = new ImageIcon(PlayPanel.class.getResource(/buttons/PLAY.png));
playKnop = new JButton(play);
playKnop.setBounds(x, y, width, height);
playKnop.addActionListener(this);
HS = new ImageIcon(PlayPanel.class.getResource(/buttons/HS.png));
highScoreKnop = new JButton(HS);
highScoreKnop.setBounds(x, 460, width, height);
highScoreKnop.addActionListener(this);
HTP = new ImageIcon(PlayPanel.class.getResource(/buttons/HTP.png));
HTPKnop = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在不同的文件中扩展导入的枚举,并在另一个不同的文件中使用该扩展的枚举。
base.enum.ts
export enum MyEnum {
a = "Foo"
}
Run Code Online (Sandbox Code Playgroud)
扩展.enum.ts
import { MyEnum } from './base.enum';
declare module './base.enum' {
export enum MyEnum {
b = "Bar"
}
}
Run Code Online (Sandbox Code Playgroud)
在 index.ts 中使用
import { MyEnum } from './base.enum';
import './extended.enum'; // side-effects import (no usage of export)
console.log(MyEnum.a); // prints "Foo" as expected
console.log(MyEnum.b); // prints undefined, instead of the expected "Bar"
Run Code Online (Sandbox Code Playgroud)
(我在支持字符串值枚举的 TypeScript 2.4.2 中这样做)
我已经使用这个和这个SO 问题作为参考,并在 GitHub …