来自维基百科
在密码学中,定时攻击是一种侧信道攻击,攻击者通过分析执行加密算法所花费的时间来试图破坏密码系统.
实际上,为了防止定时攻击,我使用了以下从这个答案中获取的函数:
function timingSafeCompare($safe, $user) {
// Prevent issues if string length is 0
$safe .= chr(0);
$user .= chr(0);
$safeLen = strlen($safe);
$userLen = strlen($user);
// Set the result to the difference between the lengths
$result = $safeLen - $userLen;
// Note that we ALWAYS iterate over the user-supplied length
// This is to prevent leaking length information
for ($i = 0; $i < $userLen; $i++) {
// Using % here is a trick to …Run Code Online (Sandbox Code Playgroud) 我需要本地化info.plist的两个键:NSLocationUsageDescription和NSCameraUsageDescription.所以我尝试创建一个名为InfoPlist.strings的新文件,然后我将其本地化,但应用程序始终显示存储在info.plist文件中的字符串.怎么了?
信息财产清单重点参考的官方文件
本地化的值不存储在Info.plist文件本身中.而是将特定本地化的值存储在名为InfoPlist.strings的字符串文件中.将此文件放在与用于存储同一本地化的其他资源相同的特定于语言的项目目录中.InfoPlist.strings文件的内容是您想要本地化的各个键以及适当翻译的值.查找Info.plist文件中的键值的例程会考虑用户的语言首选项,并在存在时返回键的本地化版本(来自相应的InfoPlist.strings文件).如果不存在密钥的本地化版本,则例程将返回存储在Info.plist文件中的值.
我的InfoPlist.strings文件:
NSCameraUsageDescription = "hello";
NSLocationUsageDescription = "hello hello";
Run Code Online (Sandbox Code Playgroud) 关于OneToMany <-> ManyToOne我的实体Device和我之间的双向关系,我有一个问题Event.这是映射的外观:
// Device entity
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Event", mappedBy="device")
*/
protected $events;
// Event entity
/**
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Device", inversedBy="events")
*/
protected $device;
Run Code Online (Sandbox Code Playgroud)
问题来自因为Device是单表继承实体
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="device_class_type", type="string")
Run Code Online (Sandbox Code Playgroud)
每次我获取并迭代某些Event实体,然后$device总是急切地获取.发生这种情况是因为它是相关文档中报告的STI实体
单表继承存在一般性能考虑因素:如果多对一或一对一关联的目标实体是STI实体,则出于性能原因,它最好是继承中的叶实体层次结构,(即没有子类).否则,Doctrine不能创建该实体的代理实例,并且总是急切地加载该实体.
现在有另一个被称为Gateway与两者有关系的实体Device和Event:
/**
* @ORM\OneToMany(targetEntity="AppBundle\Entity\Device", mappedBy="gateway")
*/
protected $devices;
/**
* @ORM\OneToMany(targetEntity="targetEntity="AppBundle\Entity\Event", mappedBy="gateway")
*/
protected $events;
public function getEvents(): Collection
{
return $this->events;
}
Run Code Online (Sandbox Code Playgroud)
当然,每次迭代$gateway->getEvents()所有相关事件时,都会急切地获取设备.即使我没有得到任何$device …
几分钟前,在玩javascript时,我注意到了一个奇怪的行为console.log().实际上它似乎记录了"扭曲"的变量.看看以下内容:
var res = document.getElementById("res");
var arr = ["1", "2", "3"];
arr.push("4");
res.innerHTML = JSON.stringify(arr)+'<br>';
console.log(arr);
arr.push("5");
res.innerHTML += JSON.stringify(arr);
console.log(arr);Run Code Online (Sandbox Code Playgroud)
<div id="res"></div>Run Code Online (Sandbox Code Playgroud)
它将正确的变量打印#res到浏览器控制台中(Firefox 37)

有人能解释我为什么会这样吗?
我在尝试迭代 Twig 表单主题中的所有表单元素时遇到问题。实际上我用它来迭代它们:
{% for child in form.parent.children %}
Run Code Online (Sandbox Code Playgroud)
我在文档中没有找到它,我只是转储了表单变量并找到了该路径上的字段。这实际上适用于所有表单,除非表单本身有一个名为children的参数。我不知道这是否是一个错误,因为如果您只是转储form对象,则两种情况下的结构都是相同的:
但是,如果您尝试访问form.parent.children它内部有children参数的情况,您将不会获得该数组,而是直接获得以下结果"children":
正如您所看到的,在本例中form.parent.children直接引用表单的子元素(相同的标识符#1592)。不过,如果您尝试获取,form.parent.children.parent.children您将再次获得children元素,因此如果表单包含名为 的参数,则基本上使用这种方式不可能迭代表单字段children。
这是一个错误还是我错过了什么?也许还有另一种方式来实现我想要的?
我需要知道CLLocationManager(在这种情况下称为gps)的实例是否正在更新调用正确方法的位置
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
Run Code Online (Sandbox Code Playgroud)
在我的情况下,完整的方法是:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
//NSLog(@"didUpdateToLocation: %@", newLocation);
currentLocation = newLocation;
if (currentLocation != nil) {
longitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.longitude];
latitude.text = [NSString stringWithFormat:@"%.3f", currentLocation.coordinate.latitude];
}
address.text = NULL;
[activityIndicator setHidden:NO];
[activityIndicator startAnimating];
NSLog(@"Resolving the Address");
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
//NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks …Run Code Online (Sandbox Code Playgroud) 我需要在iOS7上隐藏状态栏.我已经尝试过设置:
Status bar is initially hidden
Run Code Online (Sandbox Code Playgroud)
和
View controller-based status bar appearance
Run Code Online (Sandbox Code Playgroud)
进入plist文件.当应用程序处于启动状态时,状态栏不会出现,但是当我更改视图控制器(是选项卡式应用程序)时,状态栏会出现!
我已经尝试过设置
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
和
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
Run Code Online (Sandbox Code Playgroud)
在视图控制器中,但不起作用.有任何想法吗?
先感谢您 :)
UPDATE
我通过将"查看基于控制器的状态栏外观"设置为"YES"到info.plist并调用该方法来部分解决该问题
- (BOOL)prefersStatusBarHidden
{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
进入视图控制器.但是现在我遇到了另一个问题:当我启动另一个控制器(UIImagePickerController)时会出现状态栏.我试着设置[myPicker prefersStatusBarHidden];但它似乎是只读的.谁知道解决方案?
PS:UIViewControllerBasedStatusBarAppearance = NO和UIViewControllerBasedStatusBarAppearance = NO是一样的..
我在处理内存限制较低的 Symfony 项目时遇到问题。我需要创建多个实体,将它们添加到另一个实体(实体是关联的),然后将更改刷新到数据库。这是while循环发生的。
问题是有时循环无法完成整个循环,因为进程因内存耗尽而崩溃。当然我不能提高内存限制。
我尝试用一些代码更好地解释你......
class Device
{
/**
* @ORM\ManyToMany(targetEntity="Resource", inversedBy="devices",cascade={"persist", "refresh"}, fetch="EXTRA_LAZY")
*/
protected $resources;
public function addResource(Resource $resource)
{
if ($this->resources->contains($resource)) return;
$this->resources->add($resource);
$resource->addDevice($this);
}
}
class Resource
{
/**
* @ORM\ManyToMany(targetEntity="Device", mappedBy="resources")
*/
protected $devices;
public function addDevice(Device $device)
{
if ($this->devices->contains($device)) return;
$this->devices->add($device);
$device->addResource($this);
}
}
Run Code Online (Sandbox Code Playgroud)
function doIt(Device $device) {
while(...) {
$res = new Resource(...);
$device->addResource($res); // store $res in memory until end
}
$em->persist($device);
$em->flush();
}
Run Code Online (Sandbox Code Playgroud)
所以问题是,在循环结束之前,$device保留内存 …
我正在尝试了解有关内存使用情况的更多信息。
使用interface{}和struct{}切片进行一些测试时,我注意到切片struct{}不分配任何内存,而切片则分配任何内存interface{}。这对我来说没有多大意义,我实际上期待相同的行为(即两者都不分配任何内容)。无论如何,我找不到关于这个特殊案例的任何解释。
有人能解释一下为什么会发生这种情况吗?
package main
import (
"runtime"
"fmt"
)
func main() {
// Below is an example of using our PrintMemUsage() function
// Print our starting memory usage (should be around 0mb)
fmt.Println("Start")
PrintMemUsage()
fmt.Println("")
structContainer := make([]struct{}, 1000000)
for i := 0; i<1000000; i++ {
structContainer[i] = struct{}{}
}
fmt.Println("With 1kk struct{}")
PrintMemUsage()
fmt.Println("")
nilContainer := make([]interface{}, 1000000)
for i := 0; i<1000000; i++ {
nilContainer[i] = nil
}
fmt.Println("With …Run Code Online (Sandbox Code Playgroud) php ×4
symfony ×3
doctrine-orm ×2
ios ×2
objective-c ×2
browser ×1
cocoa-touch ×1
collections ×1
cryptography ×1
firefox ×1
forms ×1
go ×1
info.plist ×1
ios7 ×1
javascript ×1
memory ×1
security ×1
timing ×1
twig ×1
xcode ×1