-(NSDate *)beginningOfDay:(NSDate *)date
{
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:date];
[components setHour:0];
[components setMinute:0];
[components setSecond:0];
return [cal dateFromComponents:components];
}
-(NSDate *)endOfDay:(NSDate *)date
{
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:( NSMonthCalendarUnit | NSYearCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit ) fromDate:date];
[components setHour:23];
[components setMinute:59];
[components setSecond:59];
return [cal dateFromComponents:components];
}
Run Code Online (Sandbox Code Playgroud)
当我打电话:[self endOfDay:[NSDate date]]; 我得到了本月的第一天......为什么?我使用这两种方法,因为我需要一个从第一个日期的第一秒开始的间隔(beginningOfDay:date1)到第二个日期的最后一秒(endOfDay:Date2)......
所以目前我正在尝试裁剪和调整图片大小以使其适合特定尺寸而不会失去比例.
一个小图像,以显示我的意思:

我玩了一些vocaro的类别,但他们不使用png并且与GIF有问题.图像也不会被裁剪.
有没有人有一个建议如何这样做调整大小最好的方式或可能有一个链接到现有的库/类别/什么?
谢谢你的所有提示!
ps:ios是否实现了"选择一个摘录",以便我有正确的比例,只需要缩放它?!
我的应用程序使用相机.在iOS8中,它们包含一个新的隐私设置,Camera用户可以在其中管理每个应用程序的相机权限.
问题:
如果用户不允许我的应用程序使用相机,那么我怎么知道我的应用程序无法访问相机.
就像我可以ALAssetsLibrary authorizationStatus用来发现photolibrary的状态或ABAddressBookGetAuthorizationStatus了解电话簿访问的状态.
问题:
如何知道我的应用程序是否在iOS8中具有相机访问权限,以便我可以提示用户允许相机访问我的应用程序?
我有照片展位的下面打印屏幕,与我的应用程序有相同的问题.



