我有一些在画布上绘制矩形的代码,但是当我将鼠标悬停在它上面时,我希望该矩形能够改变颜色.
问题是我绘制矩形之后我不确定如何再次选择它来进行调整.
我想做的事:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.rect(20,20,150,100);
ctx.stroke();
$('c.[rectangle]').hover(function(this){
this.fillStyle = 'red';
this.fill();
});
Run Code Online (Sandbox Code Playgroud) 考虑 TypeScript 文档中泛型的最后一个示例: https://www.typescriptlang.org/docs/handbook/generics.html#using-class-types-in-generics
如果我想设置Lion默认值createInstance()我该怎么做?
例如:
class Animal {
numLegs: number = 0;
}
class Lion extends Animal {
keeper = "zookeeper";
}
function createInstance<A extends Animal>(c: new () => A = Lion): A { // error!
// -------------------------------------> ~~~~~~~~~~~~~~~~~~~~~
// 'Lion' is assignable to the constraint of type 'A', but 'A' could be
// instantiated with a different subtype of constraint 'Animal'.
return new c();
}
Run Code Online (Sandbox Code Playgroud)
我需要利用这个removeEldestEntry()方法LinkedHashMap.
我以线程安全的方式使用LinkedHashMap's和removeEldestEntry()方法最简单的方法是什么?
我一直在研究遗传算法的并行处理以提高性能,但我想知道还有哪些其他常用技术可以优化遗传算法?
我有一个函数可以进行一些计算。它接受一个 int 数组并根据传递给它的 int 数组的内容返回一个整数。
由于我的应用程序正在执行数百个这些计算,因此我正在尝试设置一种将这些计算结果存储在哈希图中的方法,这样它就不必重新计算它最近已经完成的计算。为此,我需要使用 int 数组作为哈希图的键。
目前这是打印尺寸 2,我希望它是打印尺寸 1:
LinkedHashMap hashmap = new LinkedHashMap();
int test[] = {1,2,3};
int test2[] = {1,2,3};
hashmap.put(test, 1);
hashmap.put(test2, 1);
System.out.println("Size: "+hashmap.size());
Run Code Online (Sandbox Code Playgroud)
实现这一目标的最佳方法是什么?我可以创建一种方法将数组转换为某种字符串编码数组数据,但我认为这不是最好的解决方案。
为什么我们在计算权重时不能只使用阶跃函数,
weightChange = n * (t-o) * i
Where, n: learning rate;
t: target out;
o: actual out;
i: input
Run Code Online (Sandbox Code Playgroud)
这适用于单层网络。我听说需要 sigmoid 来处理非线性问题,但为什么呢?
所以我有一个程序运行一堆不同的计算,然后在完成所有计算后返回结果.
最初我的代码是同步的,如下所示:
public class MyApplication{
public static void main(String[] args) {
doCalculation(1);
doCalculation(2);
doCalculation(3);
doCalculation(4);
doCalculation(5);
doCalculation(6);
doCalculation(7);
doCalculation(8);
/* Print result */
}
}
Run Code Online (Sandbox Code Playgroud)
我认为在新线程中运行这些计算会更有效,所以现在我有类似的东西,
public class MyApplication{
public static void main(String[] args) {
List<Thread> threads = new ArrayList<Thread>();
threads.add(doCalculation(1));
threads.add(doCalculation(2));
threads.add(doCalculation(3));
threads.add(doCalculation(4));
threads.add(doCalculation(5));
threads.add(doCalculation(6));
threads.add(doCalculation(7));
threads.add(doCalculation(8));
for(Thread t : threads){
if(t.isAlive()){
try{
t.join();
} catch(InterruptedException e) {
System.out.println("Error calculating fitness");
}
}
}
/* Print result */
}
}
Run Code Online (Sandbox Code Playgroud)
对不起,我是线程的完全初学者.如果我不得不猜测我会假设我已经产生了两个新线程(我的应用程序中有大约50个计算),但任何建议都会非常感激!
我是rails的新手,我收到了这个错误:
undefined method `posts_path' for #<#<Class:0x007fe3547d97d8>:0x007fe3546d58f0>
Run Code Online (Sandbox Code Playgroud)
我在下面发布了我的文件,请记住我是rails的新手,所以简单的解释会非常感激!
Route.rb:
Rails.application.routes.draw do
get '/post' => 'post#index'
get '/post/new' => 'post#new'
post 'post' => 'post#create'
end
Run Code Online (Sandbox Code Playgroud)
post_controller.rb:
class PostController < ApplicationController
def index
@post = Post.all
end
def new
@post = Post.new
end
def create
@post = Post.new(post_params)
if @post.save
redirect_to '/post'
else
render 'new'
end
end
private
def post_params
params.require(:post).permit(:content).permit(:title)
end
end
Run Code Online (Sandbox Code Playgroud)
new.html.erb:
<%= form_for(@post) do |f| %>
<div class="field">
<%= f.label :post %><br>
<%= f.text_area :title %>
<%= f.text_area :content %> …Run Code Online (Sandbox Code Playgroud) 说我这样做:
$string = 'some string with a {$var}';
// Set var after
$var = 'variable'
// String with just set var
$newString = 'Here is my string: ' . $string;
echo $newString;
Run Code Online (Sandbox Code Playgroud)
我如何输出:
Here is my string: some string with a variable
Run Code Online (Sandbox Code Playgroud)
我可以用str_replace做到这一点,但我想知道是否有更简单的方法?
java ×3
hashmap ×2
canvas ×1
html ×1
html5 ×1
javascript ×1
optimization ×1
php ×1
ruby ×1
string ×1
typescript ×1