下面是一个非常简单的TODO应用程序构建与angularjs.
它到目前为止工作正常,但我的问题是angularjs继续在输入字段中调用evry键击上的"剩余"函数!! 下面的代码有什么问题吗?
<!doctype html>
<html ng-app>
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<div>
<h2>TODO:</h2>
<div ng-controller="TodoCtrl">
<span>{{remaining()}} of {{todos.length}} remaining</span> [ <a href="" ng-click="archive()">archive</a> ]
<ul class="list-unstyled">
<li ng-repeat="todo in todos">
<input type="checkbox" ng-model="todo.done" >
<span>{{todo.text}}</span>
</li>
</ul>
<form ng-submit="addTodo()">
<input type="text" ng-model="todo" placeholder="Enter your task here">
<form>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<!--script src="app.js"></script-->
<script>
function TodoCtrl($scope) {
$scope.todos = [
{text: 'learn angular', done:true},
{text: 'build an angular app', done:false}
];
$scope.remaining = function() { …Run Code Online (Sandbox Code Playgroud) 下面是一个简单的并行程序,用于使用 tbb 计算标准向量中的元素之和。
有人可以帮我理解为什么它输出错误的结果吗?
#include <iostream>
#include <algorithm>
#include <numeric>
#include <tbb/tbb.h>
struct Sum {
int value;
Sum() : value(0) {}
Sum(Sum&s, tbb::split) : value(0) {}
void operator()(const tbb::blocked_range<std::vector<int>::iterator>& r) {
value = std::accumulate(r.begin(), r.end(), 0);
}
void join(Sum& rhs) { value += rhs.value; }
};
int main()
{
std::vector<int> a(100);
std::fill(a.begin(), a.end(), 1);
Sum sum;
tbb::parallel_reduce(tbb::blocked_range<std::vector<int>::iterator>(a.begin(), a.end()), sum);
std::cout << sum.value << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud) __inline int my_sprintf (char *dest,char *format,...)
{
va_list va;
va_start(va,format);
return vsprintf(dest,format,va);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我无法将缓冲区大小参数添加到my_sprintf,因为它在超过50k的位置使用,我不能用vsprintf_s或vsnprintf替换vsprintf.
任何替代方案可以使上述功能更安全吗?
我尝试用谷歌搜索算法来压缩/加密一个固定大小的字符串,从52个字符到40个字符,但似乎找不到任何字符串.
目标字符串是随机字母数字[A-Z0-9],例如"M5KS07VHN2X42JCY1PFHE1ZZGI2XUBDFAKQBEPFB7CH4SECXHJXL"
我已经尝试了huffman和smaz(https://github.com/antirez/smaz ")并且两者都膨胀到原始字符串的大小.
有没有人知道这个目的的好算法?
#include <iostream>
#include <thread>
int x = 0;
int y = 0;
void f()
{
std::cout <<"f called\n";
static int c = 0;
while(y == 0)
{
++c;
}
std::cout << "c=" << c << std::endl;
std::cout << "x=" << x << std::endl;
}
void g()
{
std::cout <<"g called\n";
x = 42;
y = 1;
}
int main()
{
std::thread t1(f);
std::thread t2(g);
t1.join();
t2.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当从另一个线程设置标志y时,f应该打印'x = 42'(好吧,它也打印x = 0,但这不是问题)
在调试模式下运行时,它按预期工作:
f called
g called
c=80213 …Run Code Online (Sandbox Code Playgroud) 失败的代码:
Enum.map(1..30, &(&1 * 2)) |> Enum.map &(&1 + 1) |> Enum.sum
** (Protocol.UndefinedError) protocol Enumerable not implemented for 3
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:112: Enumerable.reduce/3
(elixir) lib/enum.ex:1400: Enum.reduce/3
(elixir) lib/enum.ex:1043: anonymous fn/3 in Enum.map/2
(elixir) lib/enum.ex:1387: Enum."-reduce/3-lists^foldl/2-0-"/3
(elixir) lib/enum.ex:1043: Enum.map/2
Run Code Online (Sandbox Code Playgroud)
但这完全正常:
iex(18)> arr = Enum.map(1..30, &(&1 * 2)) |> Enum.map &(&1 + 1)
[3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43,
45, 47, 49, 51, 53, …Run Code Online (Sandbox Code Playgroud) 我有两个指向数据结构X的指针列表,算法非常简单:
它循环遍历第一个列表 A 并尝试在列表 B 中查找第一个匹配元素。要求是每个列表中至少有 50k 个元素:
#include <iostream>
#include <memory>
#include <chrono>
#include <vector>
#include <algorithm>
#include <string>
struct X {
std::string field_1;
std::string field_2;
std::string field_3;
std::string field_4;
X(std::string f1, std::string f2, std::string f3, std::string f4)
: field_1(f1)
, field_2(f2)
, field_3(f3)
, field_4(f4)
{};
bool equal(const std::shared_ptr<X>& x) {
return (x->field_1 == field_1) &&
(x->field_2 == field_2) &&
(x->field_3 == field_3) &&
(x->field_4 == field_4);
};
X *match = nullptr;
};
typedef std::shared_ptr<X> X_ptr;
class Timer …Run Code Online (Sandbox Code Playgroud) c++ ×3
c++11 ×3
angularjs ×1
c ×1
compression ×1
concurrency ×1
cstdio ×1
elixir ×1
javascript ×1
matching ×1
performance ×1
stdio ×1
tbb ×1