我对一个名为OpenBCI的新物联网项目感兴趣,该项目基本上是一个用于读取和处理脑电波和其他生物数据的开源脑电图.在他们的文档中,他们声称通过空中传输的数据(通过RFDuino)发送24位数据.要将24位值转换为32位有符号整数,他们建议使用以下Java友好的处理代码:
int interpret24bitAsInt32(byte[] byteArray) {
int newInt = (
((0xFF & byteArray[0]) << 16) |
((0xFF & byteArray[1]) << 8) |
(0xFF & byteArray[2])
);
if ((newInt & 0x00800000) > 0) {
newInt |= 0xFF000000;
} else {
newInt &= 0x00FFFFFF;
}
return newInt;
}
Run Code Online (Sandbox Code Playgroud)
我想我正在努力了解到底发生了什么.让我们来看看第一段代码:
int newInt = (
((0xFF & byteArray[0]) << 16) |
((0xFF & byteArray[1]) << 8) |
(0xFF & byteArray[2])
);
Run Code Online (Sandbox Code Playgroud)
0xFF价值的意义是什么?<<)的目的是什么? …Spring Boot在这里.我正在实现我自己的UserDetailsServiceimpl并需要引用/使用Spring提供的UserCache:
package myorg.myapp;
import org.springframework.security.core.userdetails.UserCache;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class MyUserDetailsService implements UserDetailsService {
@Resource
private UserCache userCache;
...
}
Run Code Online (Sandbox Code Playgroud)
当我去运行我的应用程序时,我收到以下异常消息:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of
type [org.springframework.security.core.userdetails.UserCache] found for dependency: expected at
least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.annotation.Resource(shareable=true, lookup=, name=, description=, authenticationType=CONTAINER,
type=class java.lang.Object, mappedName=)}
Run Code Online (Sandbox Code Playgroud)
有什么想法为什么Spring找不到UserCache豆子?
我有两个String[]相同的长度.它们是"关联数组",意思是一个字符串的值是键,另一个字符串值是值:
String[] keys = { 'fizz', 'buzz', 'bupo' }
String[] values = { 'true', 'false', 'yes' }
Run Code Online (Sandbox Code Playgroud)
我想把这两个关联数组转换成一个Map<String,String>带有一些Groovy魔法的数组.到目前为止,我已经尝试了以下但它不起作用:
Map<String,String> kvPairs = [keys, values]
Run Code Online (Sandbox Code Playgroud)
我出错的任何想法?
我正在尝试构建一个由 shell 脚本配置的 Vagrant box (CentOS) install.sh。该脚本将执行几件事,其中第一件事涉及在其下创建正确的目录结构,/opt以便我的服务可以安装在那里并执行其他操作,例如在那里写入日志。
所以我的 Vagrant 项目(到目前为止)包括:
my-app-vagrant/
Vagrantfile
install.sh
Run Code Online (Sandbox Code Playgroud)
看起来像install.sh:
mkdir /opt/myapp
mkdir /opt/myapp/bin # Where we will install binary to (later in this script)
mkdir /opt/myapp/logs # Where the binary will write logs to
Run Code Online (Sandbox Code Playgroud)
现在,二进制文件不需要提升权限即可运行(它是通过命令行参数配置的,以写入日志)。不过,我只是希望它位于/opt上述目录结构下,至少对于这台特定的机器来说是这样。
问题是它的/opt所有者是root. 这意味着我需要使用 运行它们mkdirs,为sudo脚本提供密码sudo,然后调整目录权限,以便当应用程序运行时,它有权运行并将日志写入我的预期目的地(同样是/opt/myapp/logs)。所以我调整了一下install.sh,看起来像这样:
mkdir /opt/myapp
mkdir /opt/myapp/bin
mkdir /opt/myapp/logs
chmod -R 777 /opt/myapp # Now …Run Code Online (Sandbox Code Playgroud) 我正在尝试(如果可能的话)获得Scala匹配/ case语句来为我执行内联正则表达式匹配.
具体来说,我有一个将运行a的方法,match如果方法的输入以字符串"fizz"开头,那么我希望match语句选择正确的大小写:
def animalToSound(animal : String) : String = {
animal match {
case "duck" => "quack"
case "lion" => "roar"
case "dog" => "woof"
case matchesFizzRegex(animal) => "heyo!"
case _ => "meow"
}
}
def matchesFizzRegex(animal : String) : ??? = {
val fizzRegex = "fizz*".r
if(fizzRegex.match(animal)) {
???
} else {
???
}
}
Run Code Online (Sandbox Code Playgroud)
所以,如果我打电话animalToSound("fizzBuzz"),那么期望的行为是:
有什么想法,我怎么能正常工作?
用于Java的(相对)新的内置性能监视器/分析器是Mission Control。在甲骨文的文档做广告,他们可以在生产中使用,而不会产生性能开销(不到2%):
工具链[Mission Control + Flight Recorder]使开发人员和管理员可以从本地运行或部署在生产环境中的Java应用程序收集和分析数据。
我已经使用jvisualvm(VisualVM)多年了,但是由于在生产环境中可能会带来性能开销,所以人们从来没有使用过(VisualVM)。
所以我问:任务控制(及其飞行记录器)与VisualVM之间的区别是什么,它使MC / FR不会妨碍性能?还是它们不包括VisualVM提供的某些功能?
我是Spring Boot和JPA的新手。我看过在字段声明上添加JPA注释的示例,例如:
@Entity
public class Fizz {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
// other fields
public Fizz(Long id) {
super();
setId(id);
}
// setter defined here
public Long getId() {
return this.id;
}
}
Run Code Online (Sandbox Code Playgroud)
...以及在吸气剂上添加相同批注的示例,如下所示:
@Entity
public class Fizz {
private Long id;
// other fields
public Fizz(Long id) {
super();
setId(id);
}
// setter defined here
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return this.id;
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道它们在语义上是否等效,或者是否有不同的用例,您会选择其中一种。我问是因为我实际上是在Groovy中编写我的Spring Boot / JPA应用程序,而您通常不定义getter:
@Canonical
@Entity
class Fizz { …Run Code Online (Sandbox Code Playgroud) 我正在编写一个Spring Boot应用程序,它将使用Hibernate/JPA在应用程序和MySQL数据库之间保持不变.
这里我们有以下JPA实体:
@MappedSuperclass
public abstract class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@JsonIgnore
private Long id;
@Type(type="uuid-binary")
private UUID refId;
}
@Entity(name = "contacts")
@AttributeOverrides({
@AttributeOverride(name = "id", column=@Column(name="contact_id")),
@AttributeOverride(name = "refId", column=@Column(name="contact_ref_id"))
})
public class Contact extends BaseEntity {
@Column(name = "contact_given_name")
private String givenName;
@Column(name = "contact_surname")
private String surname;
@Column(name = "contact_phone_number")
private String phone;
}
@Entity(name = "assets")
@AttributeOverrides({
@AttributeOverride(name = "id", column=@Column(name="asset_id")),
@AttributeOverride(name = "refId", column=@Column(name="asset_ref_id"))
})
public class Asset extends BaseEntity {
@Column(name …Run Code Online (Sandbox Code Playgroud) 刚刚阅读了Docker覆盖网络,非常棒的东西。我似乎找不到一件事的答案。
根据文档:
我想知道为什么会这样。显然,覆盖网络需要在同行之间达成共识,但是我不确定那些“同行”为什么或者是谁。
我只是在猜测,使用Swarm时,有一些内部/内部共识服务器正在运行。
我有以下 Groovy 枚举:
enum Flower {
Tulip(1),
Daisy(2)
private int rank
Flower(int rank) {
super()
this.rank = rank
}
int getRank() {
rank
}
}
Run Code Online (Sandbox Code Playgroud)
我还有一个GardernGenerator类,它将Flower实例作为其构造函数参数之一:
class GardenGenerator {
Flower flower
int length
int width
boolean isOrganic
GardenGenerator(Flower flower, int length, int width, boolean isOrganic) {
super()
this.flower = flower
this.length = length
this.width = width
this.isOrganic =isOrganic
}
Garden createGarden() {
// ...blah whatever
}
}
Run Code Online (Sandbox Code Playgroud)
GardenGenerator当我尝试像这样创建这个实例时:
GardenGenerator gg = new GardenGenerator(Flower.Daisy, 5, 10, …Run Code Online (Sandbox Code Playgroud) java ×4
groovy ×3
spring-boot ×3
jpa ×2
apm ×1
bit-shift ×1
caching ×1
consensus ×1
constructor ×1
docker ×1
enums ×1
gossip ×1
hibernate ×1
jvisualvm ×1
linux ×1
networking ×1
performance ×1
processing ×1
regex ×1
scala ×1
shell ×1
sudo ×1
vagrant ×1