小编cgo*_*gon的帖子

Chrome与Firefox中的ToLowerCase

以下在Fi​​refox中给出0.但是它在chrome中给出了-1.

var index = "?STANBUL".toLowerCase().indexOf("is");
console.log(index);
Run Code Online (Sandbox Code Playgroud)

https://jsfiddle.net/81f0yr8w/1/

较低的外壳时,Chrome会增加一个额外的字符(拉丁语大写字母i,上面有一个点"\ u0130")

"?".toLocaleLowerCase().length
>2
Run Code Online (Sandbox Code Playgroud)

这是正常的行为吗?

javascript

11
推荐指数
1
解决办法
306
查看次数

删除非红色色调像素

我有一个非常简单的图像处理应用程序.

我试图删除不涉及红色调的像素.

到目前为止,基本代码似乎实现了我想要的.

        private void removeUnRedCellsBtn_Click(object sender, EventArgs e)
        {
            byte threshold = Convert.ToByte(diffTxtBox.Text); 
            byte r, g, b;
            for (int i = 0; i < m_Bitmap.Width; i++)
            {
                for (int j = 0; j < m_Bitmap.Height; j++)
                {
                    r = im_matrix[i, j].R;
                    g = im_matrix[i, j].G;
                    b = im_matrix[i, j].B;
                    if ((r - b) < threshold || (r - g) < threshold)
                    {
                        m_Bitmap.SetPixel(i, j, Color.White);
                    }

                }
            }
            pictureArea_PictureBox.Image = m_Bitmap;
        }
Run Code Online (Sandbox Code Playgroud)

基本上,如果(红色和蓝色)或(红色和绿色)的差异小于阈值,则将像素设置为白色.

我的结果似乎很有希望,但我想知道是否有更好的解决方案来确定像素是否涉及红色调.

我的阈值为75的结果是 之前 后

任何算法或思想都将非常感激.

提前致谢

matlab imtool

c# image-processing

10
推荐指数
1
解决办法
1088
查看次数

将递归实现转换为基于循环的实现

我有两个接口负责持有一个闭包

这是第一个在映射操作时保持闭包的方法.

package com.fs;

/**
 * This interface is responsible for holding the closures when it comes to map.
 * It uses two generic types. One for the argument and one for the return type.
 * @param <B> Generic type 
 * @param <A> Generic type
 */
