我在查看jQuery插件时发现了这个片段,并想知道它实际上是做什么的
一个jQuery插件框架:
(function($) {
...
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
最近在nettuts中:
var STICKIES = (function () {
...
}());
Run Code Online (Sandbox Code Playgroud) 我有保存文件的代码
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Text files|*.txt";
SaveDialog:
if ((bool)dialog.ShowDialog()) {
if (System.IO.Path.GetExtension(dialog.FileName) != ".txt") {
MessageBox.Show("You must select a .txt file");
dialog.FileName = "";
goto SaveDialog;
}
File.WriteAllText(dialog.FileName, txtEditor.Text);
}
Run Code Online (Sandbox Code Playgroud)
我读到我不应该使用goto.我可以使用do/while并检查是否选择了有效的扩展名,但这将添加许多不必要的代码.我觉得这个整洁.还是有更好/更正确的方法?
我正在看这个教程.在大约15:40左右,发言人说像LINQ查询这样的东西不会创建丰富的集合BindingListCollectionView.我想也许这意味着更改不会保存到数据库或其他东西.所以我尝试更换
var result = database.Customers.Execute(System.Data.Objects.MergeOption.AppendOnly);
Run Code Online (Sandbox Code Playgroud)
同
var result = from cust in database.Customers
where cust.City == "Seattle"
select cust;
Run Code Online (Sandbox Code Playgroud)
一切都还行不错.
我有以下代码
var postData = "";
var req = HttpWebRequest.Create("http://www.imageshack.us/upload_api.php");
req.ContentType = "multipart/form-data";
postData += "key=xxx&";
postData += "type=base64&";
// get base64 data from image
var fs = new FileStream(@"D:\tmp\WpfApplication1\WpfApplication1\Images\Icon128.gif", FileMode.Open, FileAccess.Read);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
string encoded = Convert.ToBase64String(bytes);
postData += "fileupload=" + encoded;
byte[] reqData = Encoding.UTF8.GetBytes(postData);
Stream dataStream = req.GetRequestStream(); // error triggered here
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
System.Net.ProtocolViolationException was unhandled
Message=Cannot send a content-body with this verb-type.
Source=System
StackTrace:
at System.Net.HttpWebRequest.CheckProtocol(Boolean onRequestStream)
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at …Run Code Online (Sandbox Code Playgroud) 我很难搞清楚导致输出流中出现奇怪字符的原因...完整代码@pastebin
提琴手输出
在我的边界之前注意" s"," X"," ?"?
s---------------634227387532666996
Content-Disposition: form-data; name='key'
c06f4d0cdf6f2cc652635a08be34973d
X---------------634227387532666996
Content-Disposition: form-data; name='type'
file
?---------------634227387532666996
Content-Disposition: form-data; name='image'; filename='application_osx_split.png'
Content-Type=image/png
?PNG
Run Code Online (Sandbox Code Playgroud)
我的代码
var bound = "-------------" + DateTime.Now.Ticks.ToString();
var tmplField = "--" + bound + "\r\nContent-Disposition: form-data; name='{0}'\r\n\r\n{1}\r\n";
var tmplFile = "--" + bound + "\r\nContent-Disposition: form-data; name='{0}'; filename='{1}'\r\nContent-Type={2}\r\n\r\n";
....
using (var reqStream = req.GetRequestStream())
{
var reqWriter = new BinaryWriter(reqStream);
reqWriter.Write(string.Format(tmplField, "key", "c06f4d0cdf6f2cc652635a08be34973d"));
reqWriter.Write(string.Format(tmplField, "type", "file"));
reqWriter.Write(string.Format(tmplFile, "image", Path.GetFileName(filepath), "image/" + Path.GetExtension(filepath).Substring(1)));
reqWriter.Write(File.ReadAllBytes(filepath)); …Run Code Online (Sandbox Code Playgroud) 假设我得到了一些项目列表$(".box").是否有可能获得索引的jQuery对象
喜欢
var $boxes = $(".box"),
$box2 = $boxes[1]
Run Code Online (Sandbox Code Playgroud)
目前我做的事情就像
var $boxes = $(".box");
$boxes.each(function(i, box) {
var $box = $(box); // <-- is this a good idea?
// do something with $box
});
Run Code Online (Sandbox Code Playgroud)
我想知道这条线var $box = $(box)是不是一个好主意?我实际上是在运行它setInterval()
喜欢
var $boxes = $(".box");
setInterval(function() {
$boxes.each(function(i, box) {
var $box = $(box); // <-- is this a good idea?
// do something with $box
});
}, 1000);
Run Code Online (Sandbox Code Playgroud)
我想知道它是否对性能有害,因为我$boxes在这个例子中为每1s中的每个项初始化一个变量.如果我可以直接从jQuery"数组"或任何$ box访问元素,它可能更好?
我在一个项目中使用VC++ 10.作为C/C++的新手,我只是谷歌搜索,似乎在标准C++中没有正则表达式?VC++ 10似乎有正则表达式.但是,我如何进行正则表达式拆分?我是否需要提升?
在网上搜索,我发现许多人推荐使用Boost进行许多操作,标记/拆分字符串,解析(PEG),现在甚至是正则表达式(尽管这应该是内置的......).我能否得出结论提升是必须的?它的180MB只是琐碎的东西,在许多语言中天真地支持?
我有一个AbstractCacheBlock,我想定义一个CacheSet包含许多类扩展的类AbstractCacheBlock.我相信我想要的是类似的东西
public class CacheSet<? extend AbstractCacheBlock>
Run Code Online (Sandbox Code Playgroud)
但这似乎没有效果.那我怎么能参考那门课呢?通常它看起来像
public class CacheSet<T> {
public void something() {
T t = new T();
}
Run Code Online (Sandbox Code Playgroud)
我用什么代替T当时的?
我知道redis很快,我发现只使用redis就可以实现很多东西.但是以牺牲多个查询为代价.在我使用Mongo时,我可能有一个模型/架构,如:
聊天室(Mongo)
有了redis,我需要更复杂的东西
chatrooms:<<id>> 其中id需要手动生成
chatrooms:<<id>>:users 存储用户集要检索mongo的聊天室详细信息很简单,使用mongo我需要在这种情况下产生2个查询.在更复杂的用例中,可能更多
所以我从性能的角度来看,哪个更高效?从开发的角度来看,肯定是以简单的Mongo为例.
我得到的东西是这样的:
[jiewmeng@JM Assignment 2]$ mpic++ basketball-match.cpp -o basketball-match && mpirun -np 12 basketball-match
In file included from /usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/vector:70:0,
from basketball-match.cpp:4:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/vector.tcc: In instantiation of ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, const _Tp&) [with _Tp = int [2]; _Alloc = std::allocator<int [2]>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int (*)[2], std::vector<int [2]> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int (*)[2]]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/stl_vector.h:893:4: required from ‘void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int [2]; _Alloc = std::allocator<int [2]>; std::vector<_Tp, _Alloc>::value_type = int [2]]’
basketball-match.cpp:145:49: required from here
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.2/../../../../include/c++/4.7.2/bits/vector.tcc:327:19: error: …Run Code Online (Sandbox Code Playgroud) 阅读加速C++:是否int* i或int *i应该使用的讨论.这int* p, q实际上就是这样int (*p), q.所以我想q只是一个int?(不是指针)?那么可以声明一堆指针吗?
我认为int *p, *q不会起作用吗?
我有
if p != None && (self.running == None or self.running < p):
self.preempt(p)
Run Code Online (Sandbox Code Playgroud)
缩进有什么问题?
c# ×4
c++ ×3
javascript ×2
jquery ×2
database ×1
generics ×1
java ×1
mongodb ×1
nosql ×1
openmpi ×1
performance ×1
python ×1
python-3.x ×1
redis ×1
vector ×1
visual-c++ ×1
wpf ×1