coding-style

Silverlight Listbox Item Style

纵然是瞬间 提交于 2019-12-08 00:42:45
问题 How would one go about styling a listbox such that the selection has a different text color than the default view? I've looked at this in several ways and because the ContentPresenter lacks a Foreground property. The default control template of the listbox provides several rectangles which one can use to adjust the highlight color. For example, with the default style a rectangle called BGColor3 has its opacity adjusted to get a highlight effect. Here is the bulk of my control template: <Grid>

Attribute lists or inheritance jungle?

≡放荡痞女 提交于 2019-12-08 00:13:19
问题 I've got 2 applications (lets call them AppA and AppB) communicating with each other. AppA is sending objects to AppB. There could be different objects and AppB does not support every object. An object could be a Model (think of a game, where models are vehicles, houses, persons etc). There could be different AppBs. Each supporting another base of objects. E.g. there could be an AppB which just supports vehicle-models. Another AppB just supports specific airplane-models. The current case is

Endianness conversion and g++ warnings

夙愿已清 提交于 2019-12-07 20:52:05
问题 I've got the following C++ code : template <int isBigEndian, typename val> struct EndiannessConv { inline static val fromLittleEndianToHost( val v ) { union { val outVal __attribute__ ((used)); uint8_t bytes[ sizeof( val ) ] __attribute__ ((used)); } ; outVal = v; std::reverse( &bytes[0], &bytes[ sizeof(val) ] ); return outVal; } inline static void convertArray( val v[], uint32_t size ) { // TODO : find a way to map the array for (uint32_t i = 0; i < size; i++) for (uint32_t i = 0; i < size;

Java eclipse highlight missing brackets

北战南征 提交于 2019-12-07 20:03:59
问题 I just can't find the option anywhere. Is there some way in eclipse to warn about stuff like this? if(a==b)continue; instead of if(a==b){continue;} Or can maybe the format function fix this? 回答1: CheckStyle is a nice tool which can also be used as a plugin for eclipse. You can specify different kinds of coding styles you want to enforce on you / your team, by configuring rules in this tool. This could help you create your custom check. 回答2: Window-->Preferences--> Java > Editor > Save Actions

Best practice to write generic numerical functions that work with both ndarray and MaskedArray

谁说胖子不能爱 提交于 2019-12-07 17:20:35
问题 Is there a more beautiful way than: import numpy as np from numpy import ma def foo(x): pkg = ma if isinstance(x, ma.MaskedArray) else np return pkg.apply_along_axis(bar, -1, x) I feel it not Pythonic, in terms of trying to make the most out of polymorphism. EDIT The above code snippet is just a demo to highlight the fact that np and ma have highly similar (designed on purpose) interface (e.g., apply_along_axis ), but under different namespace. 回答1: isinstance() is fine as it is here. You

What is the correct way of ensuring a single instance of a class? [duplicate]

馋奶兔 提交于 2019-12-07 16:21:23
问题 This question already has answers here : What is the correct way to write a singleton pattern in Ruby? (3 answers) What is an efficient way to implement a singleton pattern in Java? [closed] (29 answers) Closed last year . In java I would create something like this: private static MyClass instance; public static MyClass getInstance() { if(instance != null) { return instance; } instance = new MyClass(); return instance; } What is the appropriate way to obtain the same functionality in ruby?

Why is “lower-case with dashes” the standard for HTML classes? [duplicate]

拥有回忆 提交于 2019-12-07 14:37:24
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why are dashes preferred for CSS selectors / HTML attributes? Personally I use "lower-case with dashes" to format my HTML classes, which seems to be the standard these days. Using something like camel case seems more reserved for JavaScript in my eyes, but I realise that's just my opinion. I'm trying to improve front-end code consistency at my workplace and part of that will be coding guidelines. Rather than

How to get Win32 to use Windows XP style fonts

僤鯓⒐⒋嵵緔 提交于 2019-12-07 12:21:00
问题 I'm writing a Win32 application using plain C and WinAPI. No MFC or C++ is allowed. To get the controls to draw using the appropriate style, I use a manifest, as described in the corresponding MSDN article. Everything is fine, and when I change the system style, my application changes style as well. But the font used is just ugly. How do I force the application to use the standard system font? 回答1: You can use SystemParametersInfo with SPI_GETNONCLIENTMETRICS parameter to retrieve the current

Initializing disposable resources outside or inside try/finally

╄→尐↘猪︶ㄣ 提交于 2019-12-07 12:16:50
问题 I have seen two ways of acquiring and disposing resources. Either: Resource resource = getResource(); try { /* do something with resource */ } finally { resource.close(); } or: Resource resource = null; try { resource = getResource(); /* do something with resource */ } finally { if (resource != null) resource.close(); } I was wondering which style is preferable. The first one avoids the if condition, while the second one (I presume) handles the case of thread abort right after the assignment

Early return/golden path in Swift

╄→гoц情女王★ 提交于 2019-12-07 11:14:48
问题 I'm used to write code with early return/golden path in Objective-C. I tried this approach in Swift, and noticed that early return comes at the expense of using the forced unwrapping operator ( ! ) when optionals are involved. Take a method that calculates the size of a directory. First, the golden path version: private func calculateSize_GoldenPath(directory:String) -> UInt64 { let fileManager = NSFileManager.defaultManager() var error : NSError? var contents = fileManager