我使用以下c#代码将图像文件转换为base64字符串
using (var fs = new FileStream(filename, FileMode.Open, FileAccess.Read))
{
var buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
var base64 = Convert.ToBase64String(buffer);
}
Run Code Online (Sandbox Code Playgroud)
如何测试前后尺寸?即.图像文件大小和基本64字符串的大小.我想通过转换它来检查我是赢还是输.
如何在不删除任何更改的情况下"回滚"git中的最后一次提交?
这是我在hg中经常做的事情:
我想为我的MongoDB实例设置用户名和密码验证,以便任何远程访问都会要求输入用户名和密码.我尝试了MongoDB网站上的教程并做了以下事情:
use admin
db.addUser('theadmin', '12345');
db.auth('theadmin','12345');
Run Code Online (Sandbox Code Playgroud)
在那之后,我退出并再次运行mongo.而且我不需要密码来访问它.即使我远程连接到数据库,也不会提示我输入用户名和密码.
更新这是我最终使用的解决方案
1) At the mongo command line, set the administrator:
use admin;
db.addUser('admin','123456');
2) Shutdown the server and exit
db.shutdownServer();
exit
3) Restart mongod with --auth
$ sudo ./mongodb/bin/mongod --auth --dbpath /mnt/db/
4) Run mongo again in 2 ways:
i) run mongo first then login:
$ ./mongodb/bin/mongo localhost:27017
use admin
db.auth('admin','123456');
ii) run & login to mongo in command line.
$ ./mongodb/bin/mongo localhost:27017/admin -u admin -p 123456
Run Code Online (Sandbox Code Playgroud)
用户名和密码将以相同的方式用于mongodump和mongoexport.
我试图用ifstream打开一个文件,我想用一个字符串作为路径(我的程序创建一个字符串路径).它会编译,但它保持空白.
string path = NameOfTheFile; // it would be something close to "c:\file\textfile.txt"
string line;
ifstream myfile (path); // will compile but wont do anything.
// ifstream myfile ("c:\\file\\textfile.txt"); // This works but i can't change it
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用的是Windows 7,我的编译器是VC++ 2010.
除了删除之外,我把JMenu打倒了.:DI意味着,我可以做,popup.remove(NUMBER)但这可能会导致NPE错误.那么,有没有一种方法来删除所有JMenuItems来自JMenu?
checkPopup()如果有人有兴趣,这是我的更新:
private void checkPopup(MouseEvent e)
{
if (e.isPopupTrigger())
{
int itemSelectx = listbox.getSelectedIndex();
Object actItemx = listbox.getModel().getElementAt(itemSelectx);
System.out.println("You pressed on " + actItemx);
if (actItemx == "Item 1") {
popup.add(cancelMenuItem); // add the ability to cancel an item
popup.add(dropMenuItem); // add ability to drop the item
}
popup.show(inv.this, e.getX(), e.getY()); // show item at mouse
popup.revalidate(); // revalidate
//popup.remove(0); // removing first (0) menu item
}
}
Run Code Online (Sandbox Code Playgroud)
差不多了!:)(是的,我试过Google和JavaDocs)
我在网上和这个网站上搜索过,我找不到在MIPS中实现2D数组的好例子.我希望能够看到一个如何遍历数组以便将数据放在特定索引以及如何打印数组的示例,如下所示.
例如5x5数组,其中$将是每个索引中的数据.
a b c d e
1 $ $ $ $ $
2 $ $ $ $ $
3 $ $ $ $ $
4 $ $ $ $ $
5 $ $ $ $ $
Run Code Online (Sandbox Code Playgroud) 我从系统中得到了一份Knowncolor列表,但是我想删除一些太暗的内容并使前景字符看不见.我尝试了以下代码,但KnownColor.Black仍然出现.无论如何,他们在黑暗中命令他们?
if (knownColor > KnownColor.Transparent && knownColor < KnownColor.MidnightBlue && knownColor < KnownColor.Navy)
{
//add it to our list
colors.Add(knownColor);
}
Run Code Online (Sandbox Code Playgroud) 我需要确保程序中的所有随机性都是完全可复制的.我应该在哪里拨打random.seed()?
我认为它应该在我的main.py模块中,但它会导入其他碰巧使用随机函数的模块.
我可以仔细浏览我的导入,看看哪一个是第一个执行,但是当我改变我的代码结构时,我将不得不记得再次重做这个分析.
有没有简单安全的解决方案?
我正在尝试使用InputMap/ActionMap拦截删除键.我让它与Enter一起工作,但它似乎没有回复删除(这是在Mac OSX上,所以我想知道这是否是问题的一部分).
我究竟做错了什么?
private void setupKeyBindings(final JList jlist) {
String delAction = "deleteItems";
KeyStroke delKey = KeyStroke.getKeyStroke("DELETE");
jlist.getInputMap().put(delKey, delAction);
jlist.getActionMap().put(delAction, new AbstractAction()
{
@Override public void actionPerformed(ActionEvent e) {
System.out.println("delete pressed");
doDelete(jlist);
}
});
String enterAction = "useItems";
KeyStroke enterKey = KeyStroke.getKeyStroke("ENTER");
jlist.getInputMap().put(enterKey, enterAction);
jlist.getActionMap().put(enterAction, new AbstractAction()
{
@Override public void actionPerformed(ActionEvent e) {
System.out.println("enter pressed");
}
});
}
Run Code Online (Sandbox Code Playgroud) 我在VS2010下安装了NUnit 2.5.9,并希望它能够与新发布的MVC3一起运行.关注 http://www.nuclex.org/downloads/tools/39-nunit-template-for-asp-net-mvc-2 我无法实现让NUnit在MVC3-New Project模板中显示为测试框架.在添加项目时,我也没有将NUnit视为模板.
如何让NUnit与MVC 3一起工作?