coding-style

Prevent CSS Inheritance

谁说我不能喝 提交于 2019-12-11 12:22:32
问题 I am trying to write a jQuery plugin that can be ported to any site. What my plugin does is create a div and applies a style to it. It works well in standalone but when I put it into the context of a site, there is a css class that it is inheriting from. The thing is, I can't modify the web site's existing CSS... so I need a way to "prevent inheritance" (which I know is technically not possible). I have tried the !important flag on the specific styles that are causing problems, but to no

How can I make this into a loop?

本秂侑毒 提交于 2019-12-11 10:39:33
问题 Writing an LSH program in Java, during this first part I read through 5 different text files and pulled out all the unique words. Then created 5 different shuffling of the words. Now, the code I came up with works, obviously, but I know anytime you copy paste the same block of code a bunch of times, you generally could have done it cleaner using a loop. I just, in this instance, can't figure out how. I feel like its bad practice to do it the way I did, so in the future I'd love to avoid this.

Best practice for tiny code reuse in PHP

寵の児 提交于 2019-12-11 10:35:38
问题 For a long time I have a problem - should I reuse small parts of code and if so, how should I do it so it would be the best practice. What I mean about small code is for example: if (!is_array($table)) { $table = array($table); } or $x = explode("\n", $file_content); $lines = array(); for ($i=0, $c = count($x); $i<$c; ++$i) { $x[$i] = trim($x[$i]); if ($x[$i] == '') { continue; } $lines[] = $x[$i]; } Such tiny parts of code may be used in many classes in one project but some of them are used

How often to derive from boost::signals::trackable?

一世执手 提交于 2019-12-11 10:16:35
问题 When using Boost.Signals, boost allows you to derive from boost::signals::trackable in order to ease object/connection lifetime management (See the boost documentation). I am in an early stage of my project and I am thinking, whether to derive from boost::signals::trackable in every new class I write that might use Boost.Signals in the future or only in classes I am sure that they will need the functionality of the trackable bas e-class The main reason for th first approach would be to

Problems changing the style of certain items in a ListView

最后都变了- 提交于 2019-12-11 10:09:48
问题 I have a ListView of TextViews and to highlight one of these, I want to make the TextView bold . This only works if I don't scroll the ListView. After I scroll, the boldness changes to a different position. Does anyone know why, or how I can solve this problem? 回答1: It may be problem with ListView, because listview reuses view items (and puts content inside them), if you are using convertView feature. It's hard to say without seeing your code where it goes wrong. You could try using Html

ref keyword with reference type parameter [closed]

╄→尐↘猪︶ㄣ 提交于 2019-12-11 09:55:20
问题 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 . I think it is more clear that if I pass reference type parameter to the method, that will be changed inside method to add ref keyword like this void Foo(ref Boo boo) { boo.Value = 6; } , even this doesn't affect program execution any way and by default objects are passed by

Tips for refactoring repetitive code in R

穿精又带淫゛_ 提交于 2019-12-11 09:27:13
问题 How would a real R programmer go about writing blocks of code with redundant steps? Here I'm copy/pasting/editing each line, which works fine for this small analysis, but for bigger ones gets unwieldy. In SAS, I'd write macros. Looking for a generating principle in R. This example has a few typical patterns, like recoding a set of columns that are consecutive and/or have a numbering pattern. Also the recoding logic is just "replace NA with 0 and then add 1" as input to another algorithm that

setting width of div jquery

落花浮王杯 提交于 2019-12-11 09:14:21
问题 I'm trying to set the width of a div using jquery. this is how I'm trying to set the size of the div $('#page').css("width",data[0]['imageWidth']); and this is the div I'm trying to set <div id="page"> </div> any help with this would be much appreciated 回答1: In CSS lengths require a unit, in this case most likely Pixel ( px ): $('#page').css("width",data[0]['imageWidth'] + "px"); 来源: https://stackoverflow.com/questions/3881693/setting-width-of-div-jquery

calling method Versus class.method

二次信任 提交于 2019-12-11 09:08:10
问题 I have a class with two methods defined in it. public class Routines { public static method1() { /* set of statements */ } public static method2() { /* another set of statements.*/ } } Now I need to call method1() from method2() Which one the following approaches is better? Or is this qualify as a question? public static method2() { method1(); } OR public static method2() { Routines.method1(); } 回答1: While I agree with the existing answers that this is primarily a style issue, it is enough of

Clean code - how to design this class?

瘦欲@ 提交于 2019-12-11 08:22:18
问题 I have been reading the "Clean code" book and particularly the part on Hybrid classes and the difference between data structures and objects. I have an SFTPUtil class with one method for deleting a file from an sftp server. Currently it looks like what is described as a Hybrid class like so: String host; int port; String rootDirectory; String username; String password; public void deleteFile(String filename){ // Code using the instance variables above } //GETTERS AND SETTERS FOR INSTANCE