小编Ach*_*ome的帖子

RequireJS和CommonJS之间的区别

我想知道这些片段之间的区别是什么.

var $ = require('jquery');
var _ = require('underscore');
var BackBone = require('backbone');
Run Code Online (Sandbox Code Playgroud)

require(['jquery','underscore','backbone'],function ($, _, BackBone){
    //code goes here
})
Run Code Online (Sandbox Code Playgroud)

两者对我来说都很好,但不确定它们背后的任何目的.

javascript node.js requirejs

17
推荐指数
1
解决办法
5243
查看次数

如何使用被动事件流同时处理鼠标和触摸事件

我正在构建一个音频播放控件,让用户可以在音频文件中来回擦洗.它需要处理触摸和鼠标事件.我应该如何使用被动事件流来管理事件?

以下是我希望如何构建它的大致想法.

<div id="timeline">
  <span id="scrubber"></span>
</div>
Run Code Online (Sandbox Code Playgroud)

然后,使用Bacon.js创建事件流

var mousedowns = $('#timeline').asEventStream('mousedown');
var touchstarts = $('#timeline').asEventStream('touchstart');

var starts = Bacon.mergeAll(mousedowns, touchstarts);

var mousemoves = $('#timeline').asEventStream('mousemove');
var touchmoves = $('#timeline').asEventStream('touchmove');

var moves = Bacon.mergeAll(mousemoves, touchmoves);

var mouseups = $('#timeline').asEventStream('mouseup');
var touchends = $('#timeline').asEventStream('touchend');

var ends = Bacon.mergeAll(mouseups, touchends);

starts.onValue(function () {
  var repositionScrubber = moves.onValue(function (ev) {
    $('#scrubber').moveTo(ev.offsetX);
  });
  ends.onValue(function () {
    repositionScrubber.stop();
  });
});
Run Code Online (Sandbox Code Playgroud)

我确定这是各种各样的错误,但我真的很擅长处理具有可观察流的事件,我还不知道它有什么好的烹饪书.任何帮助将不胜感激!

javascript touch reactive-programming rxjs bacon.js

6
推荐指数
1
解决办法
1742
查看次数

在SQL中查找连续增加的数字的最长序列

对于这个例子,我说我有一个包含两个字段的表,AREA varchar(30)OrderNumber INT.

该表具有以下数据

AREA      | OrderNumber
Fontana   |       32
Fontana   |       42
Fontana   |       76
Fontana   |       12
Fontana   |        3
Fontana   |       99
RC        |       32
RC        |        1
RC        |        8
RC        |        9
RC        |        4
Run Code Online (Sandbox Code Playgroud)

我想回来

我想要返回的结果是每个区域增加连续值的最长长度.为了Fontana it is 3 (32, 42, 76).For RC it is 2 (8,9)

AREA    | LongestLength
Fontana |          3
RC      |          2
Run Code Online (Sandbox Code Playgroud)

我如何在MS Sql 2005上执行此操作?

sql sql-server

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

在对已解析的xml数据执行计算时,如何避免除零错误

请善待您的答案我现在已经编码了10天.我在代码中执行循环时遇到问题,但我相当肯定这是因为我得到了一个回溯.

我使用以下代码解析从url获取的xml文件:

pattern4 = re.compile('title=\'Naps posted: (.*) Winners:')
pattern5 = re.compile('Winners: (.*)\'><img src=')

for row in xmlload1['rows']:
    cell = row["cell"]

##### defining the Keys (key is the area from which data is pulled in the XML) for use   in the pattern finding/regex
    user_delimiter = cell['username']
    selection_delimiter = cell['race_horse']

##### the use of the float here is to make sure the result of the strike rate calculations returns as a decimal, otherwise python 2 rounds to the nearest integer! 
    user_numberofselections = …
Run Code Online (Sandbox Code Playgroud)

python loops division divide-by-zero python-2.7

0
推荐指数
1
解决办法
9377
查看次数

Java同步语句

我需要像这样的线程安全的arraylist.

public class BookingList {

  private List<Booking> bookings;

  public BookingList() {
      bookings = Collections.synchronizedList(new ArrayList<Booking>());
  }

  @Override
  public void addBooking(Booking booking)
  {
    synchronized (bookings) {
        bookings.add(booking);
    }   
  }

  @Override
  public void removeBooking(Booking booking)
  {
    synchronized (bookings) {
        bookings.remove(booking);
    }   
  }
}
Run Code Online (Sandbox Code Playgroud)

根据java doc,当使用Collections.synchronizedList时,需要同步对列表的每次访问.我不确定我的同步块是否会这样做?

  1. 我使用的synchronized块是否相当于

    ...
    public synchronized void addBooking(Booking booking) {
      bookings.add(booking);
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. 我应该像这样使用ReentrantLock吗?

    private Lock lock = new ReentrantLock();
    public void addBooking(Booking booking) {
      try {
        lock.lock;
        bookings.add(booking);
      } finally {
        lock.release();
      }
    }
    
    Run Code Online (Sandbox Code Playgroud)

java synchronization synchronized-block reentrantlock

0
推荐指数
1
解决办法
404
查看次数

在Python中查找列表中的5个最小数字

我有一个名单列表,x和一个与名称对应的分数列表y.

x = {a,b,c,d,e,f,g,h,i,j,k} 
y= {8,8,15,13,12,17,18,12,14,14} 
Run Code Online (Sandbox Code Playgroud)

所以,a得分为8,b得分为8,c得分为15,......,k得分为14

我想从列表中找到5个最小的分数,y,并得到他们的名字,并打印出类似于以下内容:

前5名得分最低:

a : 8
b : 8 
e : 12
h : 12 
d : 13
Run Code Online (Sandbox Code Playgroud)

目前,我正在创建列表的副本,然后使用pop来减少列表,但是它给了我不正确的分数名称.但是,当我为max5值创建列表时,使用相同的方法一切都很好.我不确定一个允许我在python中执行此操作的函数.这只是我的问题的一个例子,我的真正问题涉及商店位置以及我从一个函数计算的那些商店的分数,但我想获得前5名最高分和5分最低分.有没有人有这个有效的解决方案?

python sorting max minimum

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

Java Test Class中的错误

这是我有错误的测试类,我无法弄清楚它究竟是什么.

import java.util.*;
public class EmployeeTest 
{

public static void main(String[] args) {
    Employee e = new Employee();
    e.setId("100012");
    e.setLastname("Smith"); 
    ResponsibilityDecorator d;
    d = new Recruiter(e);
    d = new CommunityLiaison(e);
    d = new ProductionDesigner(e);      
    System.out.println(e.toString());
}
}
Run Code Online (Sandbox Code Playgroud)

这是链接到测试类的类

public class Employee 
{

String id;
String lastname;

Employee(String id, String lastname) 

{

    this.id=id;
    this.lastname=lastname;

}
 EmploymentDuties eduties=new EmploymentDuties();

public EmploymentDuties getDuties()
{
    return eduties;
}
public String toString(){
    return "Duties for this employee: "+eduties.jobtitles;
}

public void setId(String id)
{
    this.id …
Run Code Online (Sandbox Code Playgroud)

java decorator

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