我激活了一个安装了pip的virtualenv.我做到了
pip3 install Django==1.8
Run Code Online (Sandbox Code Playgroud)
和Django成功下载.现在,我想打开Django文件夹.文件夹位于何处?通常它会在"下载"中,但我不确定如果我在virtualenv中使用pip安装它会是什么.
在许多iOS应用程序中,我可以看到一个按钮,说明getDirections,点击后会打开经过目的地的纬度和经度的Apple/Google地图.
我的TouchableHighlight按钮有lat和lng准备好了.我需要在onPress回调中调用什么API端点来打开Apple坐标作为路径目的地的坐标?
我有一项任务,要求我安排任务,并在发生特定事件时将其删除.我正在使用ScheduledThreadPoolExecutor来安排任务,这非常简单.但是,我找到了两种取消待处理项目的方法,它们看起来有点奇怪.
我很好奇他们是否有生产质量.如果他们两个都没有,那你有什么建议?
这是我做的骨架:
private final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1);
public void doStuff() {
//...
scheduler.schedule(new Runnable() {/*...*/}, 10, TimeUnit.MILISECONDS)
}
public void actOnEvent() {
cancelPendingItems();
doMoreStuff();
}
public void cancelPendnigItems() {
// TODO implement me
}
Run Code Online (Sandbox Code Playgroud)
这是候选人1:
public void cancelPendingItems() {
scheduler.getQueue().clear();
}
Run Code Online (Sandbox Code Playgroud)
这是候选人2:
public void cancelPendingItems() {
for (Runnable task : scheduler.getQueue()) {
scheduler.remove(task);
}
}
Run Code Online (Sandbox Code Playgroud)
两者看起来像是一个黑客,因为它们依赖于ScheduledExecutor接口中未指定的ScheduledThreadPoolExecutor.queue属性.我有点担心我可能会违反ScheduledThreadPoolExecutor的不变量而且我会发现它太迟了.
那么,这些片段是否会按照我希望他们做的去做?有没有更好/更清洁的方法呢?
我在我们的代码中使用以下代码片段。
ExecutorService executor = Executors.newFixedThreadPool(4);
while(loop 50 times){
//In the extreme case I will have 50 threads and only 4 will be active and remaining are in queue
MyThread myThread = new MyThread();
executor.execute(myThread);//Each Thread process 100,000 records and put in a file
}
executor.shutdown();
while (!executor.isTerminated()) {
}
Run Code Online (Sandbox Code Playgroud)
以下是我的问题:
请帮我解决这个问题。
一些编程语言提供动态执行正则表达式替换的能力。
例如,假设我们有一个像foo:$USER:$GROUP, where$USER和$GROUP将被它们的环境变量替换的字符串。转换后的字符串看起来像foo:john:admin. 为了解决这个问题,我们必须取所有匹配的字符串\$[A-Za-z]+并查找环境变量值。
在 PHP 中,如下所示:
<?php
preg_replace_callback(
# the regular expression to match the shell variables.
'/\$[A-Za-z]+/',
# Function that takes in the matched string and returns the environment
# variable value.
function($m) {
return getenv(substr($m[0], 1));
},
# The input string.
'foo:$USER:$GROUP'
);
Run Code Online (Sandbox Code Playgroud)
Python中有类似的东西吗?
我的观点
def apost(request):
if request.method =='POST':
form = APostForm(request.POST, request.FILES)
if form.is_valid():
form = form.save(commit=False)
form.slug = slugify(form.title)
form.save()
return redirect('apost')
else:
form = APostForm()
template_name = 'dadmin/form.html'
items = Post.objects.all()
context = {'title':'Add Post','form':form,'items':items}
return render (request, template_name, context)
Run Code Online (Sandbox Code Playgroud)
我的表格
class APostForm(forms.ModelForm):
class Meta:
model = Post
fields = {'title','photo','content'}
Run Code Online (Sandbox Code Playgroud)
楷模
photo = models.ImageField(upload_to='images')
Run Code Online (Sandbox Code Playgroud)
没有图像上传被接受 照片被选中,但是当点击保存时。它显示此字段是必需的错误。我已经在这里搜索了问题,但 request.FILES 解决了其他问题,但不能解决我的问题。怎么了?
我想使用Java 8从字符串转换为日期。
我可以轻松地使用SimpleDateFormat和进行yyyy-MM-dd格式转换
String startDate2="2017-03-24";
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
System.out.println(new java.sql.Date(sdf1.parse(startDate2).getTime()));
Run Code Online (Sandbox Code Playgroud)
输出: 2017-03-24
String startDate2="2017-03-24";
SimpleDateFormat sdf1 = new SimpleDateFormat("uuuu-MM-dd");
System.out.println(new java.sql.Date(sdf1.parse(startDate2).getTime()));
Run Code Online (Sandbox Code Playgroud)
但是当我用'uuuu-MM-dd'代替'yyyy-MM-dd'
输出:(
1970-03-24错误)
现在在Java 8中:
String startDate1="2017-03-23";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd");
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何获取与上述正确输出相同的sql date类型的日期。
在我的程序中,我正在读取单元测试的资源文件。我使用文件路径为:
\\\path\\\to\\\file
Run Code Online (Sandbox Code Playgroud)
在我的机器(Windows)上运行良好。但在服务器(Unix)上,这失败了,我必须将其更改为:/path/to/file
但Java 应该是平台无关的。那么这样的行为是不是出人意料呢?
Follwing是我的示例项目中的代码片段.但它在我的实际项目中不起作用.
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable||!CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
var filePath = await CrossMedia.Current.TakePhotoAsync(newPlugin.Media.Abstractions.StoreCameraMediaOptions
{
SaveToAlbum = true
});
Run Code Online (Sandbox Code Playgroud)
例外:
java.lang.NullPointerException: Attempt to invoke virtual method
'android.content.res.XmlResourceParser
android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager,
java.lang.String)' on a null object reference
at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:560)
at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:534)
at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:376)
at md5a3e164e78ade0c22cefea770ddd0bc49.MediaPickerActivity.n_onCreate(NativeMethod) at md5a3e164e78ade0c22cefea770ddd0bc49.MediaPickerActivity.onCreate(MediaPickerActvity.java:42)
at android.app.Activity.performCreate(Activity.java:6092)
Run Code Online (Sandbox Code Playgroud) java ×4
django ×2
python ×2
concurrency ×1
executors ×1
java-8 ×1
php ×1
pip ×1
python-3.x ×1
react-native ×1
regex ×1
virtualenv ×1