我正在尝试使用不同版本的cc在两台不同的机器上编译相同的C文件.
gcc版本3.2.3说 warning: 'foo' was declared implicitly 'extern' and later 'static'
gcc版本4.1.2说 error: static declaration of 'foo' follows non-static declaration
两者都有相同的CFLAGS.我想让gcc 4.1.2表现得像gcc 3.2.3,也就是说,找到一个可以将这个错误变成一个警告的选项.
我有一个重命名的js文件,我必须在我的每个PHP页面调用.现在我想使用shell替换旧名称.我用的是这个: -
sed -i ’s/old/new/g’ *
Run Code Online (Sandbox Code Playgroud)
但这会产生以下错误: -
sed: -e expression #1, char 1: unknown command:
Run Code Online (Sandbox Code Playgroud)
现在我该如何替换?
你知道一个JavaScript库,它为集合实现一个通用的Iterator类(可以是Arrays还是一些抽象的Enumerable),它具有一整套功能,比如Google Common 或Apache Commons?
编辑:Enumerable#each不是迭代器类.我正在寻找一个Iterator,它可以让我们写出类似的东西:
var iterator = new Iterator(myCollection);
for (var element = iterator.next(); iterator.hasNext(); element = iterator.next()) {
// iterator
}
Run Code Online (Sandbox Code Playgroud)
编辑:mamoo提醒我们Mozilla的Javascript 1.7中的Iterator实现.因此,现在的目标是在Javascript 1.5(ECMA 4)中找到此迭代器函数的实现.
Edit2:为什么在库(和ECMA 5)提供each方法时使用迭代器?首先,因为each通常会混淆this因为回调是call-ed(这就是为什么each在Prototype中接受第二个参数).然后,因为人们对for(;;)构造比对.each(callback)构造更熟悉(至少在我的领域).最后,因为迭代器可以迭代普通对象(参见JavaScript 1.7).
编辑3:我接受了npup的anwser,但这是我的镜头:
function Iterator(o, keysOnly) {
if (!(this instanceof arguments.callee))
return new arguments.callee(o, keysOnly);
var index = 0, keys = [];
if (!o || typeof o != "object") return;
if …Run Code Online (Sandbox Code Playgroud) 我有一个包含javascript对象序列化的php字符串:
$string = '{fu:"bar",baz:["bat"]}';
Run Code Online (Sandbox Code Playgroud)
当然,实际的字符串要复杂得多,但仍然是格式良好的javascript.这不是标准的JSON,因此json_decode失败.你知道任何解析这个字符串并返回php关联数组的php库吗?
我想fubar.log从shell(bash)globbing字符串中删除特定的文件名(例如)*.log.我尝试过的任何东西似乎都不起作用,因为globbing不使用标准RE集.
测试用例:目录包含
fubar.log
fubaz.log
barbaz.log
text.txt
Run Code Online (Sandbox Code Playgroud)
并且只能fubaz.log barbaz.log通过glob扩展.
与返回引用相比,返回数组或哈希的优缺点是什么?
是否会影响内存或执行时间?
两者之间的功能差异是什么?
sub i_return_an_array
{
my @a = ();
# push things in @a;
return @a;
}
sub i_return_a_ref
{
my @a = ();
# push things in @a;
return \@a;
}
my @v = i_return_an_array();
my $v = i_return_a_ref();
Run Code Online (Sandbox Code Playgroud) 我有这个测试页面:http://jsfiddle.net/VWnm9/7/.所有运行IE7或IE8的计算机上的图像都正确褪色,除了一台运行IE7的计算机,即使在非文本模式下也不会淡化花朵.
该页面是:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<style type="text/css">
body {
background: blue;
}
img {
filter: alpha(opacity=10);
opacity: 0.1;
}
</style>
</head>
<body>
<img src="http://upload.wikimedia.org/wikipedia/commons/c/c3/Extracted_pink_rose.png" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
有人知道为什么吗?
使用Symfony 2.7和Doctrine 2.5,我有
Alsciende\MyBundle\Model\CycleInterfaceAlsciende\MyBundle\Entity\Cycle实现接口的抽象类AppBundle\Entity\Cycle,它扩展了抽象类并实现了接口resolve_target_entities用于将接口映射到最终类这个系统运行良好,我能够创建数据库并在AppBundle中实现一些CRUD,直接操作目标实体.
但是,我现在想通过接口操作MyBundle中的目标实体.我需要获取其存储库:
$this->getDoctrine()->getRepository('Alsciende\MyBundle\Model\CycleInterface');
Run Code Online (Sandbox Code Playgroud)
但我得到了例外
class 'Alsciende\MyBundle\Model\CycleInterface' does not exist
Run Code Online (Sandbox Code Playgroud)
如何获取目标实体的存储库?也就是说,如何直接调用ResolveTargetEntityListener来获取实现接口的实体的名称?
编辑:
我为什么需要那个?很简单,例如,我需要一个显示所有Cycles列表的控制器.接口定义每个Cycle都有一个id和一个名字.我想显示每个Cycle的名称和ID.为此,我需要访问实际Cycle实体的存储库.
Alsciende/MyBundle /型号/ CycleInterface.php
<?php
namespace Alsciende\MyBundle\Model;
interface CycleInterface
{
public function getId();
public function getName();
}
Run Code Online (Sandbox Code Playgroud)
Alsciende/MyBundle /控制器/ CycleController.php
<?php
namespace Alsciende\MyBundle\Controller;
class CycleController extends Controller
{
public function indexAction()
{
$cycles = $this
->getDoctrine()
->getRepository('Alsciende\MyBundle\Model\CycleInterface')
->findAll();
// return template with list $cycles
// using only id and name properties
}
}
Run Code Online (Sandbox Code Playgroud)
这与FosUserBundle能够管理用户实体的方式相同,即使FosUserBundle中定义的User类是抽象类.
默认情况下,当您http_basic在Symfony中配置防火墙时,防火墙将返回" 401 Unauthorized",并为失败的请求返回一个空主体.
我想让它返回一个自定义JSON(例如:) {success: false, error: 401}.这可能吗?
这是我的配置:
security:
firewalls:
api:
http_basic:
provider: myprovider
Run Code Online (Sandbox Code Playgroud) 我在Javascript中构建一个复杂的对象,我想在对象的内部集合上公开迭代器.
我能想到的唯一方法是在prototype.js中公开迭代器的常用方法:
customObject.each(function (item) { ... })
Run Code Online (Sandbox Code Playgroud)
与所提供的功能迭代器被称为每个收集,一前一后在每一个项目.
你知道其他任何可靠的方式吗?也许是一种让用户使用通常的foreach结构的方法?
javascript ×3
iterator ×2
shell ×2
symfony ×2
c ×1
css ×1
doctrine-orm ×1
gcc ×1
opacity ×1
perl ×1
php ×1
sed ×1
shellexecute ×1