我在python控制台中尝试过这个命令:
re.match('^\<.+\>([\w\s-,]+)\<.+\>$', 'Carrier-A')
Run Code Online (Sandbox Code Playgroud)
我得到了:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/re.py", line 141, in match
return _compile(pattern, flags).match(string)
File "/usr/lib/python2.7/re.py", line 251, in _compile
raise error, v # invalid expression
sre_constants.error: bad character range
Run Code Online (Sandbox Code Playgroud)
但是当我使用时:
re.match('^\<.+\>([\w\s,-]+)\<.+\>$', 'Carrier-A')
Run Code Online (Sandbox Code Playgroud)
没有错误返回.
关于字符序列我应该考虑什么?
我尝试在按钮中手动设置高度/宽度,但它不起作用.然后实现了Layoutparams.但是尺寸显示小而且没有得到所需的dp值.
XML
<Button
android:id="@+id/itemButton"
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:background="#5e5789"
android:gravity="bottom"
android:padding="10dp"
android:text=""
android:textColor="#FFF"
android:textSize="10sp" />
Run Code Online (Sandbox Code Playgroud)
构造函数:
public Item (int id, String name, String backgroundColor, String textColor, int width, int height){
this.id = id;
this.name = name;
this.backgroundColor = backgroundColor;
this.textColor = textColor;
this.width = width;
this.height = height;
}
Run Code Online (Sandbox Code Playgroud)
适配器:
@Override public void onBindViewHolder(final ViewHolder holder, int position) {
final Item item = items.get(position);
holder.itemView.setTag(item);
holder.itemButton.setText(item.getName());
holder.itemButton.setTextColor(Color.parseColor(item.getTextColor()));
holder.itemButton.setBackgroundColor(Color.parseColor(item.getBackgroundColor()));
ViewGroup.LayoutParams params = holder.itemButton.getLayoutParams();
params.width = item.getWidth();
params.height = item.getHeight();
holder.itemButton.setLayoutParams(params);
}
Run Code Online (Sandbox Code Playgroud) 我正在玩ES6类,我的最终目标是了解类与构造函数与工厂函数之间的区别。我目前的理解是,构造函数和类基本上使用相同的设计模式,而类只是构造函数的新语法。基于此假设,我试图创建一些示例,以显示类/构造函数与工厂函数之间的对比。
在下面的示例中,我旨在返回新对象和继承的一些方法。
我的第一个示例使用类语法非常简单。
示例#1:类
class Person {
constructor(name, age, location, occupation) {
this.name = name;
this.age = age;
this.location = location;
this.occupation = occupation;
}
printDescription() {
console.log(`My name is ${this.name} and I'm ${this.age} years old. I live in ${this.location} and I work as a ${this.occupation}.`);
}
}
const firstUser = new Person('Tom', 30, 'Sydney', 'Teacher');
firstUser.printDescription();
Run Code Online (Sandbox Code Playgroud)
在第二个示例中,我尝试使用不同的方法来复制第一个示例,但是我不确定这是工厂构造函数还是工厂函数。
实施例#2: ?
function PersonMaker (name, age, location, occupation) {
let person = {name, age, location, occupation};
person.printDetails = () …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用AngularFire2从我的Firebase获取数据.我想查看具体数据,在从Firebase获取此数据后,我只能在特定范围内检查,而不是在对Firebase进行操作后检查.为什么会这样?
以下是我的代码:
this.af.database.list('/users/1qfcMAQnglX9jsW5GdLpPko1HqE2', { preserveSnapshot: true})
.subscribe(snapshots=>{
snapshots.forEach(snapshot => {
if(snapshot.key=="reg_boolean"){
console.log(snapshot.val());
this.bo=snapshot.val();
}
this.currentUser.push({key:snapshot.key,value:snapshot.val()});
console.log(this.currentUser);
//console.log(snapshot.key, snapshot.val());
if(this.bo==true){console.log("happy"); }; //i can access only in this scope
});
})
if(this.bo==true){console.log("happy"); }; //why i can access this value??it's undefined, this happen before the subscribe with angularfire2
Run Code Online (Sandbox Code Playgroud)
角度js中的新手 - 我正在尝试将jQuery日期选择器添加到ng-model文本框中.以下是jQuery日期选择器的链接:
src="https://resources.ibe4all.com/BrokerAssist/js/BuroRaDer_DateRangePicker.js" type="text/javascript"></script><script type="text/javascript" src="https://resources.ibe4all.com/CommonIBE/js/jquery-1.4.1.js"></script<script type="text/javascript" src="https://resources.ibe4all.com/CommonIBE/js/jquery-ui-1.8.11.custom.min.js">
<link href="https://resources.ibe4all.com/BrokerAssist/cssnew/BuroRaDer.DateRangePicker.css" rel="stylesheet" />
Run Code Online (Sandbox Code Playgroud)
jQuery日期选择器代码:
<script>
$(document).ready(function () {
$('#RDate').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true
});
//$("#RDate").click(function () {
// $(this).focus();
//});
});
function AvoidSpace(event) {
var k = event ? event.which : window.event.keyCode;
if (k == 32) return false;
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是我的HTML标记:
<body style="background-image: url(/Content/images/img_bg_2.jpg);"
ng-app="nmodule" ng-controller="ncontroller">
<form name="userForm" novalidate="novalidate">
<ng-form name="userForm" ng-submit="submitForm(userForm.$valid)">
<input type="text" name="RDate" ng-model="RDate" id="RDate"
placeholder="Enter Registration Date" required />
{{RDate}}
</ng-form>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)
日期选择器工作就像一个魅力,但我面临的问题是日期没有绑定我的角度模型,我无法在$ scope中获取日期加上我的验证不在文本框上工作,因为它没有考虑日期作为日期选择器的输入. …
在Algolia,目前我在我的数据库中搜索"亚马逊书籍",其中包含条目
我得到了"亚马逊书"作为结果.我要找的是所有带有"亚马逊"或"书籍"的条目都会显示在结果中.我该如何进行此搜索?
或者我必须从我的iOS应用程序发送多个查询 - 一个用于亚马逊,一个用于swift并解析结果?提前致谢.
我正在尝试从“音乐”应用中快速检索用户的播放列表名称。
我这样尝试
let myMediaQuery = MPMediaQuery.playlists().collections
Run Code Online (Sandbox Code Playgroud)
虽然如何在iOS的iPod Library中检索播放列表?似乎有一个答案,在Swift中不起作用
我们正在使用HashMap
中JDK 1.7
,我和代码审查过程中面临的一些问题SonarQube.
请考虑以下样本:
public class SerializationTest implements Serializable {
private Map<String,String> test1=new HashMap<>(); //Serializeable
private Map<ANEnum,String> test2=new HashMap<>(); //Serializeable
private Map<String,ASerializeableObject> test3=new HashMap<>(); //Serializeable
private Map<String,Map<String,String>> test4=new HashMap<>(); //Not Serializeable
private Map<ANEnum,Map<String,String>> test5=new HashMap<>(); //Not Serializeable
private Map<String,Map<String, ASerializeableObject>> test6=new HashMap<>(); //Not Serializeable
Run Code Online (Sandbox Code Playgroud)
声纳标记最后三个HashMap
不是serializeable
.声纳错误是(Make "test4" transient or serializable
)
据我的猜测HashMap
是serializeable
,如果它的键和值是serializeable
.但似乎如果我将一个HashMap
值设置为另一个HashMap
,原始的HashMap
根本就不会serializeable
.
这个声纳问题是否正确?!如果是我该如何解决它?
import numpy as np
import pandas as pd
import matplotlib.pyplot as pt
data1 = pd.read_csv('stage1_labels.csv')
X = data1.iloc[:, :-1].values
y = data1.iloc[:, 1].values
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
label_X = LabelEncoder()
X[:,0] = label_X.fit_transform(X[:,0])
encoder = OneHotEncoder(categorical_features = [0])
X = encoder.fit_transform(X).toarray()
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train,y_test = train_test_split(X, y, test_size = 0.4, random_state = 0)
#fitting Simple Regression to training set
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(X_train, y_train)
#predecting the test set results
y_pred = …
Run Code Online (Sandbox Code Playgroud) 我在我的Angular项目中使用Lodash,我想知道是否有更好的方法来编写以下代码:
$scope.new_arr = _.map(arr1, function(item){
return _.assign(item, {new_id: _.find(arr2, {id: item.id})});
});
$scope.new_arr = _.filter($scope.new_arr, function (item) {
return item.new_id !== undefined;
});
Run Code Online (Sandbox Code Playgroud)
我试图将一个数组中的值组合到另一个数组中的相同对象,我想忽略两个数组中没有出现的对象(它类似于连接或sql语言中的左外连接).
这是一个代码示例的小提琴:点击我!
javascript ×3
angularjs ×2
python ×2
algolia ×1
android ×1
angularfire2 ×1
csv ×1
ecmascript-6 ×1
firebase ×1
hashmap ×1
ionic2 ×1
ios ×1
ios10 ×1
java ×1
jquery ×1
lodash ×1
matplotlib ×1
numpy ×1
python-2.7 ×1
regex ×1
search ×1
sonarqube ×1
swift ×1
swift3 ×1
xml ×1