我正在尝试以编程方式对我正在编辑的文件执行'OrganizeImports'.我的代码看起来像这样:
final ICommandService cmdService = (ICommandService)PlatformUI.getWorkbench().getService (ICommandService.class);
if (cmdService != null) {
final Command cmd = cmdService.getCommand(IJavaEditorActionDefinitionIds.ORGANIZE_IMPORTS);
final ExecutionEvent execEvt = new ExecutionEvent(cmd, Collections.EMPTY_MAP, compileationUnit, null);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ResourcesPlugin.getWorkspace().
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
try {
//cmd.executeWithChecks(execEvt);
cmd.execute(execEvt);
} catch (Exception e) {
getLogger().severe("organize imports failed: " + e.getMessage());
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是OrganizeImportsAction在当前选择上执行,这与我正在编辑的编译单元不同.我想在编译单元上以编程方式设置选择,但我不知道如何做到这一点.或者可能还有另一种触发OrganizeImports的方法.
谢谢,斯特凡
为什么我们更喜欢对文件的较小分区进行排序,并在为快速排序(非递归实现)分区后将更大的分区推入堆栈?这样做可以减少随机文件的快速排序O(log n)的空间复杂性.有人可以详细说明吗?
可以任何人告诉我如何使用Xcode 4在我的iphone/ipad project.im中集成FFMPEG.我搜索了很多但没有找到任何有用的链接.请告诉我一步一步的程序将FFMpeg集成到我的项目中.
谢谢,
我正在创建一个Google App Engine网络应用程序来"转换"10K~50M的文件
场景:
(现在我没有实现第4步,servlet将文件发回而不进行转换.)
问题:它适用于15MB文件但不适用于40MB文件,说:"错误:请求实体太大.您的客户发出的请求太大了."
对此有任何解决方法吗?
源代码:https://github.com/nicolas-raoul/transdeck
原理:http://code.google.com/p/ankidroid/issues/detail ? id = 697
我想知道是否有办法将zip文件上传到django web服务器并将zip文件放入django数据库而不访问过程中的实际文件系统(例如将zip文件解压缩到tmp目录然后加载它们)
Django提供了一个将python文件转换为Django文件的函数,所以如果有一种方法将ZipExtFile转换为python文件,它应该没问题.
感谢帮助!
Django模型:
from django.db import models
class Foo:
file = models.FileField(upload_to='somewhere')
Run Code Online (Sandbox Code Playgroud)
用法:
from zipfile import ZipFile
from django.core.exceptions import ValidationError
from django.core.files import File
from io import BytesIO
z = ZipFile('zipFile')
istream = z.open('subfile')
ostream = BytesIO(istream.read())
tmp = Foo(file=File(ostream))
try:
tmp.full_clean()
except Validation, e:
print e
Run Code Online (Sandbox Code Playgroud)
输出:
{'file': [u'This field cannot be blank.']}
Run Code Online (Sandbox Code Playgroud)
[解决方案]解决方案使用丑陋的黑客:
正如Don Quest正确指出的那样,类似文件的类(如StringIO或BytesIO)应将数据表示为虚拟文件.但是,Django File的构造函数只接受内置文件类型而不接受任何其他内容,尽管类文件类也可以完成这项工作.黑客是手动设置Django :: File中的变量:
buf = bytesarray(OPENED_ZIP_OBJECT.read(FILE_NAME))
tmp_file = BytesIO(buf)
dummy_file = File(tmp_file) # this line actually fails
dummy_file.name = SOME_RANDOM_NAME …
Run Code Online (Sandbox Code Playgroud) 我的/ var/log/messages中出现了很多suhosin错误
Dec 22 06:28:12 server suhosin[4637]: ALERT - configured request variable name length limit exceeded - dropped variable '66583-((-....-..................-....-__-......-................-......-............-........-......-\\__-))' (attacker '127.0.0.1', file '/home/user/public_html/vb/showthread.php')
Dec 22 06:28:14 server suhosin[4620]: ALERT - configured request variable name length limit exceeded - dropped variable '125055-........-..............-............-Zombie-Driftwood-2010-DVDrip-..........-............-......-18-............-......-........-............' (attacker '127.0.0.1', file '/home/user/public_html/vb/showthread.php')
Run Code Online (Sandbox Code Playgroud)
这是我的php.ini
文件中的suhosin配置
[suhosin]
suhosin.cookie.encrypt = Off
suhosin.request.max_vars = 10000
suhosin.request.max_value_length = 65000
suhosin.post.max_vars = 10000
suhosin.post.max_value_length = 5000
suhosin.get.max_vars = 10000
suhosin.get.max_value_length = 10000
suhosin.memory_limit = 128M
Run Code Online (Sandbox Code Playgroud)
那么我该如何解决这个问题呢?我试图提高上面的所有值,但它也不起作用.
是否可以(?P<toto>...)
使用等效的re.findall()
?访问正则表达式中定义的符号组名称?
使用re.match()
,重新返回一个可以使用MatchObject
该功能的.group('toto')
...我想做一些接近的事情.
这是一个例子:
import re
my_str = 'toto=1, bip=xyz, toto=15, bip=abu'
print re.findall('toto=(?P<toto>\d+)\,\sbip=(?P<bip>\w+)', my_str)
Run Code Online (Sandbox Code Playgroud)
它返回:
[('1', 'xyz'), ('15', 'abu')]
Run Code Online (Sandbox Code Playgroud)
我想得到类似的东西:
[{'toto':'1', 'bip':'xyz'}, {'toto':'15', 'bip':'abu'}]
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法呢?我在任何地方找不到它......
有谁知道如何使用按估计频率排序的JWNL(Java Wordnet Library)来获取单词的同义词?我知道这可以以某种方式完成,因为Wordnet的应用程序可以做到这一点.(我不知道是否重要,但我使用的是Wordnet 2.1)
以下是我如何获取同义词的代码,任何人都可以告诉我应该添加的内容......(完全不同的方式也欢迎!)
ArrayList<String> synonyms=new ArrayList<String>();
System.setProperty("wordnet.database.dir", filepath);
String wordForm = "make";
Synset[] synsets = database.getSynsets(wordForm,SynsetType.VERB);
if (synsets.length > 0) {
for (int i = 0; i < synsets.length; i++) {
String[] wordForms = synsets[i].getWordForms();
for (int j = 0; j < wordForms.length; j++) {
if(!synonyms.contains(wordForms[j])){
synonyms.add(wordForms[j]); }
}
}
}
Run Code Online (Sandbox Code Playgroud) 所以我仍然在使用Mockito时遇到麻烦.所以我们假设我有以下类(请忽略它的逻辑或结构,它只是我从另一个类创建的一个简短示例,具有不同的名称等等.):
public class Restaurant(
@Autowired
private CustomerService customerService;
private CustomerInputData updateCustomer(CustomerInputData inputData){
String customerId = inputData.getID();
Customer customer = customerService.getCustomerById(customerID);
if(customer.getAddress() != null){
inputData.setCustomerName(customer.getCustomerName());
inputData.setCustomerCity(customer.getCustomerCity);
inputData.setCustomerLanguage(customer.getLanguage);
}
return inputData
}
}
Run Code Online (Sandbox Code Playgroud)
因此,我对单元测试的理解是,隔离所有依赖项.在这里,我将拥有客户级和客户服务.
所以要写一个测试类,我现在会做以下事情:
public class RestaurantTest()
{
@Mock(name="customerService");
private CustomerService customerService;
@InjectMocks
private Restaurant classUnderTest;
@Before
public void setUp(){
MockitoAnnotations.initMocks(this);
}
@Test
public void updateCustomer_WithValidInput_ShouldReturnUpdatedInput(){
//Some Mocking first
String customerId = "customerId";
Customer customer = mock(Customer.class);
CustomerInputData = mock(CustomerInputData.class);
doReturn(customer).when(customerService.getCustomerById(any(String.class)));
doReturn(customerId).when(inputData.getId());
doReturn("address").when(customer.getAddress());
doReturn("Name").when(customer.getName());
doReturn("City").when(customer.getCity());
doReturn("Language").when(customer.getLanguage());
doNothing().when(inputData).setCustomerName(any(String.class));
doNothing().when(inputData).setCustomerCity(any(String.class));
doNothing().when(inputData).setCustomerLanguage(any(String.class));
verify(customer.getAddress(), atLeastOnce()); …
Run Code Online (Sandbox Code Playgroud)