我在阅读了有关Jon Skeet的有趣内容之后找到了一个字符串,我猜这是在ROT13中.在检查我的猜测之前,我想我会尝试用PHP解密它.这就是我的所作所为:
$string = "Vs lbh nfxrq Oehpr Fpuarvre gb qrpelcg guvf, ur'q pehfu lbhe fxhyy jvgu uvf ynhtu.";
$tokens = str_split($string);
for ($i = 1; $i <= sizeof($tokens); $i++) {
$char = $tokens[$i-1];
for ($c = 1; $c <= 13; $c++) {
$char++;
}
echo $char;
}
Run Code Online (Sandbox Code Playgroud)
我的字符串回来了 AIaf you aasakaead ABruacae Sacahnaeaiaer to adaeacrypt tahais, ahae'ad acrusah your sakualal waitah ahais alaauagah.
我的逻辑似乎很接近,但显然是错的.你能帮帮我吗?
我正在尝试从PHP数组创建一个JS对象数组,但我很难找到一种在每个对象之间插入逗号的方法.
这是我想要输出的内容:
var things = [
{
a: "foo",
b: "bar"
}, // Comma on this line
{
a: "moo",
b: "car"
} // No comma on this line
];
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所拥有的:
var things = [
<?php foreach ($things as $thing): ?>
{
a: "<?php echo $thing->getA(); ?>",
b: "<?php echo $thing->getB(); ?>"
}
<?php endforeach; ?>
];
Run Code Online (Sandbox Code Playgroud)
我想我可以诉诸丑陋的东西,就像if只运行一次的陈述:
<?php
$i = 1;
if ($i == 1) {
echo '{';
$i++;
} else {
echo ',{';
}
?>
Run Code Online (Sandbox Code Playgroud)
有没有更清洁/更好的方法来做到这一点?
我正在使用get_next_posts_link()Wordpress主题中的自定义分页控件.问题是,该函数返回HTML标签和一些描述文本:
<a href="http://localhost/awebsite/page/2/" >Next Page »</a>"><span>Next</span>
Run Code Online (Sandbox Code Playgroud)
我感兴趣的只是URL.是否只有URL的核心功能?或者我是否必须执行一系列字符串函数来减少我返回的内容?
如果字符串符合某种格式,我正在尝试在字符串中插入一些空格.具体来说,如果字符串仅由数字组成,并且长度恰好为五个字符,则应在第三个和第四个数字之间添加空格.
function codeAddress() {
var num_regex = /^\d+$/,
input = $("#distributor-search").val(),
address = (input.match(num_regex) && input.length == 5) ? input.split('').splice(3, 0 , ' ').join() : input ;
console.log('The address is: ' + address);
return false;
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因,链接.split(),.splice()并.join()似乎不返回任何东西.我哪里错了?
我理解,给定一个对象数组,我可以_.uniq()通过检查每个对象共有的对象属性来过滤掉唯一对象.我想知道,我可以一次检查两个属性吗?
例如:
var foo = [
{"name":"Steve", "age":"56", "car":"Porsche"},
{"name":"Steve", "age":"56", "car":"Mercedes"},
{"name":"Bill", "age":"57", "car":"Porsche"},
{"name":"Linus", "age":"56", "car":"Mercedes"}
];
var bar = _.unique(foo, false, function(obj, k, v){
return obj.name && obj.age;
});
console.log(bar);
Run Code Online (Sandbox Code Playgroud)
我非常希望我能找回史蒂夫,比尔和莱纳斯.但是,它看起来好像只是obj.age被检查.
我正在修补Clojure,目前正在试验clojure.lang.PersistentQueue在Dijkstra的睡眠理发师问题中为等候室建模.
barber.core=> (def q (ref clojure.lang.PersistentQueue))
#'barber.core/q
barber.core=> q
#<Ref@37c3a6f0: clojure.lang.PersistentQueue>
barber.core=> @q
clojure.lang.PersistentQueue
barber.core=> (dosync (alter q concat :customer))
IllegalArgumentException Don't know how to create ISeq from: java.lang.Class clojure.lang.RT.seqFrom (RT.java:505)
barber.core=> (dosync (alter q conj :customer))
IllegalArgumentException Don't know how to create ISeq from: clojure.lang.Keyword clojure.lang.RT.seqFrom (RT.java:505)
barber.core=> (dosync (alter q conj :customer))
(:customer)
Run Code Online (Sandbox Code Playgroud)
如您所见,我发送了两次相同的命令.它第一次抛出异常.然而,第二次似乎工作得很好.我现在可以conj和pop我q直到希基的母牛回家.
在哪个世界这是可以接受的?幕后发生了什么,我没有看到?

我有一些UIButtons,我正在以编程方式设置自定义字体,如下所示:
Button1.titleLabel.font = [UIFont fontWithName:@"myCustomFont" size:16];
Button2.titleLabel.font = [UIFont fontWithName:@"myCustomFont" size:16];
Button3.titleLabel.font = [UIFont fontWithName:@"myCustomFont" size:16];
Button4.titleLabel.font = [UIFont fontWithName:@"myCustomFont" size:16];
Button5.titleLabel.font = [UIFont fontWithName:@"myCustomFont" size:16];
Button6.titleLabel.font = [UIFont fontWithName:@"myCustomFont" size:16];
Run Code Online (Sandbox Code Playgroud)
这段代码是正确的,它可以工作,但它似乎不是最简单的编写方式.有没有办法循环使用这些元素?
我曾经想象过这样的事情:
for (int i = 1; i <= 5; i++) {
Button(i).titleLabel.font = etc.. // How would I get the value of 'i'?
}
Run Code Online (Sandbox Code Playgroud)
或者这只是一个坏主意?
我没有看到这个代码有什么问题,但它没有按预期工作.
function slide(slideIndex, slideDirection) {
console.log(slideDirection); // outputs 'right'
$('.slide').animate({slideDirection: '-=940'}, 400);
}
$(function(){
$('.prev','.slide').click(function (e) {
e.preventDefault();
var slideIndex = $(this).closest('.slide').index(),
slideDirection = 'right';
slide(slideIndex, slideDirection);
});
});
Run Code Online (Sandbox Code Playgroud)
如果我在animate方法中只使用字符串'right',它就可以了.我究竟做错了什么?
javascript ×4
php ×3
jquery ×2
clojure ×1
encryption ×1
leiningen ×1
objective-c ×1
rot13 ×1
wordpress ×1