给定以下代码,如果抛出异常,如何返回一些值(DateTime.Now.ToString())?
public string DateToString(int year, int month, int day)
{
try
{
DateTime datetime = new DateTime(year, month, day);
return datetime.ToString();
}
catch (Exception)
{
//log error and rethrow
throw;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在从使用简单MD5无密码密码的遗留系统迁移到Devise.虽然我可以按照Devise wiki的建议滚动我自己的加密器,但我实际上想要迁移到bcrypt密码机制.
这似乎比下载彩虹表并尝试发现所有明文密码更合理......
所以,我想知道下面的代码是否会有任何副作用,尤其是在保存期间!触发任何具有意外行为的回调:
## config/initializers/legacy.rb
require 'bcrypt'
require 'digest/md5'
module Devise
module Models
module DatabaseAuthenticatable
def valid_password?(password)
if self.legacy_password_hash
if ::Digest::MD5.hexdigest(password) == self.legacy_password_hash
## authenticated; now convert to bcrypt password
self.password = password
self.legacy_password_hash = nil
self.save!
return true
else
## so that we don't get a bcrypt invalid hash exception
return false
end
else
return ::BCrypt::Password.new(self.encrypted_password) == "#{password}#{self.class.pepper}"
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud) 优选地,这将是通过电缆连接的计算机,但是如果有办法通过wifi进行,则这也是有用的.我想知道是否可以在它们之间发送消息?
或者,如果我有一个Mac应用程序和一个iPhone应用程序,我可以通过wifi或USB连接,而不是使用服务器或其他东西进行通信吗?
我有一个标签栏应用程序.一切正常,我可以切换到标签和所有内容,除非我切换到我的第二个选项卡ProductViewClass,视图不会更新,它会吐出下面的控制台输出.除了UIWebView和UILabel之外,我在此视图中没有任何内容.当我删除UIWebView它成功运行时,当我添加另一个它仍然有效.它只在我将IBOutlet从我的文件所有者连接到UIWebView时停止工作.除了合成和发布productWebView唯一的非模板代码ProductWebView.m是这样的:
NSString *urlString = @"http://www.google.com/";
NSURL *theURL = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:theURL];
[productWebView loadRequest:urlRequest];
NSLog(@"Google loaded");
Run Code Online (Sandbox Code Playgroud)
ProductWebView.h的整体如下:
#import <UIKit/UIKit.h>
@interface ProductViewClass : UIViewController {
IBOutlet UIWebView *productWebView;
}
@property(nonatomic, retain) UIWebView *productWebView;
@end
Run Code Online (Sandbox Code Playgroud)
这是控制台输出:
This GDB was configured as "x86_64-apple-darwin".Attaching to process 52523.
2011-01-30 19:18:28.907 FairCom[52523:40b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4d06eb0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key productWebView.'
*** Call …Run Code Online (Sandbox Code Playgroud) 可能重复:
什么限制了c中嵌套循环的数量?
你好.
当我读到我的C书时,它说
Run Code Online (Sandbox Code Playgroud)Nesting for-Loop in C can continue even further up to 127 levels!
怎么127来的?
我的书没有提到这一点.对我来说就像一个神奇的数字.
[更新]
int main()
{
int number, n, triangularNumber, counter;
triangularNumber = 0;
for (counter = 1; counter <= 5; ++counter){
printf("What triangular number do you want? \n");
// using a routine called scanf
scanf("%i", &number);
triangularNumber = 0;
for (n =1 ; n <= number; ++n)
triangularNumber += n;
printf("Triangular number %i is %i\n", number, triangularNumber);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 说我有一个Grid,其Width被设置为Auto.在这个网格中,我想放一个正方形的新网格.为此,我希望新网格的宽度和高度相等.我以为我可以设置Width和Height父网格Width.问题是,父网格的宽度是double.NaN,因为它设置为auto.
我的问题是,有没有办法获得ActualWidth这个父网格,以便我知道它有多宽?如果没有,是否有另一种方法来创建适合父网格的矩形网格?
我有一个显示取消按钮的UISearchDisplayController.我想在用户点击取消按钮时调用方法.有没有办法做到这一点?
我可以移动到python项目目录(比如c:\ www\myproject),然后发出
python manage.py shell
Run Code Online (Sandbox Code Playgroud)
然后我可以使用django项目中的所有模块,从shell命令中说出以下命令:
import settings
from django.template import Template, Context
t=Template("My name is {myname}.")
c=Context({"myname":"John"})
f = open('write_test.txt', 'w')
f.write(t.render(c))
f.close
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试将所有命令收集到python脚本中时,说"mytest.py",我无法执行脚本.我必须错过重要的事情.
我发出了python mytest.py
然后我得到Import error: could not import settings它是在sys路径上吗?"
我在settings.py所在的项目目录中......
有人可以帮帮我吗?
谢谢.
这似乎是一个非常简单的查询,但不知怎的,我不断收到错误......
基本上,我只是从用户那里获得了大量信息,现在我将users在一个查询中更新表中的记录:
UPDATE usersSET timezone='America/New_York',SET updates='NO',SET verified='YES'WHERE id='1'
但是,在运行之后,我收到以下错误:"您的SQL语法中有错误;请检查与您的MySQL服务器版本对应的手册,以便在'SET updates='NO' 附近使用正确的语法,SET verified='YES 'WHERE id='1''在第1行".
任何帮助深表感谢.
c# ×2
ios ×2
iphone ×2
actualwidth ×1
asp.net ×1
c ×1
c99 ×1
cocoa-touch ×1
devise ×1
django ×1
exception ×1
for-loop ×1
ipad ×1
macos ×1
mysql ×1
nested ×1
nsexception ×1
objective-c ×1
php ×1
python ×1
silverlight ×1
uitabbar ×1
uiwebview ×1