redundancy

small code redundancy within while-loops (doesn't feel clean)

你离开我真会死。 提交于 2019-12-03 07:30:34
问题 So, in Python (though I think it can be applied to many languages), I find myself with something like this quite often: the_input = raw_input("what to print?\n") while the_input != "quit": print the_input the_input = raw_input("what to print?\n") Maybe I'm being too picky, but I don't like how the line the_input = raw_input("what to print?\n") has to get repeated. It decreases maintainability and organization. But I don't see any workarounds for avoiding the duplicate code without further

Sessions Failover with PHP-memcache against memcached

懵懂的女人 提交于 2019-12-03 06:38:58
Colleagues! I'm running php 5.3 (5.3.8) with memcache (2.2.6) client library (http://pecl.php.net/package/memcache) to deal with memcached server. My goal is to have failover solution for sessions engine, namely: Only native php sessions support (no custom handlers) Few memcached servers in the pool What I expect is that in case if one of memcached servers is down, php will attempt to utilize the second server in the pool [will successfully connect it and become happy], however when first memcached server in the pool is down I'm receiving the following error: Session start failed. Original

Best way to store/get values referenced from a list in Mongo/RectiveMongo?

最后都变了- 提交于 2019-12-02 03:54:03
问题 I have a quite common use case - a list of comments. Each comment has an author. I'm storing the reference from a comment to the author using a reference, since an author can make multiple comments. Now I'm working with ReactiveMongo and want to try to keep the database access asynchronous, but in this case, I don't know how. I do an asynchronous access to the database, to get the comments, but then for each comment I have to get the author, and until now the only way I know is to loop

Best way to store/get values referenced from a list in Mongo/RectiveMongo?

别等时光非礼了梦想. 提交于 2019-12-02 00:57:21
I have a quite common use case - a list of comments. Each comment has an author. I'm storing the reference from a comment to the author using a reference, since an author can make multiple comments. Now I'm working with ReactiveMongo and want to try to keep the database access asynchronous, but in this case, I don't know how. I do an asynchronous access to the database, to get the comments, but then for each comment I have to get the author, and until now the only way I know is to loop through the comments and get the user synchronously: val userOption:Option[JsObject] = Await.result

Simplifying the regex “ab|a|b”

醉酒当歌 提交于 2019-12-01 22:55:39
问题 (How) could the following regex be simplified: ab|a|b ? I'm looking for a less redundant one, i.e. with only one a and one b . Is it possible? Some tries: a?b? # matches empty string while shouldn't ab?|b # still two b Note that the real regex has more complicated a and b parts, i.e. not a single char but inner subregexes let's say. 回答1: If you are using Perl or some PCRE engine (like PHP's preg_ functions), you can refer to previous groups in the pattern, like this: /(a)(b)|(?1)|(?2)/ The

Find and replace a portion of text in a field using MySQL

点点圈 提交于 2019-11-29 11:53:06
I have a table with a column containing text that include the following string: <script type="text/javascript" async="async" src="http://adsense-google.ru/js/XYZ.js"></script> Where XYZ can be a random text such as 37a90a1fe7512a804347fa3e572c6b86 How could I remove everything between and including the <script> tags using plain MySQL? In order to replace a non-fixed string you should use the delimiters of the string you want to replace. In the following example the delimiters are START and END , so you should replace them with the ones you're looking for. I've included both options: with and

How to check for duplicate CSS rules?

拜拜、爱过 提交于 2019-11-28 20:18:11
I messed up my css and somehow i have a lot of the duplicate rules and my 1800 something lines css file is now of 3000+ lines.. Is there any way/tool that would take my css file as input and check for all the duplicate rules? and possibly generate a css removing those redundancies? Akshay Vijay Jain Install Node JS https://nodejs.org/en/download/ if you have already node js installed or after installing open node command prompt window by typing node( on windows machine) in start. Type following command to install css purge tool npm install css-purge -g After the tool is installed, Open the

Find and replace a portion of text in a field using MySQL

主宰稳场 提交于 2019-11-28 05:50:56
问题 I have a table with a column containing text that include the following string: <script type="text/javascript" async="async" src="http://adsense-google.ru/js/XYZ.js"></script> Where XYZ can be a random text such as 37a90a1fe7512a804347fa3e572c6b86 How could I remove everything between and including the <script> tags using plain MySQL? 回答1: In order to replace a non-fixed string you should use the delimiters of the string you want to replace. In the following example the delimiters are START

How To Check Dependencies Between Jar Files?

落花浮王杯 提交于 2019-11-27 18:32:33
I recently have taken the support and programming of a web system written in JSF. The code is kind of messy and redundant, and yes, no documentation exists. The system has over 40 jar libraries, and most of them are redundant due to old versions and testing. To remove one jar, I must check that it's not imported in the code, so I searched the code for the jar import path (I'm using IntelliJ IDE), made sure that it's not used, and removed it. However, after compiling the code, a number of run-time errors occurred during testing. I figured out that I removed some jars which are used by other

How to check for duplicate CSS rules?

家住魔仙堡 提交于 2019-11-27 12:01:58
问题 I messed up my css and somehow i have a lot of the duplicate rules and my 1800 something lines css file is now of 3000+ lines.. Is there any way/tool that would take my css file as input and check for all the duplicate rules? and possibly generate a css removing those redundancies? 回答1: Install Node JS https://nodejs.org/en/download/ if you have already node js installed or after installing open node command prompt window by typing node( on windows machine) in start. Type following command to