public interface Func<B,A> {
    /**
     * Function prototype m takes an argument of type A and returns a type B.
     * A map operation can produce a different type.
     * @param x of type …
Run Code Online (Sandbox Code Playgroud)

java closures

8
推荐指数
1
解决办法
157
查看次数

如何跟踪和防止在单独进程中运行的c3po中出现的死锁?

我有一个非常简单的计算,它产生字母矩阵可能找到矩阵中的所有单词.单词中的字母是相邻的单元格.

   for (int i = 0; i < 500; i++) {
        System.out.println(i);
        Matrix matrix = new Matrix(4);
        matrix.scanWordsRandomly(9);
        matrix.printMatrix();
        System.out.println(matrix.getSollSize());
        matrix.write_to_db();
    }
Run Code Online (Sandbox Code Playgroud)

这是持久代码.

public void write_to_db() {
    Session session = null;
    try {
        session = HibernateUtil.getSessionFactory().openSession();
        session.beginTransaction();
        Matrixtr onematrixtr = new Matrixtr();
        onematrixtr.setDimension(dimension);
        onematrixtr.setMatrixstr(this.toString());
        onematrixtr.setSolsize(getSollSize());
        session.save(onematrixtr);
        for (Map.Entry<Kelimetr, List<Cell>> sollution : sollutions.entrySet()) {
            Kelimetr kelimetr = sollution.getKey();
            List<Cell> solpath = sollution.getValue();
            Solstr onesol = new Solstr();
            onesol.setKelimetr(kelimetr);
            onesol.setMatrixtr(onematrixtr);
            onesol.setSoltext(solpath.toString().replace("[", "").replace("]", "").replace("true", "").replace("false", ""));
            session.save(onesol);
        }

        session.getTransaction().commit();
        session.close();

    }
    catch (HibernateException …
Run Code Online (Sandbox Code Playgroud)

java deadlock c3p0

8
推荐指数
1
解决办法
1万
查看次数

SQL NOT IN语句不使用索引检索数据

我有简单的查询:

SELECT * FROM MH.APPOINTMENT WHERE DOCTOR_INC_ID = 1391791151
Run Code Online (Sandbox Code Playgroud)

当我检查执行计划时,我看到使用索引检索数据

但是以下查询:

SELECT * FROM MH.APPOINTMENT WHERE DOCTOR_INC_ID NOT IN (1391791151)
Run Code Online (Sandbox Code Playgroud)

没有受益于我们的指数.我们正在使用Oracle 11g Release2.欢迎任何建议.谢谢

sql oracle indexing

6
推荐指数
2
解决办法
414
查看次数

QuickSort传统与功能风格是什么导致这种差异?

我正在比较用scala语言编写的两个代码.

package chapter01

object QuickSortScalaTime {
  def sortFunctional(xs: Array[Int]): Array[Int] = {
    if (xs.length <= 1) xs
    else {
      val pivot = xs(xs.length / 2)
      Array.concat(sortFunctional(xs filter (pivot >)), xs filter (pivot ==), sortFunctional(xs filter (pivot <)))
    }
  }

  def sortTraditionl(xs: Array[Int]) {
    def swap(i: Int, j: Int) {
      val t = xs(i);
      xs(i) = xs(j);
      xs(j) = t;
    }

    def sort1(l: Int, r: Int) {
      val pivot = xs((l + r) / 2)
      var i = l;
      var j …
Run Code Online (Sandbox Code Playgroud)

scala

5
推荐指数
2
解决办法
4683
查看次数

Spring BeanUtils使用List字段复制属性

我hava Foo和Item类如下.

import java.util.ArrayList;
import java.util.List;

public class Foo {
    private Long id;
    private List<Item> items;

    public Foo(Long id) {
        this.id = id;
        this.items = new ArrayList<Item>();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public List<Item> getItems() {
        return items;
    }

    public void setItems(List<Item> items) {
        this.items = items;
    }
}


public class Item {
    private String bar;

    public Item(String bar) {
        this.bar = bar;
    }

    public String getBar() { …
Run Code Online (Sandbox Code Playgroud)

java spring

5
推荐指数
1
解决办法
1万
查看次数

这个代码可以在socket io中引起竞争条件吗?

我是节点js和socket io的新手.此代码是否可以导致计数器变量的竞争条件.我应该使用锁定库来安全地更新计数器变量.

"use strict";

module.exports = function (opts) {
    var module = {};

    var io = opts.io;

    var counter = 0;

    io.on('connection', function (socket) {

        socket.on("inc", function (msg) {
            counter += 1;
        });

        socket.on("dec" , function (msg) {
            counter -= 1;
        });

    });


    return module;
};
Run Code Online (Sandbox Code Playgroud)

node.js socket.io

4
推荐指数
1
解决办法
876
查看次数

很难理解为什么这个函数被称为MapReduce

在我的Scala课程中给出了一个例子.它是关于寻找更通用的函数,可用于定义算术求和函数和算术生成函数.以下是应该概括的函数.

def sum(f:Int=>Int)(a:Int,b:Int):Int ={
 if(a>b) 0
 else f(a) + sum(f)(a+1,b)
}

def product(f:Int=>Int)(a:Int,b:Int):Int={
 if(a>b)1
 else f(a)*product(f)(a+1,b)
}
Run Code Online (Sandbox Code Playgroud)

为了概括这些功能,老师给出了这样一个功能:

def mapReduce(f:Int=>Int,combine: (Int,Int)=>Int, zero:Int)(a:Int,b:Int):Int ={
    if(a>b) zero
    else combine(f(a),mapReduce(f, combine, zero)(a+1, b))
}
Run Code Online (Sandbox Code Playgroud)

因此mapReduce函数可用于概括sum和product函数,如下所示:

def sumGN(f:Int=>Int)(a:Int,b:Int) = mapReduce(f, (x,y)=>(x+y), 0)(a, b)
def productGN(f:Int=>Int)(a:Int,b:Int) = mapReduce(f, (x,y)=>(x*y), 1)(a, b)
Run Code Online (Sandbox Code Playgroud)

我看了一下函数式编程中map reduce的定义,但是我很难将泛化函数命名为map reduce.我无法理解这种关系.任何帮助都会让我非常开心.

问候

reduce scala map

3
推荐指数
1
解决办法
1203
查看次数

Java中静态变量和初始化顺序的文本顺序

我只花了五分钟在SO中找到一份副本.

我的问题很简单.以下代码是否始终有效?

public class LexicalOrderStatic {
    private static Integer a1 = initA1();

    private static Integer a2 = initA2();


    private static Integer initA2(){
        return new Integer(5) / a1;
    }

    private static Integer initA1(){
        return new Integer(5);
    }

    public Integer getA1(){
        return new Integer(a2);
    }

    public static void main(String[] args) {
        LexicalOrderStatic lexLuthor = new LexicalOrderStatic();
        System.out.println(lexLuthor.getA1());

    }
}
Run Code Online (Sandbox Code Playgroud)

在java中我可以确定a1 总是在a2之前初始化吗?

谢谢.如果被问到或者它是否非常简单,Dw就可以了.

java

2
推荐指数
1
解决办法
396
查看次数

用于将列表映射到列表元素顺序的简单scala代码.(用于生成行号)

我有简单的scala代码:

object CollectionSnippets extends App {

  var closureVal = 0 
  def lineNum(s:String) : String = {
    closureVal = closureVal + 1;
    closureVal.toString + "." + s;
  }
  val list1 = List("aline","aline","aline")

  val list2 = list1.map(lineNum)

  list2.foreach(println)

}
Run Code Online (Sandbox Code Playgroud)

问题是我正在改变变量,我觉得这不是正确的做法.

你能建议我一个更好的方法吗?

scala

2
推荐指数
1
解决办法
87
查看次数