coding-style

Pythonic way to get some rows of a matrix

喜你入骨 提交于 2019-12-24 11:33:37
问题 I was thinking about a code that I wrote a few years ago in Python, at some point it had to get just some elements, by index, of a list of lists. I remember I did something like this: def getRows(m, row_indices): tmp = [] for i in row_indices: tmp.append(m[i]) return tmp Now that I've learnt a little bit more since then, I'd use a list comprehension like this: [m[i] for i in row_indices] But I'm still wondering if there's an even more pythonic way to do it. Any ideas? I would like to know

How to create and apply styles through programming in android?

让人想犯罪 __ 提交于 2019-12-24 08:23:46
问题 I am new to Android app. development. I need to change the existing style at runtime or can create new styles at runtime and I need to apply it for my buttons and textviews.. Can any one suggest me? 回答1: There are several methods to do so (most of them are provided by the super class TextView): setTextColor to change the color of foreground setTypeface to change the font style setBackgroundResource(int) to change its backgrond setPadding to add padding All of them work for EditText , Button

Should you include source code in a header file?

耗尽温柔 提交于 2019-12-24 08:21:13
问题 I am working on porting some source code to a linux system, and as expected, some stuff is broken. One thing that is throwing an error for me right now, is that someone has a .h and a .cpp file that both use fclose() The compiler is complaining about fclose() being undeclared in the header file. here was the function declaration in the header file: void closeFile() { if (fp) fclose(fp); } Now, I think this is bad style, but also - how did they get this working before? Did their version of the

Coding Style: lock/unlock internal or external?

两盒软妹~` 提交于 2019-12-24 07:35:58
问题 Another possibly inane style question: How should concurrency be locked? Should the executor or caller be responsible for locking the thread? e.g. in no particular language... Caller::callAnotherThread() { _executor.method(); } Executor::method() { _lock(); doSomething(); _unlock(); } OR Caller::callAnotherThread() { _executor.lock() _executor.method(); _executor.unlock() } Executor::method() { doSomething(); } I know little about threading and locking, so I want to make sure the code is

PHP preg_replace: remove style=“..” from img tags

邮差的信 提交于 2019-12-24 07:07:16
问题 I'm trying to find an expression for preg_replace, that deletes all inline css styles for images. For example, I have this text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. <img style="float:left; margin:0 0 10px 10px;" src="image.jpg" /> Proin vestibulum libero id nisl dignissim eu sodales. And I need to make it look like: Lorem ipsum dolor sit amet, consectetur adipiscing elit. <img src="image.jpg" /> Proin vestibulum libero id nisl dignissim eu sodales. I have tried dozens of

Trying to understand which is better in python creating variables or using expressions

纵然是瞬间 提交于 2019-12-24 06:44:38
问题 One of the practices I have gotten into in Python from the beginning is to reduce the number of variables I create as compared to the number I would create when trying to do the same thing in SAS or Fortran for example here is some code I wrote tonight: def idMissingFilings(dEFilings,indexFilings): inBoth=set(indexFilings.keys()).intersection(dEFilings.keys()) missingFromDE=[] for each in inBoth: if len(dEFilings[each])<len(indexFilings[each]): dEtemp=[] for filing in dEFilings[each]:

Trying to understand which is better in python creating variables or using expressions

混江龙づ霸主 提交于 2019-12-24 06:44:09
问题 One of the practices I have gotten into in Python from the beginning is to reduce the number of variables I create as compared to the number I would create when trying to do the same thing in SAS or Fortran for example here is some code I wrote tonight: def idMissingFilings(dEFilings,indexFilings): inBoth=set(indexFilings.keys()).intersection(dEFilings.keys()) missingFromDE=[] for each in inBoth: if len(dEFilings[each])<len(indexFilings[each]): dEtemp=[] for filing in dEFilings[each]:

How do I get a single string with an Oxford comma in Groovy?

自闭症网瘾萝莉.ら 提交于 2019-12-24 04:32:16
问题 I'm new to Groovy and am trying to sort out some of the idioms that make it attractive. For example, I'd like to take a list of strings and return a single properly punctuated string built from the list, with each element quoted. Roughly, the literal (rather generic, and probably brain-dead) approach would be def temp = things.collect({"\'${it}\'"}) switch (things.size()) { case 1: result = temp[0] break case 2: result = temp.join(" and ") break default: result = temp.take(temp.size()-1).join

.NET Coding standards and framework for a web service

主宰稳场 提交于 2019-12-24 04:32:13
问题 I have been given to the task of writing a coding standards document and creating a framework for web services. I've looked at numerous articles but I am still stumped to what is exactly required especially when developing a framework as it is completely different from application code. Has anyone got any useful tips or books they can recommend? 回答1: Check out Framework Design Guidelines by Brad Abrams. 回答2: If you think about frameworks, the best make repetitive coding tasks easier, DRY, and

Java best style for return statement - inside or outside if condition? [closed]

房东的猫 提交于 2019-12-24 02:22:07
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . Is there a better way to write the code below? I'm checking if an object is null, returning false if it is, otherwise I check another variable and choose what to do based on that. private boolean myFunction(MyObjectType myObject) { if (myObject == null) { return false; } else