我在perl中编写了这段代码:
shift( @interfaces = qx'ifconfig -s' );
Run Code Online (Sandbox Code Playgroud)
并得到这个错误:
Type of arg 1 to shift must be array (not list assignment)
Run Code Online (Sandbox Code Playgroud)
当我这样写的时候:
@interfaces = qx'ifconfig -s';
shift @interfaces;
Run Code Online (Sandbox Code Playgroud)
它做我想要的,即将ifconfig命令的输出作为一个行数组并删除数组中的第一个元素(这是一个标题,而不是一个实际的接口).
我个人的偏好是把它写成一个班轮.在我看来,第一个例子中的括号应该导致赋值被完全解析,因此允许转换将@interfaces看作一个数组,但显然perl认为它是一个"列表赋值".
对于perl大师来说,这肯定是一个简单的问题,但我用Google搜索并用谷歌搜索并没有找到启示.
如果有人愿意提供具体的语义来完成我想要的一行,我将不胜感激.如果你也请花时间解释为什么我的第一个版本不起作用我会永远感激(教一个人钓鱼等等).
预先感谢您的帮助.
我想知道在 C++ 中是否可以声明一个必须是字符串文字的函数参数?我的目标是接收一个对象,我只能保留指向它的指针,并且知道它不会free()从我下面被删除(即具有应用程序生命周期范围)。
例如,假设我有类似的东西:
#include <string.h>
struct Example {
Example(const char *s) : string(s) { }
const char *string;
};
void f() {
char *freeableFoo = strdup("foo");
Example e(freeableFoo); // e.string's lifetime is unknown
Example e1("literalFoo"); // e1.string is always valid
free(freeableFoo);
// e.string is now invalid
}
Run Code Online (Sandbox Code Playgroud)
如示例所示,当ed 时,该freeableFoo成员变得无效。这一切都是在你没有意识到的情况下发生的。free()e.stringExample
显然,如果在其构造函数中复制字符串,我们可以解决这个问题Example,但我不想为副本分配内存。
的构造函数是否可以Example声明“您必须传递字符串文字”(在编译时强制执行),以便知道Example它不必复制字符串并且知道其string指针在应用程序的生命周期内有效?
我使用内置的Cipher类在Android上实现了AES/CTR.对于我的目的来说,解密似乎太慢了,128KB的块在仿真器上解密大约需要6秒,而在三星Galaxy硬件上需要2.6秒.
我想知道是否使用NDK构建OpenSSL并调用其方法会更快.有人对这个有经验么?部分我想要相信Cipher("AES/CTR/NoPadding")方法只是本机OpenSSL调用的包装器,因为支持Android的Linux操作系统应该安装了libcrypto.如果是这种情况,那么尝试使用NDK只会浪费时间,因为不会出现性能提升.
我没有费心在iOS上计算时间,但即使3Gs硬件也解密得如此之快,以至于10MB解密似乎对最终用户来说是即时的.我发现很难相信Android的实现确实更糟糕,但也许这就是现实.
如果这真的是我面临的问题,那么是否有人对其他实施策略有任何想法会为最终用户提供难以察觉的响应(在10Mb文件上)?我办公室的另一位开发人员用一种诙谐的方式建议我只使用XOR加密,这让我想要自己面对,但我认为(安全问题除外),如果我这样做,它会起作用.
谢谢!
这里有一些简化的代码供参考:
public class ResourceDecryptor {
private static ThreadLocal<Cipher> mCipher;
private byte[] mIV = new byte[ 8 ];
private SecretKeySpec mKey;
private String mResourcePath;
private static final int kAESBlockSize = 16;
public ResourceDecryptor( String resourcePath, String decryptionKey ) throws UnsupportedOperationException {
// initialization of mKey, mIV, & mResourcePath, elided
// store mCipher as a thread local because Cipher.getInstance() is so slow,
// ResourceDecryptor is a static object that persists for the app lifetime
// so this …Run Code Online (Sandbox Code Playgroud) 使用JSF,Managed Beans和EL 2.2,我通常知道表单的形式:
#{bean.value}
Run Code Online (Sandbox Code Playgroud)
将映射到托管bean类中的相应函数集,如下所示:
@ManagedBean
class Bean {
private String value;
public String getValue() { return value; }
public void setValue( String s ) { value = s; }
}
Run Code Online (Sandbox Code Playgroud)
也可以获取和设置地图的属性:
#{bean.value['key']}
Run Code Online (Sandbox Code Playgroud)
由以下内容支持:
@ManagedBean
class Bean {
private Map<String, Boolean> kvMap;
public boolean getValue( String key ) { return kvMap.get( key ); }
public void setValue( String key, boolean value ) { kvMap.put( key, value ); }
}
Run Code Online (Sandbox Code Playgroud)
到现在为止还挺好.
我发现我花了更多时间在JSF上,但是我正在尝试编写可重用的代码块.具体来说,<ui:composition>我可以包含块中的小块xhtml <ui:include>.更重要的是,对我来说,许多更有用的东西都是嵌套的复选框(我们的UI设计师只是对它们的加法;-),并且<ui:repeat>变得非常方便.
总是,为了使用<ui:repeat>和 …
我们经常看到Oracle(11gR2)在尝试通过JDBC进行更新时挂起.访问Oracle的线程是应用程序中连接到数据库的唯一线程,它永远等待Oracle返回数据.可能另一个进程可能访问了同一个数据库并更新了一个表,但我认为Oracle会自动检测死锁并返回错误.在我们的例子中,数据库只是挂起.有什么可能导致这个或通过一些DBA命令调试的方法的想法?这是我遇到的堆栈跟踪:
Thread 7315: (state = IN_NATIVE)
- java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise)
- java.net.SocketInputStream.read(byte[], int, int, int) @bci=79 (Compiled frame)
- java.net.SocketInputStream.read(byte[], int, int) @bci=11 (Compiled frame)
- oracle.net.ns.Packet.receive() @bci=180, line=308 (Compiled frame)
- oracle.net.ns.DataPacket.receive() @bci=1, line=106 (Compiled frame)
- oracle.net.ns.NetInputStream.getNextPacket() @bci=48, line=324 (Compiled frame)
- oracle.net.ns.NetInputStream.read(byte[], int, int) @bci=33, line=268 (Compiled frame)
- oracle.net.ns.NetInputStream.read(byte[]) @bci=5, line=190 (Compiled frame)
- oracle.net.ns.NetInputStream.read() @bci=73, line=107 (Compiled frame)
- oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket() @bci=94, line=143 (Compiled frame)
- oracle.jdbc.driver.T4CSocketInputStreamWrapper.read() …Run Code Online (Sandbox Code Playgroud)