pid
int64 2.28k
41.1M
| label
int64 0
1
| text
stringlengths 1
28.3k
|
---|---|---|
4,189,778 | 0 | <p>The CLR makes no guarantees with respect to the order that finalizers will be called. It sees a group of unrooted objects (e.g. not reachable from any GC root) and starts calling finalizers. It doesn't matter that you have connections within your object graph. The finalizers can be called in any order. Finalizers are intended to clean up unmanaged resources, not child objects. You need to re-think your API.</p> |
6,780,483 | 0 | <p>As a lot of people have suggested, Resource Leaks are fairly easy to cause - like the JDBC examples. Actual Memory leaks are a bit harder - especially if you aren't relying on broken bits of the JVM to do it for you...</p> <p>The ideas of creating objects that have a very large footprint and then not being able to access them aren't real memory leaks either. If nothing can access it then it will be garbage collected, and if something can access it then it's not a leak...</p> <p>One way that <em>used</em> to work though - and I don't know if it still does - is to have a three-deep circular chain. As in Object A has a reference to Object B, Object B has a reference to Object C and Object C has a reference to Object A. The GC was clever enough to know that a two deep chain - as in A <--> B - can safely be collected if A and B aren't accessible by anything else, but couldn't handle the three-way chain...</p> |
24,880,090 | 0 | How can I use @for in sass to assign background positions to multiple classes <p>Ok so here's my code:</p> <pre><code>.file-icon,.folder-icon{ $size:24px; position: absolute; top: 10px; left: 44px; display: block; float: left; width: $size; height: $size; margin-right: 10px; background: $driveIcon; &.folder-close{ background-position: 0 -72px; &.folder-open{ background-position: -$size -72px; } } &.archiveIcon{ background-position: -$size*2 -72px; } &.audioIcon{ background-position: -$size*3 -72px; } &.brokenIcon{ background-position: -$size*4 -72px; } &.docIcon{ background-position: -$size*5 -72px; } &.imgfile{ background-position: -$size*6 -72px; } &.pdfIcon{ background-position: -$size*7 -72px; } &.pptx{ background-position: -$size*8 -72px; } &.txtIcon{ background-position: -$size*9 -72px; } &.unknown{ background-position: -$size*10 -72px; } &.videoIcon{ background-position: -$size*11 -72px; } &.xlsIcon{ background-position: -$size*12 -72px; } &.viewer{ background-position: -$size*13 -72px; &.folder-open{ background-position: -$size*14 -72px; } } &.owner{ background-position: -$size*15 -72px; &.folder-open{ background-position: -$size*16 -72px; } } &.moderator{ background-position: -$size*17 -72px; &.folder-open{ background-position: -$size*18 -72px; } } } </code></pre> <p>What I want to do is automate this assigning of background positioning. I tried using @for for the actual statement but not able to figure out how to assign the results one by one to my custom second classes. Please help me out, i'm a beginner in sass. Thankyou.</p> <p>This is what I've done up till now:</p> <pre><code>@for $i from 0 to 18{ background-position: -($size*$i} -72px; } </code></pre> |
23,225,683 | 0 | PHP nested array in $_SESSION <p>I'm trying to do a simple nested array in a session variable. But I'm having a hard time wrapping my head around the logic for the dynamic creation of the arrays.</p> <p>What I think my code should look like (which I know is wrong, because I want it to be dynamic):</p> <p>Page 1:</p> <pre><code>session_start(); $_SESSION['test'] = array(); </code></pre> <p>Page 2: </p> <pre><code>session_start(); $_SESSION['test'][0] = array('name' => 'john smith', 'age' => '20', 'city' => 'new york'); $_SESSION['test'][1] = array('name' => 'jane doe', 'age' => '42', 'city' => 'seattle'); </code></pre> <p>I want to be able to do a foreach loop to grab the values</p> <pre><code>foreach($_SESSION['test'] as $test){ echo "Name " . $test['name']; echo "Age " . $test['age']; echo "City " . $test['city']; } </code></pre> |
40,567,470 | 1 | Split in python and strip whitespace <p>I am learning Python, and currently working on reading in a file, splitting the lines and then printing specific elements. I am having trouble splitting multiple times though. The file I am working on has many lines that look like this</p> <pre><code>c0_g1_i1|m.1 gi|74665200|sp|Q9HGP0.1|PVG4_SCHPO 100.00 372 0 0 1 372 1 372 0.0 754 </code></pre> <p>I am trying to split it, first by tab and newline "/t/n", and then split the elements with |, I have tried .split and .strip and am not having much luck. I figured maybe if I just worked on a single line I could get the idea down, and then modify it into a loop that would access the file</p> <pre><code>blast_out = ("c0_g1_i1|m.1 gi|74665200|sp|Q9HGP0.1|PVG4_SCHPO 100.00 372 0 0 1 372 1 372 0.0 754") fields = blast_out.strip(' \t\r\n').split() subFields = fields.split("|") print(fields) print(subFields) </code></pre> <p>print(fields)</p> <pre><code>['c0_g1_i1|m.1', 'gi|74665200|sp|Q9HGP0.1|PVG4_SCHPO', '100.00', '372', '0', '0', '1', '372', '1', '372', '0.0', '754'] </code></pre> <p>print(subFields) generates an error </p> <pre><code>subFields = fields.split('|') AttributeError: 'list' object has no attribute 'split' </code></pre> <p>This is what I did just to try to strip the whitespace and the tabs, then to split on | but it doesn't seem to do anything. Eventually my desired output from this single string would be </p> <pre><code>c0_g1_i1 m.1 Q9HGP0.1 100.0 </code></pre> |
9,288,021 | 0 | <p>I think you need to use the constant <code>JSON_HEX_QUOT</code></p> <p>this seems to work:</p> <pre><code>$options = array(JSON_HEX_QUOT); $json = Zend_JSON($value, $cyclecheck, $options); </code></pre> <p>I got deeper into the Zend/Json.php code and it looks like if you'd like to use JSON_HEX_QUOT you're going to have to use the PHP function as Zend_Json doesn't pass the constant.</p> <pre><code> // Encoding if (function_exists('json_encode') && self::$useBuiltinEncoderDecoder !== true) { $encodedResult = json_encode($valueToEncode); </code></pre> <p>I think this is because ZF is coded to the PHP 5.2.6 standard and $options was added to json_encode in PHP 5.3.0</p> <p>here is the reference from the php manual:</p> <blockquote> <p><strong>Example #2</strong> *A json_encode() example showing all the options in action*</p> <p><code><?php $a = array('<foo>',"'bar'",'"baz"','&blong&');</code></p> <p>echo "Normal: ", json_encode($a), "\n"; echo "Tags: ",<br> json_encode($a,JSON_HEX_TAG), "\n"; echo "Apos: ",<br> json_encode($a,JSON_HEX_APOS), "\n"; echo "Quot: ",<br> json_encode($a,JSON_HEX_QUOT), "\n"; echo "Amp: ",<br> json_encode($a,JSON_HEX_AMP), "\n"; echo "All: ",<br> json_encode($a,JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP), "\n\n";</p> <p>$b = array();</p> <p>echo "Empty array output as array: ", json_encode($b), "\n"; echo "Empty array output as object: ", json_encode($b, JSON_FORCE_OBJECT), "\n\n";</p> <p>$c = array(array(1,2,3));</p> <p>echo "Non-associative array output as array: ", json_encode($c), "\n"; echo "Non-associative array output as object: ", json_encode($c, JSON_FORCE_OBJECT), "\n\n";</p> <p>$d = array('foo' => 'bar', 'baz' => 'long');</p> <p>echo "Associative array always output as object: ", json_encode($d), "\n"; echo "Associative array always output as object: ", json_encode($d, JSON_FORCE_OBJECT), "\n\n";</p> </blockquote> |
14,954,554 | 0 | <p>Probably reason of those twitches is endless loop. When your <code>p:selectCheckboxMenu</code> is shown remote command is called, and <code>p:selectCheckboxMenu</code> is updated and it is shown again and remote command is called again... And this never ends. It is strange that you are updating component in <code>onShow</code>. You probably should do this in moment when conditions for updating are changed, this is not place where you should update component. If this <code>p:selectCheckboxMenu</code> is for example dependent on some <code>p:selectOneMenu</code> update it when value of <code>p:selectOneMenu</code> is changed.</p> |
2,220,308 | 0 | <p>Try slipping something like this into your jquery:</p> <pre><code>$("#fancy_outer").css({"float":"right","position":"static"}); </code></pre> |
37,566,814 | 0 | <p>Without a <a href="http://stackoverflow.com/help/mcve">Minimal, Complete, and Verifiable example</a> nobody can really help you. Nevertheless, this sticks out in a major way:</p> <pre><code>if(prev->next=NULL) { prev->next=temp; } </code></pre> <p>You assign <code>NULL</code> to <code>prev->next</code> instead of comparing it with <code>==</code>.</p> |
12,569,923 | 0 | <p>You may try this</p> <pre><code>var map, locations = [ [43.82846160000000000000, -79.53560419999997000000], [43.65162010000000000000, -79.73558579999997000000], [43.75846240000000000000, -79.22252100000003000000], [43.71773540000000000000, -79.74897190000002000000] ]; var myOptions = { zoom: 6, center: new google.maps.LatLng(locations[0][0], locations[0][1]), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map($('#map')[0], myOptions); var infowindow = new google.maps.InfoWindow(), marker, i; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][0], locations[i][1]), map: map }); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent('Current location is: '+ locations[i][0]+', '+locations[i][1]); infowindow.open(map, marker); } })(marker, i)); } </code></pre> <p><a href="http://jsfiddle.net/X5r8r/652/" rel="nofollow"><strong>DEMO</strong></a>.</p> |
17,264,742 | 0 | <ol> <li>xmlDoc is not defined somewhere</li> <li>you open the XMLHttpRequest, but you <strong>did not send it</strong></li> </ol> |
8,793,452 | 0 | MEF, IOC or Prism? Best approach to develop Silverlight client to RIA Services <p>I need to get correct decision for the long-term project about what to choose: MEF, IOC or Prism.</p> <p>Which is the best approach to develop Silverlight website (RIA Services).</p> <p>Basically it has complex UI.</p> <p>Thank you for any clue!</p> |
33,475,404 | 0 | At Which Position MD5-PADDING starts? <p>I'm trying to implement MD5 File-Hash in and I think it will be finished in the near future. Currently I need to append the PADDING but i don't understand how this works.</p> <p>Example: I have a file with 109 Bytes of data.</p> <pre><code>// 512 Bit 360 Bit // ------------- ------------- // |xxxxxxxxxxx| |xxxxxx | // ------------- ------------- </code></pre> <p>When appending the PADDING to the data, does it have to look like this:</p> <pre><code>// 512 Bit 360 Bit 512 Bit // ------------- ------------- ------------- // |xxxxxxxxxxx| |xxxxxx|1|00| |00000000|64| // ------------- ------------- ------------- </code></pre> <p>or this</p> <pre><code>// 512 Bit 512 Bit // ------------- ------------- // |xxxxxxxxxxx| |xxx|1|00|64| // ------------- ------------- </code></pre> <p>or this?</p> <pre><code>// 512 Bit 360 Bit 512 Bit // ------------- ------------- ------------- // |xxxxxxxxxxx| |xxxxxx | |10000000|64| // ------------- ------------- ------------- </code></pre> <p>I'm confused. After Consulting the RFC1321 Text I think to use the Padding in the SAME Block if it is possible to pad inside a block. And if this doesn't fit then use a new block. </p> <p>Am I right?</p> <p>EDIT: Need more detail.</p> <p>Where will the padding be appended? after the last data bit or the last data byte? or is this the same?</p> <p>Like this?</p> <pre><code> 512 Bit-Block -------------------------------------------------- |1|1|0|X0000000| |0|0|0|0|0|0|0|1| |0|0|0|00000000| |0|0|0|0|0|0|0|0| |0|0|4|00000000| |0|0|0|0|0|0|0|1| |0|0|6|00000000| ... |0|0|0|0|0|0|0|1| |1|1|8|00000000| |0|0|0|0|0|0|0|1| |1|1|0|00000000| |0|0|0|0|0|0|0|1| |0|1|0|00000000| |0|0|0|0|0|0|0|1| |1|1|0|00000000| |0|0|0|0|0|0|0|0| -------------------------------------------------- |DATA |PADDING | 64 Bit counter| </code></pre> <p>or like this?</p> <pre><code> 512 Bit-Block -------------------------------------------------- |1|1|0|00000000| |0|0|0|0|0|0|0|1| |0|0|0|00000000| |0|0|0|0|0|0|0|0| |0|0|4|00000000| |0|0|0|0|0|0|0|1| |0|0|6|00000000| ... |0|0|0|0|0|0|0|1| |1|1|8|00000000| |0|0|0|0|0|0|0|1| |1|1|X|00000000| |0|0|0|0|0|0|0|1| |0|1|0|00000000| |0|0|0|0|0|0|0|1| |1|1|0|00000000| |0|0|0|0|0|0|0|0| -------------------------------------------------- |DATA |PADDING | 64 Bit counter| </code></pre> |
7,606,244 | 0 | How should my Rails before_validation callbacks handle bad data? <p>I have several before_validation callbacks that operate on the attributes being set on my model. I run into trouble when I have a situation like this:</p> <pre><code>class Foo < ActiveRecord::Base before_validation :capitalize_title validates :title, :presence => true def capitalize_title title.upcase end end </code></pre> <p>I write a test to ensure that 'nil' title is not allowed, but the test gets an error because the nil.upcase is not defined. I'd like to handle this error, but I already have error handling that runs after before_validation callbacks.</p> <p>I don't want to put checks around all of my before_validation callbacks to make sure the data exists, if I can avoid it.</p> <p>Is there a clean or accepted way to deal with this type of situation?</p> |
35,083,769 | 1 | How to use nltk sentence tokenizer in case of bulleted-data or listed data? <p>I am using nltk sentence tokenizer to fetch sentences of files.<br> But it fails terribly when there are bullets/listed data.</p> <p><a href="http://pastebin.com/6YA1JNzb" rel="nofollow">Example text</a></p> <p>Code I am using is: </p> <pre><code>dataFile = open(inputFile, 'r') fileContent = dataFile.read() fileContent = re.sub("\n+", " ", fileContent) sentences = nltk.sent_tokenize(fileContent) print(sentences) </code></pre> <p>I want the sentence tokenizer to give each bullet as a sentence.</p> <p>Can someone please help me here? Thanks! </p> <p><strong>Edit1</strong>:<br> Raw ppt sample: <a href="http://pastebin.com/dbwKCESg" rel="nofollow">http://pastebin.com/dbwKCESg</a><br> Processed ppt data: <a href="http://pastebin.com/0N64krKC" rel="nofollow">http://pastebin.com/0N64krKC</a></p> <p>I will recieve only the processed data file and need to sentence tokenize on the same.</p> |
8,203,330 | 0 | <p>First off, "compiler" does <strong>not</strong> imply "outputs machine code". You can compile from any language to any other, be it a high-level programming language, some intermediate format, code for a virtual machine (bytecode) or code for a physical machine (machine code).</p> <ol> <li><p>Like a compiler, an interpreter needs to read and understand the language it implements. Thus you have the same front-end code (though today's interpreters usually implement far simpler language - the bytecode only; therefore these interpreters only need a very simple frontend). Unlike a compiler, an interpreter's backend doesn't generate code, but executes it. Obviously, this is a different problem entirely and hence an interpreter looks quite difference from a compiler. It emulates a computer (often one that's far more high-level than real life machines) instead of producing a representation of an equivalent program.</p></li> <li><p>Assuming today's somewhat-high-level virtual machines, this is the job of the interpreter - there are dedicated instructions for, among other things, calling functions and creating objects, and garbage collection is baked into the VM. When you target lower-level machines (such as the x86 instruction set), many such details need to be baked into the generated code, be it directly (system calls or whatever) or via calling into the C standard library implementation.</p></li> </ol> <p>3.</p> <ul> <li><p>a) Probably not, as a VM dedicated to Python won't require it. It would be very easy to screw up, unnecessary and arguably incompatible to Python semantics as it allows manual memory management. On the other hand, if you were to target something low-level like LLVM, you'd have to take special care - the details depend on the target language. That's part of why nobody does it.</p></li> <li><p>b) It would be a perfectly fine compiler, and obviously not an interpreter. You'd probably have a simpler backend than a compiler targeting machine code, and due to the nature of the input language you wouldn't have quite as much analysis and optimization to do, but there's no fundamental difference.</p></li> </ul> |
12,256,418 | 0 | radio is not SELECTED, how to set "selected"? <p>One of my radio should selected when initialize (first load then user can change the selection), but radio is not selected first time, how to initialize "Selected" appropriately?</p> <p><strong>Here radio "Two" should selected as "selected" is True for this?</strong></p> <pre><code>@using (Html.BeginForm("Index", "Two", FormMethod.Post, new Dictionary<string, object> { { "data-bind", "submit:onSubmit" } })) { <table> <tr> <td> <div data-bind="foreach: items"> <input type="radio" name="items" data-bind="attr: { value: id }, checked: $root.selected" /> <span data-bind="text: name"></span> </div> <div data-bind="text: selected"> </div> </td> </tr> </table> <input type="submit" name="send" value="Send" /> } <script type="text/javascript"> var viewModel = { items: [ { "id": 1, "name": "one", "selected": false }, { "id": 2, "name": "two", "selected": true }, { "id": 3, "name": "three", "selected": false } ], selected: ko.observable(), onSubmit: function(){ var x = this.selected(); } }; $(function() { ko.applyBindings(viewModel); }); </script> </code></pre> |
26,455,109 | 0 | <p>Thank you for giving you time to answer me Alex D with some information :) It was to long to comment to your answer.</p> <ol> <li><p>I´m understanding most of those instruction does. I know now that cmp is the big part that I have to watch for.</p></li> <li><p>I think I know some about call stack.</p></li> <li><p>I should know how if else and for in C are translated into assembly.</p></li> <li><p>I´ve been watching in gdb using stepping how it goes through the loops (jumps) and have got to 5 jumps now and stop at the 6th one so I think I´m getting closer.</p></li> <li><p>Think it´s EAX if I´m watching gdb, it´s getting higher with stepping.</p></li> <li><p>Don´t think I could tell that.</p></li> </ol> <p>Thank you again for giving time to comment back, think it will be much easier when the lights turn on in my head :)</p> |
35,631,239 | 0 | <p>Try put $("#tabs").tabs(); first</p> |
39,513,539 | 0 | <p>What about </p> <pre><code>for( $i = 0; $i < 3; $i++) { echo $i."<br>"; } </code></pre> <p>or</p> <pre><code>for( $i = 0; $i <= 10; $i++) { echo $i."<br>"; if ($i == 2) break; } </code></pre> <p>?</p> |
22,768,050 | 0 | <p>There is no predefined function of that kind in Armadillo.</p> <p>Here is a quick self-made version, that however will not benefit from any delayed expression evaluation template features of Armadillo:</p> <pre class="lang-cpp prettyprint-override"><code>#include <cassert> #include <cmath> #include <armadillo> #include <iostream> template<class Object> Object elementwise_pow(const Object& base, const Object& p) { assert(base.n_elem == p.n_elem); Object result; result.copy_size(base); for (std::size_t i = 0; i < result.n_elem; ++i) { result[i] = std::pow(base[i], p[i]); } return result; } int main() { arma::mat m(3,3); m.fill(2.); arma::mat p(3,3); p << 1 << 2 << 3 << arma::endr << 4 << 5 << 6 << arma::endr << 7 << 8 << 9 << arma::endr; arma::mat r = elementwise_pow(m, p); r.print(std::cout); return 0; } </code></pre> <p>An optimizing compiler should also easily <strong>vectorize</strong> this code.</p> |
30,324,222 | 0 | <p>actually the solution is to use custom listviews</p> <p><a href="http://javatechig.com/xamarin/listview-example-in-xamarin-android" rel="nofollow">http://javatechig.com/xamarin/listview-example-in-xamarin-android</a></p> |
14,707,533 | 0 | jquery get specific html for inner class? <pre><code>var myhtml= '<td class="dataCell"><table border="0" bordercolor="#FFFFFF" cellpadding="0" cellspacing="0" width="100%"><tbody><tr bgcolor="#FFFFFF"><td><div align="right">1.</div></td><td>Kabul Edildi - İZMİR(ÇAMDİBİ/ÇAMDİBİ)</td><td><div>04/02/2013 16:06:16</div></td></tr><tr><td><div align="right">2.</div></td><td>Torbaya Eklendi - İZMİR(ÇAMDİBİ/ÇAMDİBİ)</td><td><div>04/02/2013 16:09:33</div></td></tr><tr bgcolor="#FFFFFF"><td><div align="right">3.</div></td><td>Gönderinin Geliş Kaydı Yapıldı - İZMİR(İZMİR K.İ.M/MERKEZ)</td><td><div>04/02/2013 18:01:35</div></td></tr><tr><td><div align="right">4.</div></td><td>Torbaya Eklendi - İZMİR(İZMİR K.İ.M/MERKEZ)</td><td><div>04/02/2013 18:52:15</div></td></tr><tr bgcolor="#FFFFFF"><td><div align="right">5.</div></td><td>Gönderinin Geliş Kaydı Yapıldı - AYDIN(AYDIN POS.DAG.VE TOP/AYDIN POS.DAG.VE TOP)</td><td><div>05/02/2013 02:22:20</div></td></tr><tr><td><div align="right">6.</div></td><td>Torbaya Eklendi - AYDIN(AYDIN POS.DAG.VE TOP/AYDIN POS.DAG.VE TOP)</td><td><div>05/02/2013 02:35:34</div></td></tr><tr bgcolor="#FFFFFF"><td><div align="right">7.</div></td><td>Gönderinin Geliş Kaydı Yapıldı - AYDIN(SÖKE/SÖKE)</td><td><div>05/02/2013 09:27:41</div></td></tr></tbody></table></td>'; $('#siptakip_1360003997').html($('.dataCell', myhtml)); // ->not work.... $('#siptakip_1360003997').html(jQuery(myhtml).find('.dataCell').html()); // ->not work.... </code></pre> <p>Why is my Jquery code not working? How can I fix it?</p> |
4,548,127 | 0 | <p>If you prefer/are stuck with bash, perhaps you are looking for <a href="http://linux.die.net/man/1/expect" rel="nofollow">expect</a>?</p> <p>More on that here: <a href="http://wiki.tcl.tk/11583" rel="nofollow">http://wiki.tcl.tk/11583</a></p> |
25,940,643 | 0 | Missing array data in C <p>I have a code which creates an array of 1000 random entries and a routine which bins them in to a histogram. When I look at the results of the histogram I see that there are a lot more 0s than there should be. I can debug the code and I find that while my original array seems correct, after I pass the array to the next routine the last few entries are now 0. Furthermore, if I run a few more lines in the same routine, even more of the entries turn to 0. Does anyone have an idea as to what might be causing this? </p> <p>Here is the code for reference:</p> <pre><code>int n = 1000; int m = 100; double r; double *p;//line 22 p = generate_random( n ); //returns array of length n containing random numbers between 0 and 1 r = group(p, m, n); ... double group(double* rnd, int m, int n) { int count[100] = { 0 }; int length = n; int i, bin;//line 66 double dx = 1/(double) m;//length of each interval for (i = 0; i < length; i++) { bin = (int) floor(*(rnd+i)/dx);//line 71 count[bin]++;//count[0] should be the number of random elements between 0 and 0.1 } ...//some more code that sets return double </code></pre> <p>When I enter the debugger at line 22 after creating p, I can see that p contains 1000 random numbers:</p> <pre><code>print *p = 0.78846 print *(p+851) = 0.3475 print *(p+999) = 0.9325 </code></pre> <p>At line 66 it contains less:</p> <pre><code>print *rnd = 0.78846 print *(rnd+851) = 0.3475 print *(rnd+999) = 0 </code></pre> <p>And at line 71 (i = 0) even less:</p> <pre><code>print *rnd = 0.78846 print *(rnd+851) = 6.9533e-310 print *(rnd+999) = 0 </code></pre> <p>Edit: Here is the code for generate_random:</p> <pre><code>double * generate_random( int n ) { const unsigned int a = 1664525; const unsigned int b = 1013904223; const unsigned int M = pow(2,32); int i; double random_numbers[n]; unsigned int rnd = time(NULL)%M; //number of seconds since 00:00 hours, // Jan 1, 1970 UTC for (i = 0; i < n; i++) { rnd = (a*rnd + b)%M; random_numbers[i] = (double) rnd; //map to [0,1] random_numbers[i] = random_numbers[i]/M; } return random_numbers; } </code></pre> |
24,815,219 | 0 | <p>Ok, to answer your question the way you want it because you're being difficult. If you want a different answer, I highly suggest that you actually ask the question you want answered.</p> <p>I am compiling this code, first with only region 1 and then second with only region 2:</p> <pre><code>int var_a = 0; //... //Some code that fetches var_a from db if db field is not null //... // region 1 if(var_a != null && var_a > 0) var_a = -1; //region 2 if(var_a != null){ if (var_a > 0) var_a = -1; } </code></pre> <p>If I extract the IL code for region 1, I get this:</p> <pre><code>IL_0015: nop IL_0016: ldc.i4.0 IL_0017: stloc.0 IL_0018: ldloc.0 IL_0019: ldc.i4.0 IL_001a: cgt IL_001c: ldc.i4.0 IL_001d: ceq IL_001f: stloc.1 IL_0020: ldloc.1 IL_0021: brtrue.s IL_0025 IL_0023: ldc.i4.m1 IL_0024: stloc.0 IL_0025: ldloc.0 </code></pre> <p>And for region 2, I get this:</p> <pre><code>IL_0015: nop IL_0016: ldc.i4.0 IL_0017: stloc.0 IL_0018: ldc.i4.1 IL_0019: ldc.i4.0 IL_001a: ceq IL_001c: stloc.1 IL_001d: nop IL_001e: ldloc.0 IL_001f: ldc.i4.0 IL_0020: cgt IL_0022: ldc.i4.0 IL_0023: ceq IL_0025: stloc.1 IL_0026: ldloc.1 IL_0027: brtrue.s IL_002b IL_0029: ldc.i4.m1 IL_002a: stloc.0 IL_002b: nop IL_002c: ldloc.0 </code></pre> <p>So, yes, there is a slightly difference. JetBrains DotPeek shows a difference.</p> <p>Region 1:</p> <pre><code>if (num > 0) num = -1; </code></pre> <p>Region 2:</p> <pre><code>int num = 0; bool flag = 1 == 0; if (num > 0) num = -1; </code></pre> <p>Whereas JustDecompile cleans things up a bit and shows the same IL->C# conversion for both:</p> <pre><code>if (var_a > 0) { var_a = -1; } </code></pre> <p>Since you care so much about efficiency, I've written a quick bit of code to try and benchmark the difference:</p> <pre><code>Random rn = new Random(); List<int> l = new List<int>(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); for (int j = 1; j <= 20; ++j) { l.Clear(); sw.Start(); if (j % 2 == 0) { Console.Write("A: "); for (int i = 0; i < 100000000; ++i) { int var_a = rn.Next(1, 10000) * (rn.NextDouble() <= 0.5 ? -1 : 1); if (var_a != null) if (var_a > 0) var_a *= -1; l.Add(var_a); } } else { Console.Write("B: "); for (int i = 0; i < 100000000; ++i) { int var_a = rn.Next(1, 10000) * (rn.NextDouble() <= 0.5 ? -1 : 1); if (var_a != null && var_a > 0) var_a *= -1; l.Add(var_a); } } sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds); sw.Reset(); } </code></pre> <p>Values for A:</p> <pre><code>2918.6503 2910.8609 2916.2404 2909.5394 2914.0309 2961.0775 2948.4139 2957.1939 2962.1737 </code></pre> <p>Values for B:</p> <pre><code>3170.8064 2891.6971 2924.8533 2890.6248 2885.1991 2890.6321 2887.0145 2935.6778 2909.035 </code></pre> <p>The average for the entire 100,000,000 execution cycle for A vs B is <code>2933 ms</code> vs <code>2932 ms</code> respectively.</p> <p>Per execution of the internal block, that's <code>2.9331 * 10^-5</code> vs <code>2.9317 * 10^-5</code>.</p> <p>Now we've got down to this, I have to ask why you would be writing a program in as high a level language as C# when you care about something that makes <code>0.000000014045333333 ms</code> difference between one way and the other. Perhaps you should try something more low level like Assembly? All in all, this discrepancy could still come down to activity of the CPU during that operation doing other things for Windows.</p> <p>I hope this answer goes into the depth you've come to expect from StackOverflow.</p> |
36,473,394 | 0 | <p>It's not necessary to give each div it's own class or ID.</p> <p>You could give them all the same class and use the jQuery eq: filter to choose the correct div.</p> <p>Example code:</p> <pre><code>$(".custom button").click(function(){ var nextDiv = $(this).attr('data-id'); // Usually a +1 for the next div, but since eq filter is zero based, it works in this case. $('.custom').hide(); $('.custom:eq(' + nextDiv + ')').show(); }); </code></pre> <p>Working example: <a href="https://jsfiddle.net/ore5h6tk/" rel="nofollow">https://jsfiddle.net/ore5h6tk/</a></p> <p>Another example, hiding all but the first with CSS: <a href="https://jsfiddle.net/ore5h6tk/1/" rel="nofollow">https://jsfiddle.net/ore5h6tk/1/</a></p> <p>Hope this helps.</p> |
8,724,719 | 0 | Group Multiple Tables in LINQ <p>I have a very simple SQL query </p> <pre><code>Select r.SpaceID,Count(*), SpaceCode from Rider r join Spaces s on r.SpaceID=s.SpaceID Group By r.SpaceID, s.SpaceCode </code></pre> <p>Please note that my group by clause is on multiple tables, i want to do the same in linq, i know how to group single table, but about multiple tables i have no idea.</p> |
689,424 | 0 | <p>The only way I can think of is to use <strong>Eclipse File Search dialog</strong> for all <em>.java</em> files and use this regular expression as input:</p> <pre><code>"(?s:/\*\*([^\*]|\*[^/])*?###INPUT###.*?\*/)" </code></pre> <p>and replace the ###INPUT### with what you are searching for.</p> <p>See this <a href="http://stackoverflow.com/questions/689354/regex-for-matching-javadoc-fragments">other question</a> about this regex.</p> |
19,730,151 | 0 | Unable to retrieve videos from youtube with youtube-api <p>I'm developing a GWT application witch reads and displays videos from youtube. With that purpose in mind I started using gwt-youtube-api.</p> <p>I can display a player and play the video from youtube accordingly but I'm unable to search videos on youtube.</p> <p>The following code should retrieve the most recent videos from youtube, but it doesn't do anything. After making RPC call I can't see any results for both onSucess and onFailure:</p> <pre><code>import java.util.List; import com.google.gdata.client.youtube.YouTubeManager; import com.google.gdata.data.youtube.VideoEntry; import com.google.gdata.data.youtube.VideoFeed; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.rpc.AsyncCallback; public class Webmetalmore implements EntryPoint { @Override public void onModuleLoad() { YouTubeManager youTubeManager = new YouTubeManager(); youTubeManager.retrieveMostRecent(new AsyncCallback<VideoFeed>() { @Override public void onSuccess(VideoFeed result) { List<VideoEntry> entries = result.getEntries(); for (VideoEntry entry: entries){ System.out.println(entry.getTitle()); } } @Override public void onFailure(Throwable caught) { GWT.log("Unable to obtain videos from youtube service", caught); } }); } } </code></pre> <p>Any ideas of what I'm doing wrong? Thank you</p> |
9,405,278 | 0 | How to save state when extending UIComponentBase <p>I'm creating a composite component that will wrap a datatable to implement very simple paging. I need to save state (the current page number) between ajax requests.</p> <p>I tried creating fields in my FacesComponent, but I discovered they are wiped out during the JSF lifecycle:</p> <pre><code>@FacesComponent(value = "bfTableComponent") public class BFTableComponent extends UIComponentBase implements NamingContainer { private int currentPageNumber; ... </code></pre> <p>I can't seems to find a concise guide to doing this anywhere! How would one save state between requests when creating a composite component?</p> |
7,204,651 | 0 | <p>There are two approaches:</p> <p>1. Encapsulated timeout</p> <p>The thread reading the data from network or serial port can measure time elapsed from its time of start and wait for the data for no more than the remaining time. Network communication APIs usually provide means to specify a timeout for the operation. Hence by doing simple DateTime arithmetic you can encapsulate timeout management within your worker thread.</p> <p>2. External timeout</p> <p>Use another thread (or do it in the main thread if that's feasible) to wait for the worker thread to finish within a certain time limit, and if not, abort it. Like this:</p> <pre><code>// start the worker thread ... // give it no more than 5 seconds to execute if (!workerThread.Join(new TimeSpan(0, 0, 5))) { workerThread.Abort(); } </code></pre> |
20,849,388 | 0 | <p>You can use <code>rev(dd)</code>; <code>rev.dendrogram</code> simply returns the dendrogram with reversed nodes:</p> <pre><code>hc <- hclust(dist(USArrests), "ave") dd <- as.dendrogram(hc) plot(dd) </code></pre> <p><img src="https://i.stack.imgur.com/3GN1Q.png" alt="dendrogram"></p> <pre><code>plot(rev(dd)) </code></pre> <p><img src="https://i.stack.imgur.com/6LNto.png" alt="reversed dendrogram"></p> |
20,675,352 | 0 | <p>An efficient way to print nth line from a file (<strong>especially suited for large files</strong>):</p> <pre><code>sed '2q;d' file </code></pre> <p>This sed command quits just after printing 2nd line rather than reading file till the end.</p> <p>To store this in a variable:</p> <pre><code>line=$(sed '2q;d' file) </code></pre> <p>OR using a variable for line #:</p> <pre><code>n=2 line=$(sed $n'q;d' file) </code></pre> <p><strong>UPDATE:</strong> </p> <p><strong>Java Code:</strong></p> <pre><code>try { ProcessBuilder pb = new ProcessBuilder("/bin/bash", "/full/path/of/myScript.sh" ); Process pr = pb.start(); InputStreamReader isr = new InputStreamReader(pr.getInputStream()); BufferedReader br = new BufferedReader(isr); String line; while((line = br.readLine()) != null) System.out.println(line); int exitVal = pr.waitFor(); System.out.println("exitVal: " + exitVal); } catch(Exception e) { e.printStackTrace(); } </code></pre> <p><strong>Shell script:</strong></p> <pre><code>f=$(dirname $0)/edit.txt read -r i < "$f" echo "session is: $i" echo -n "file path is: " sed '2q;d' "$f" </code></pre> |
15,088,988 | 1 | jython lambda function <p>May I know why the following code does not print out <code>[1,2,3,1,2,3]</code>. Instead, it throws an exception. Could you show me how to make it work.</p> <pre><code>x = [1,2,3] print apply(lambda x: x * 2, (x)) </code></pre> <p>if I try the following, it works:</p> <pre><code>test1 = lambda x: x * 2 print test1(x) </code></pre> |
9,501,164 | 0 | <p>I use the second one with slight modification,</p> <pre><code>UIImageView *shadowView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 150, 800, 600)]; shadowView.image = [UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:extension] ]; </code></pre> <p>because imageNamed: caches image and cause memory leak.</p> |
29,322,199 | 0 | <p>I think there is no chance. You need to add them one by one. <code>frame.add(...); frame.add(...);</code><br> I don't clearly understand what you want as result, but using <code>GridLayout(3, 3)</code> with only 2 panels is the same as use <code>GridLayout(0, 2)</code>.<br> P.S. Check out GridBagLayout - it can be more useful for you.</p> |
2,977,468 | 0 | <p>Avoid <a href="http://en.wikipedia.org/wiki/Eclipse_%28software%29" rel="nofollow noreferrer">Eclipse</a> for C/C++ development for now on <a href="http://en.wikipedia.org/wiki/Mac_OS_X_Snow_Leopard" rel="nofollow noreferrer">Mac OS X v10.6</a> (Snow Leopard). There are serious problems which make debugging problematic or nearly impossible on it currently due to <a href="http://en.wikipedia.org/wiki/GNU_Debugger" rel="nofollow noreferrer">GDB</a> incompatibility problems and the like. See: <em><a href="http://stackoverflow.com/questions/1270285/trouble-debugging-c-using-eclipse-galileo-on-mac">Trouble debugging C++ using Eclipse Galileo on Mac</a></em>.</p> |
23,433,032 | 0 | How to Parse XML Data <p>I am having an XML,which is like</p> <pre><code><polygon> <coordinates> <coordinate order="1" long="75.9375" lat="32.91648534731439"/> <coordinate order="2" long="76.640625" lat="23.241346102386135"/> <coordinate order="3" long="88.59375" lat="31.052933985705163"/> </coordinates> </polygon> </code></pre> <p>I want to get the long and lat values of every coordinates and assign to string. I was trying like :</p> <pre><code>DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document document = db.parse( new InputSource(new StringReader(s))); System.out.println(document.getChildNodes()); NodeList nl = document.getElementsByTagName("coordinates"); for (int i = 0; i < nl.getLength(); i++) { System.out.println("name is : "+nl.item(i).getNodeName()); System.out.println("name is : "+nl.item(i).getNodeValue()); } </code></pre> <p>The String reader is the XML String I pass,but I am not able to get the data.</p> |
38,501,236 | 0 | <p>You have to complete the statement with the semicolon (<code>;</code>) at the end</p> <pre><code>List<string> icons = new List<string>() { "!","!","N","N",",",",","k","k", "b","b","v","v","w","w","z","z" }; </code></pre> |
22,357,252 | 0 | <p>A widget is usually a small application with limited functionality. It usually, not always, will have one specific purpose. An app is much broader and is short for application which can encompass any number of things.</p> |
24,376,379 | 0 | <p>I'm not sure about your approach or why there are performance issues but here is my solution to similar issue.</p> <p>The full solution can be found <a href="https://github.com/steinborge/ProxyTypeHelper/wiki" rel="nofollow">https://github.com/steinborge/ProxyTypeHelper/wiki</a></p> <p>What I wanted to achieve was the ability to create a 'generic' view model which can then be assigned to a datatemplate. The data template is just a user control. In the case where you have a lot of simple data maintenance screens would save a lot of repetitive code. </p> <p>But had a couple of issues. Datatemplates don't work well with in XAML with generics and if you have a lot of data templates you are creating a lot of XAML - especially if you wanted to use it in separate views. In your case you mention up to 90 views - this would be a lot of XAML.</p> <p>Solution is to store the templates in a lookup and use a content control and DataTemplateSelector populate depending upon the DataContext. So first need to register the data template/views:</p> <pre><code> manager.RegisterDataTemplate(typeof(GenericViewModel<CarType, WPFEventInter.ViewModel.CarTypeViewModel>), typeof(WPFEventInter.UserControls.CarTypesView)); manager.RegisterDataTemplate(typeof(GenericViewModel<Colour, WPFEventInter.ViewModel.ColourViewModel>), typeof(WPFEventInter.UserControls.ColourView)); </code></pre> <p>RegisterDataTemplate just adds the datatemplate to a dictionary:</p> <pre><code> public void RegisterDataTemplate(Type viewModelType, Type dataTemplateType, string Tag="") { var template = BuildDataTemplate(viewModelType, dataTemplateType) ; templates.Add(viewModelType.ToString() + Tag, template); } private DataTemplate BuildDataTemplate(Type viewModelType, Type viewType) { var template = new DataTemplate() { DataType = viewModelType, VisualTree = new FrameworkElementFactory(viewType) }; return template; } </code></pre> <p>Now create a view with a ContentPresenter control .This will display the view depending upon the view's Datacontext. </p> <p>The DataTemplateSelector looks like the following. This returns the appropriate view depending upon the datacontext:</p> <pre><code>public class ContentControlGenericTemplateSelector : DataTemplateSelector { public override DataTemplate SelectTemplate(object item, DependencyObject container) { DataTemplate retVal = null; try { retVal = Core.WPF.Infrastructure.DataTemplateManager.templates[item.GetType().ToString()]; } catch //empty catch to prevent design time errors.. { } return retVal; } </code></pre> |
38,230,493 | 0 | <p>If there is a field that can be used which can indicate which table that file's data is intended for, you can do something like this using multiple <code>INFILE</code> satements. Let's say the first field is that indicator and it will not be loaded (define it as a FILLER so sqlldr will ignore it):</p> <pre><code>... INTO TABLE table1 WHEN (01) = 'TBL1' fields terminated by ',' optionally enclosed by '"' TRAILING NULLCOLS ( rec_skip filler POSITION(1), Col1 "TRIM(:Col1)", Col2 "TRIM(:Col2)" ) INTO TABLE table2 WHEN (01) = 'TBL2' fields terminated by ',' optionally enclosed by '"' TRAILING NULLCOLS ( rec_skip filler POSITION(1), Colx "TRIM(:Colx)", Coly "TRIM(:Coly)" ) INTO TABLE table3 WHEN (01) = 'TBL3' fields terminated by ',' optionally enclosed by '"' TRAILING NULLCOLS ( rec_skip filler POSITION(1), Colp "TRIM(:Colp)", Colq "TRIM(:Colq)" ) </code></pre> <p>So logically, each INTO table WHEN section handles each file. Not that flexible though and arguably harder to maintain. For ease of maintenance you may just want to have a control file for each file? If all files and tables are the same layout you could also load them all into the same staging table (with the indicator) for ease of loading, then split them out programatically into the separate tables afterwards. Pros of that method are faster and easier loading and more control over the splitting into the separate table part of the process. Just some other ideas. I have done each method, depends on the requirements and what you are able to change.</p> |
15,489,326 | 0 | <p>It makes no sense to read the entire file all at once and then convert from text to binary data; it's more convenient to write, but you run out of memory faster. I would read the text in chunks and convert as you go. The converted data, in binary format instead of text, will likely take up less space than the original source text anyway.</p> |
37,095,495 | 0 | <p>For clarifying your situation, you can run the command in your mysql console. If succeeds, then you can try it in your code.</p> <p>First try,</p> <pre><code>LOAD DATA LOCAL INFILE '/tmp/foo.txt' INTO TABLE tmp; </code></pre> <p>Second try,</p> <pre><code>LOAD DATA LOCAL INFILE '/tmp/foo.txt' INTO TABLE tmp COLUMNS TERMINATED BY '\t'; </code></pre> <p>Third try,</p> <pre><code>LOAD DATA LOCAL INFILE '/tmp/foo.txt' INTO TABLE tmp FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'; </code></pre> <p>Forth try,</p> <pre><code>LOAD DATA LOCAL INFILE '/tmp/mydata.txt' INTO TABLE tmp COLUMNS TERMINATED BY '\t' ## This should be your delimiter OPTIONALLY ENCLOSED BY '"'; ## ...and if text is enclosed, specify here </code></pre> <p>From those, which runs perfectly, you can implement your code.</p> <p>For more, You can go through <a href="http://dev.mysql.com/doc/refman/5.7/en/loading-tables.html" rel="nofollow">MySQL manual</a></p> <h2>Resource Link:</h2> <p><a href="https://dev.mysql.com/doc/refman/5.6/en/load-data.html" rel="nofollow">LOAD DATA INFILE Syntax</a></p> |
1,554,352 | 0 | <p>Try this:</p> <pre><code>$("div").filter(function() { return $(this).children("p.special").length == 0; }) </code></pre> |
31,876,646 | 0 | <p>The code is going into loop because tabellaMenu table in the cell has the delegate and datasource set to self. So, it keeps on calling table datasource methods on self and create new cells and enters into loop. </p> <p>You can either create a separate object(subclass of NSObject) and define the table delegate and datasource methods in that and set it to tabellaMenu's delegate and datasource.</p> <p>Or you can create a subclass of UITableViewCell and create a table view in that programatically. Define the table's datasource and delegate methods in that. So every table view in the cell will refer to its own cell for datasource and delegate. In addition, you get -(void)prepareForReuse(if the cell is reusable) to reload the table in the cell everytime the main table reloads.</p> |
4,238,212 | 0 | <p>This is a bug in <code>mimetypes</code>, triggered by bad data in the registry. (<code>рєфшю/AMR</code> is not at all a valid MIME media type.)</p> <p><code>ctype</code> is a registry key name returned by <code>_winreg.EnumKey</code>, which <code>mimetypes</code> is expecting to be a Unicode string, but it isn't. Unlike <code>_winreg.QueryValueEx</code>, <code>EnumKey</code> returns a byte string (direct from the ANSI version of the Windows API; <code>_winreg</code> in Python 2 doesn't use the Unicode interfaces even though it returns Unicode strings, so it'll never read non-ANSI characters correctly).</p> <p>So the attempt to <code>.encode</code> it fails with a Unicode<strong>Decode</strong>Error trying to get a Unicode string before encoding it back to ASCII!</p> <pre><code>try: ctype = ctype.encode(default_encoding) # omit in 3.x! except UnicodeEncodeError: pass </code></pre> <p>These lines in <code>mimetypes</code> should simply be removed.</p> <p>ETA: <a href="http://bugs.python.org/issue10490">added to bug tracker</a>.</p> |
21,805,276 | 0 | How to set specfic time in countdown timer using Jquery <p>I am using a jQuery plugin <code>flipoclock.js</code> to put the countdown timer in my webpage.Currently the code works fine for current time,Now i want to customize into my specific time for example i am developing an online quiz application so i should keep timer for 30 minutes.Anyone can help me? ,following script as below</p> <pre><code>// enter code here var clock; $(document).ready(function () { clock = $('.clock').FlipClock({ clockFace: 'TwelveHourClock' }); </code></pre> |
37,911,879 | 0 | <p>short answer: Yes you can use <a href="http://api.jquery.com/wrap/" rel="nofollow">wrap()</a> by default the <code>$('.gap')</code> selector it look for <code>.gap</code> class in your HTML, if it found it, it wrap it into <code>li</code> element.</p> <p>demo:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>$('.gap').wrap('<li></li>')</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <span class="gap">...</span></code></pre> </div> </div> </p> <p><strong>Note</strong></p> <p>dont use <a href="http://api.jquery.com/append/" rel="nofollow">append()</a> result will be</p> <pre><code><span class="gap">...<li></li></span> </code></pre> <p><strong>Edit:</strong></p> <p>anyway <code><span class="gap">...<li></li></span></code> or <code><li><span class="gap">...</span></li></code> both of them are not a valid HTML <code>li</code> elements should be inside <code>ul</code> element please check these link, to undertand more about both of them append and wrap</p> |
20,687,990 | 1 | Paginator in python django crashes on dict <p>I have 2 types of gathered data from database:</p> <p>One is <code>[<NaseljenoMesto: NaseljenoMesto object>, <NaseljenoMesto: NaseljenoMesto object>]</code></p> <p>And another is: <code>[{'naseljenomesto_drzava__naziv': u'Srbija', 'sifraMesta': u'ZR', 'nazivMesta': u'Zrenjanin', 'id': 3}, {'naseljenomesto _drzava__naziv': u'Srbija', 'sifraMesta': u'BG', 'nazivMesta': u'Beograd', 'id': 1}]</code></p> <p>First is QuerySet type and another is ValuesQuerySet.</p> <p>Now i have Paginator: <code>paginator = Paginator(filteredData, rowsPerPage)</code></p> <p>In first case paginator works but in second crashes. How to correct this?</p> <h2>EDIT</h2> <pre><code>Internal Server Error: /TestProjekat/main/getFormData/ Traceback (most recent call last): File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 115, in get_response response = callback(request, *callback_args, **callback_kwargs) File "C:\Users\Milan\Desktop\DA_LI_RADI\Test projekat\st_forms\views.py", line 238, in getFormData serializedData = serializers.serialize("json", data) File "C:\Python27\lib\site-packages\django\core\serializers\__init__.py", line 99, in serialize s.serialize(queryset, **options) File "C:\Python27\lib\site-packages\django\core\serializers\base.py", line 46, in serialize concrete_model = obj._meta.concrete_model AttributeError: 'dict' object has no attribute '_meta' </code></pre> <h2>EDIT 2</h2> <pre><code>paginator = Paginator(filteredData, rowsPerPage) try: data = paginator.page(page) except PageNotAnInteger: data = paginator.page(1) except EmptyPage: data = paginator.page(paginator.num_pages) serializedData = serializers.serialize("json", data) </code></pre> <h2>NEW ERROR</h2> <pre><code>Traceback (most recent call last): File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 115, in get_response response = callback(request, *callback_args, **callback_kwargs) File "C:\Users\Milan\Desktop\DA_LI_RADI\Test projekat\st_forms\views.py", line 238, in getFormData serializedData = json.dumps({'data': data}) File "C:\Python27\lib\json\__init__.py", line 243, in dumps return _default_encoder.encode(obj) File "C:\Python27\lib\json\encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True) File "C:\Python27\lib\json\encoder.py", line 270, in iterencode return _iterencode(o, 0) File "C:\Python27\lib\json\encoder.py", line 184, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: <Page 1 of 1> is not JSON serializable </code></pre> |
3,165,742 | 1 | Having PyQt app controlling all. How use reactor? <p>I've a django application, served via Twisted, which also serves ohter services (three sockets, mainly).</p> <p>I need to have it working under windows, and I decide to write a PyQt4 application which acts quite like <strong>Apache Service Monitor</strong> for windows.</p> <p>I was not able to connect twisted reactor to pyqt application reactor, so any hint on this will be welcome too.</p> <p>Now I've this kind of architecture:</p> <ul> <li><strong>QMainWindow</strong> which, in __ init __() has the log.addObserver(callBack) function, and the widget.</li> <li><strong>Twisted initializer</strong> class which extends <strong>QtCore.QThread</strong> and works in a different thread.</li> <li><strong>the django app</strong> which runs over Twisted.</li> </ul> <p>I need to understand how to run the reactor, becouse calling reactor.start() from <strong>QtCore.QThread</strong> works not at all, giving me:</p> <pre><code>exceptions.ValueError: signal only works in main thread </code></pre> <p>Also I'm asking your opinion on the design of applications, does it makes sense for you?</p> |
1,334,140 | 0 | PHP parsing textarea for domain names entered (separated by spaces, commas, newlines) <p>For my users I need to present a screen where they can input multiple domain names in a textarea. The users can put the domain names on different lines, or separate them by spaces or commas (maybe even semicolons - I dont know!)</p> <p>I need to parse and identify the individual domain names with extension (which will be .com, anything else can be ignored).</p> <p>User input can be as:</p> <p>asdf.com</p> <p>qwer.com</p> <p>AND/OR</p> <p>wqer.com, gwew.com</p> <p>AND/OR</p> <p>ertert.com gdfgdf.com</p> <p>No one will input a 3 level domain like www.abczone.com, but if they do I'm only interested in extracting the abczone.com part. (I can have a separate regex to verify/extract that from each).</p> |
586,149 | 0 | <p>You could allow every subdomain in the first place and then check if the subdomain is valid. For example:</p> <pre><code>RewriteEngine on RewriteCond %{HTTP_HOST} ^[^.]+\.example\.com$ RewriteRule !^index\.php$ index.php [L] </code></pre> <p>Inside the <code>index.php</code> you can than extract the subdomain using:</p> <pre><code>if (preg_match('/^([^.]+)\.example\.com$/', $_SERVER['HTTP_HOST'], $match)) { var_dump($match[1]); } </code></pre> <p>But all this requires that your webserver accepts every subdomain name.</p> |
31,537,921 | 0 | <p>HTML 5 has a pattern attribute for the input element, which Paypal implements:</p> <p><code>pattern="(0[1-9]|[12][0-9]|3[01])/(([0][1-9])|([1][0-2]))/((1|2)[0-9]{3})"</code></p> <p>You can find more info on that on the web, for instance this spec on <a href="https://developer.mozilla.org/de/docs/Web/HTML/Element/Input#attr-pattern" rel="nofollow">Mozilla Developer Network</a>.</p> |
37,125,614 | 0 | <p>Why not do something like:</p> <pre><code>np.sort(m)[:,-N:] </code></pre> |
28,860,754 | 0 | Unable to Share Folder in Network <p>I am attempting to create a folder share on a Windows Server 2012 R2 two-node cluster Hyper-V volume in the network and I'm getting these error messages:</p> <p>An error occurred while trying to share FolderA. The resources must be online on the same node for this operation. The shared resource was not created at this time.</p> <p>Can someone please help me resolve this?</p> <p>Thank you!</p> |
31,002,128 | 0 | <p>Some notes:</p> <ol> <li><p>To read/send data over network you need functions such as <a href="http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#sendall" rel="nofollow">this</a> and <a href="https://stackoverflow.com/questions/27527395/how-to-get-the-exact-message-from-recv-in-winsock-programming/27527668#27527668">this</a>. Because send and receive not always send/receive how much you told them to.</p></li> <li><p>You seem to use uninitialized variable <code>new_fd</code> which doesn't look nice.</p></li> <li><p>Finally after you have ensured all the data has been received that was sent(using the approach I mentioned in (1)), comparing strings is not issue - you can use just <code>strcmp</code>, assuming strings are null terminated.</p></li> </ol> |
5,633,187 | 0 | <p>for that..first check your environment variables, then see the class file names, if you do not write .class extention than it may be works...and its batter to include applet file..like in header part of the html code</p> |
36,755,403 | 0 | <p>I'd give this a shot http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </p> <pre><code><script> var app = angular.module('myApp', []); app.controller('customersCtrl', function($scope, $http) { $http.jsonp("http://localhost/json/customer.php?callback=JSON_CALLBACK") .success(function (response) { $scope.simo = response.data; console.log($scope.simo) }); }); app.directive('display',function(){ return { restrict: 'E', scope: { simo: '=' }, template: '<li ng-repeat="x in simo">{{ x.Name + ', ' + x.Country }}</li>' }; }); </script> </code></pre> <p>Not sure if your intent was to pass the entire response object to the directive, but response.data is the location of what you're likely expecting back from the ajax call.</p> <p>Aside from that I would make sure that your object structure is correct. Or if you're returning an array that you set that flag in the $http call.</p> |
3,468,167 | 0 | <p>Date::Manip requires Perl 5.10 to function, see the <a href="http://cpansearch.perl.org/src/SBECK/Date-Manip-6.11/META.yml" rel="nofollow noreferrer">META.yml</a>:</p> <pre><code>requires: ... perl: 5.010 </code></pre> <p>The <a href="http://search.cpan.org/CPAN/authors/id/S/SB/SBECK/Date-Manip-5.56.tar.gz" rel="nofollow noreferrer">older version (5.56)</a> instead only requires perl 5.001 to function and should therefore be safe for you to install.</p> <p>In other words, if you want that latest version you'll have to update your system's perl to at least 5.10. CentOS comes with an old 5.8.8 version, unfortunately.</p> |
8,225,120 | 0 | <p>Use the following method...</p> <pre><code>- (NSArray *)subarrayWithRange:(NSRange)range </code></pre> <p>As per Apple docs... </p> <blockquote> <p>Returns a new array containing the receiving array’s elements that fall within the limits specified by a given range.</p> </blockquote> |
31,497,868 | 0 | <p>If you don't mind deleting every occurrence of <code>2</code> in the list, you can use list comprehension:</p> <pre><code>dictionary["00"] = [i for i in dictionary["00"] if i != 2] </code></pre> <p>This will create a new list, and will avoid altering the other values, as it appears all your <code>dictionary</code> values reference the same list.</p> <p>EDIT: Yep your dictionary values reference the same list</p> <p>you could use dictionary and list comprehension to create your <code>dictionary</code></p> <pre><code>dictionary = {str(x):[i for i in range(10)] for x in range(100)} </code></pre> |
22,015,237 | 0 | Javacard beginner - questions <p>first of all i want to let you know that i am new regarding javacards. I am in the research phase of writing a javacard applet and i have some questions which suprisingly are not so easy to answer through google-search. I want to create an android application which triggers a javacard application via NFC. So far i established a connection to the card with IsoDep.</p> <ol> <li><p>Lets say i have a cap-file. How do I put/install it on an actual javacard? (Do i need a card reader/writer with PC/SC? Which ones do you suggest)</p></li> <li><p>Is it possible to put/install the cap-file using my smartphone (via android)?</p></li> <li><p>Is there any way (through APDU-commands) to get information about what is on the card? Specifically: applets on the card, memory available.</p></li> </ol> <p>Thx very much in advance for the answers.</p> |
32,215,851 | 1 | Problems getting python-docx working with a Python script being executed by a Rails app hosted on Heroku <p>TLDR: My python script which my rails app on heroku fires fails at "from docx import Document" due to some unicode/lxml dependency thing.</p> <pre><code> 2015-08-25T22:09:35.561165+00:00 app[web.1]: Traceback (most recent call last): 2015-08-25T22:09:35.561172+00:00 app[web.1]: File "individual_insights_survey_report.py", line 4, in <module> 2015-08-25T22:09:35.561181+00:00 app[web.1]: from docx import Document 2015-08-25T22:09:35.561222+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/__init__.py", line 3, in <module> 2015-08-25T22:09:35.561254+00:00 app[web.1]: from docx.api import Document # noqa 2015-08-25T22:09:35.561277+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/api.py", line 14, in <module> 2015-08-25T22:09:35.561312+00:00 app[web.1]: from docx.package import Package 2015-08-25T22:09:35.561336+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/package.py", line 11, in <module> 2015-08-25T22:09:35.561369+00:00 app[web.1]: from docx.opc.package import OpcPackage 2015-08-25T22:09:35.561391+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/opc/package.py", line 12, in <module> 2015-08-25T22:09:35.561421+00:00 app[web.1]: from .part import PartFactory 2015-08-25T22:09:35.561443+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/opc/part.py", line 12, in <module> 2015-08-25T22:09:35.561473+00:00 app[web.1]: from .oxml import serialize_part_xml 2015-08-25T22:09:35.561495+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/site-packages/docx/opc/oxml.py", line 12, in <module> 2015-08-25T22:09:35.561533+00:00 app[web.1]: from lxml import etree 2015-08-25T22:09:35.561628+00:00 app[web.1]: ImportError: /app/.heroku/python/lib/python2.7/site-packages/lxml/etree.so: undefined symbol: PyUnicodeUCS2_DecodeLatin1 </code></pre> <p>I thought this might be a versioning thing, but can't seem to find versions that will work as it does locally. This is probably a Python + Heroku thing as this is my first time trying to any sort of Python on Heroku.</p> <p>Specifically I found this <a href="https://mailman-mail5.webfaction.com/pipermail/lxml/2012-September/006572.html" rel="nofollow">mailgroup post</a> which mentions:</p> <blockquote> <p>lxml can support either UCS4 or UCS2 as the internal Unicode representation, but the switch is made at compile-time.</p> <p>Make sure that the Python that compiled etree.so and the Python that uses it are the same. Same version (at least minor as in 2.7.x, maybe micro as in 2.7.3), same architecture, and in this case same Unicode settings (UCS4 vs UCS2.)</p> <p>The easiest way to do this is to re-install lxml from the source tarball. Do you still have this issue?"</p> </blockquote> <p>So I tried to figure out what version of Python was used (failed) and then tried specifying different versions at runtime.txt to try and make it work.</p> <blockquote> <p><strong>Caveat:</strong> here's a lot of pieces in the chain and I'm not very familiar with most of them -- so if I need to provide more information to give context -- please let me know!</p> </blockquote> <p><strong>Full Context:</strong> My company has a Ruby on Rails Webapp that's basically a self service platform for generating data reports for our Client Delivery team.</p> <p>The Rails App, via a click of a button, should fire a Python script which opens up an Excel Spreadsheet (openpyxl) and does runs some data analysis on it and then outputs a report in a Microsoft Word (python-docx) document that is downloaded in a zip file.</p> <p>This is definitely a suboptimal/overly complicated way to do this, but I inherited the Webapp and am just trying to work within its structure for now.</p> <p>I have the Python script working fine when run locally and stand alone (no rails/ruby/heroku) with:</p> <pre><code>Python ver: 2.7.5 openpyxl==2.2.5 python-docx==0.8.5 </code></pre> <p>I've tried the heroku app with: Python versions: 2.7.3, 2.7.5, 2.7.9, 2.7.10 with the error above. This is with requirements.txt looking like:</p> <pre><code>python-docx==0.8.5 openpyxl==2.2.5 lxml==3.4.4 </code></pre> <p>Added lxml to be safe.</p> <p>When I use Python versions: 3.2.5, 3.3.3</p> <p>Where I get this error: </p> <pre><code> 2015-08-25T23:38:59.793177+00:00 app[web.1]: ImportError: No module named site </code></pre> <p>Any help on how to resolve this would be great! Do I need to re-install Python or a module? Is that even doable on Heroku? Am I missing a dependency? A configuration thing? Help :) </p> |
37,779,414 | 0 | <p>I would prefer to first exclude (or replace them by <code>NA</code>) all such values (i.e. <code>n==1</code> & <code>out==1</code>) and then plot it. This is many time useful if one want to show zeros in the plot. For e.g.</p> <blockquote> <p>Something like your plot</p> </blockquote> <pre><code>test.data = data.frame ( sample (1:10,100,replace=TRUE), sample (1:10, 100, replace=TRUE) ) names (test.data) <- c("out","n") ggplot(test.data,aes(log(out),log(n)))+geom_point(aes(color="red")) + xlim (0, 2.5) + ylim (0, 2.5) # just to get same range </code></pre> <p><a href="https://i.stack.imgur.com/GTkR4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GTkR4.png" alt="enter image description here"></a></p> <blockquote> <p>(Probably) something you want </p> </blockquote> <pre><code> dd = apply (test.data,1,function(row) all (row!=1)) # find when neither out nor n is 1 df = test.data[dd,] # take only ggplot(df,aes(log(out),log(n)))+geom_point(aes(color="red")) + xlim (0, 2.5) + ylim (0, 2.5) # just to get same range </code></pre> <p><a href="https://i.stack.imgur.com/rRkoa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rRkoa.png" alt="enter image description here"></a></p> |
8,768,744 | 0 | <p>You can compare two date with following way ..</p> <p>==> extend in built NSDate Class (.h as well as .m files)</p> <pre><code>#import <Foundation/Foundation.h> struct DateInformation { int day; int month; int year; int weekday; int minute; int hour; int second; }; typedef struct DateInformation DateInformation; @interface NSDate (Extra) - (DateInformation) dateInformation; @end </code></pre> <p>implementation class:</p> <pre><code>#import "NSDate+Extra.h" @implementation NSDate (Extra) - (DateInformation) dateInformation { DateInformation info; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *comp = [gregorian components:(NSMonthCalendarUnit | NSMinuteCalendarUnit | NSYearCalendarUnit |NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSSecondCalendarUnit) fromDate:self]; info.day = [comp day]; info.month = [comp month]; info.year = [comp year]; info.hour = [comp hour]; info.minute = [comp minute]; info.second = [comp second]; info.weekday = [comp weekday]; [gregorian release]; return info; } @end </code></pre> <p>from the class where you want to compare to dates </p> <p>do following for both dates</p> <pre><code> NSDate *date=[NSDate date]; DateInformation info=[date dateInformation]; NSLog(@"%@",info); NSDate *date1=[NSDate dateWithTimeIntervalSinceNow:1242141]; DateInformation info=[date1 dateInformation]; NSLog(@"%@",info); </code></pre> <p>implement one more method in extended date class for comparing all the parameter of date which are integer..</p> <p>hope it can help you</p> <p>regards, neil</p> |
37,541,256 | 0 | How to stop wscript.exe from java to stop a mysql server? <p>I am trying to stop wscript that was started from a java application using Runtime.getRuntime().exec("") method.I started a mysql server using wscript.But wscript is not closing when I close my java application,because of this when I restart my application every time 80% of memory is filled with wscript.exe making my pc slow. So my question is how to safely close wscript.exe after its use is over.If this question was asked before someone please point me in right direction</p> <pre><code> public void startMySQLServer() { try { Process process = Runtime.getRuntime().exec("wscript C:\\\\\\\\Users\\\\\\\\Shersha\\\\\\\\Documents\\\\\\\\NetBeansProjects\\\\\\\\Berries\\\\\\\\batch\\\\\\\\mysql_start.vbs"); System.out.println("waiting to start mysql server"); process.waitFor(); System.out.println("mysql server started sucessfully"); } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(DataBaseManager.class.getName()).log(Level.SEVERE, null, ex); } } </code></pre> <p><a href="https://i.stack.imgur.com/TMyd8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TMyd8.jpg" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/WSqt3.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WSqt3.jpg" alt="enter image description here"></a></p> <p>EDITED</p> <pre><code>public void stopMySQLServer() { try { Process process = Runtime.getRuntime().exec("wscript C:\\\\\\\\Users\\\\\\\\Shersha\\\\\\\\Documents\\\\\\\\NetBeansProjects\\\\\\\\Berries\\\\\\\\batch\\\\\\\\mysql_stop.vbs"); System.out.println("waiting to stop mysql server"); process.waitFor(); process.destroy(); System.out.println("process exit value" + process.exitValue()); System.out.println("mysql server stopped sucessfully"); } catch (InterruptedException e) { e.printStackTrace(); } catch (IOException ex) { Logger.getLogger(DataBaseManager.class.getName()).log(Level.SEVERE, null, ex); } } </code></pre> <p>EDITED 2 mysql_start.vbs</p> <pre><code>Set WshShell = WScript.CreateObject("WScript.Shell") If WScript.Arguments.length = 0 Then Set ObjShell = CreateObject("Shell.Application") ObjShell.ShellExecute "wscript.exe", """" & _ WScript.ScriptFullName & """" &_ " RunAsAdministrator", , "runas", 1 Wscript.Quit End if CreateObject("Wscript.Shell").Run "C:\Users\Shersha\Documents\NetBeansProjects\Berries\batch\mysql_start.bat",0,True </code></pre> |
36,297,241 | 0 | <p>You could try to in your functions.php create or register new "Attatchment" based posts using the URLS of your theme images or try using this...</p> <p><a href="https://wordpress.org/plugins/media-library-plus/" rel="nofollow">https://wordpress.org/plugins/media-library-plus/</a></p> |
25,719,746 | 0 | rmarkdown is not available (for R version 3.1.1) <p>I am looking to create some reports using R using markdown via RStudio. Unfortunately, I am unable to open the scripting window as I am getting an error message when trying to download the 'rmarkdown' package. </p> <p>Here is a list of what I have attempted to do to resolve the issue to date:</p> <ul> <li>Automatically install packages - all packages download properly except for one (rmarkdown) and I get the following errors:</li> </ul> <blockquote> <p>Installing package into <code>'C:/Users/rp5/Documents/R/win-library/3.1'</code> (as 'lib' is unspecified) <code>'C:\Program'</code> is not recognized as an internal or external command, operable program or batch file.</p> </blockquote> <ul> <li>If I try using <code>install.packages("rmarkdown")</code> or using the github manual downlaod:</li> </ul> <blockquote> <p>rmarkdown is not available (for R version 3.1.1)</p> </blockquote> <ul> <li>I have tried using various versions of R, updating my current packages, as well un-installing and reinstalling R and R Studio, deleting all previous packages.</li> </ul> <p>Any ideas on what to try next?</p> |
13,646,954 | 1 | swig generated code, generating illegal storage class for python wrapper of C++ API <p>I'm trying to take the approach of using swig with the main header file. It seems like swig will work doing this, but I've run into some problems. I asked a first question about it <a href="http://stackoverflow.com/questions/13581600/compiling-swig-extension-with-coledatetime-for-python">here on stackoverflow</a> and while I haven't yet been successful, I've made enough progress to feel encouraged to continue...</p> <p>So now, here's my interface file:</p> <pre><code>/* File : myAPI.i */ %module myAPI %{ #include "stdafx.h" #include <boost/algorithm/string.hpp> ... many other includes ... #include "myAPI.h" #include <boost/algorithm/string/predicate.hpp> #include <boost/filesystem/path.hpp> #include <boost/filesystem/operations.hpp> using boost::format; using namespace std; using namespace boost::algorithm; using namespace boost::serialization; %} /* Let's just grab the original header file here */ %include "myAPI.h" </code></pre> <p>As far as I can tell swig runs just fine. However, in the generated code it produces numerous definitions like this one:</p> <pre><code>SWIGINTERN int Swig_var_ModState_set(PyObject *_val) { { void *argp = 0; int res = SWIG_ConvertPtr(_val, &argp, SWIGTYPE_p_MY_API, 0 | 0); if (!SWIG_IsOK(res)) { SWIG_exception_fail(SWIG_ArgError(res), "in variable '""ModState""' of type '""MY_API""'"); } if (!argp) { SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in variable '""ModState""' of type '""MY_API""'"); } else { MY_API * temp; temp = reinterpret_cast< MY_API * >(argp); ModState = *temp; if (SWIG_IsNewObj(res)) delete temp; } } return 0; fail: return 1; } </code></pre> <p>Visual Studio 2010 complains with an error for each of these code blocks. The error is based on the <code>temp</code> var:</p> <pre><code>2>c:\svn\myapi\myapi_wrap.cxx(3109): error C2071: 'temp' : illegal storage class </code></pre> <p>I tried just to add a global declaration of this variable as an int to the swig generated _wrap.cxx file, but it didn't not work. (clearly a naive approach...).</p> <p>Does anyone have some insight as to what I need to do to avoid this error?</p> <p>Thanks in advance! </p> |
32,144,603 | 0 | <p>Notes:</p> <ul> <li><p>I am assuming <code>Product::at(int)</code>is returning a <code>Transaction</code>, given a previous question.</p></li> <li><p>I am also assuming OP mean "built-in" when he or she wrote"static"</p></li> </ul> <p>The <code>for</code> can be removed using built-in functions. Some (many?) will find the new syntax less understandable, though.</p> <pre><code>QString Product::toString() { QStringList aggregate; std::transform(m_transactions.begin(), m_transactions.end(), std::back_inserter(aggregate), std::bind(std::mem_fn(&Transactions::toString), std::placeholders::_1)); // or : [](const Transaction& transaction){ return transaction.toString(); }); return aggregate.join("\n"); } </code></pre> <p><code>std::transform</code> will transform every <code>m_transactions</code> elements using <code>Transaction::toString()</code>, and place the results into <code>aggregate</code>. </p> <p><code>std::back_inserter</code> means "use <code>QStringList::push_bask</code> to record the results". If <code>QStringList</code> had a <code>resize(int)</code> like <code>QVector</code> does, we could have used <code>aggregate.begin()</code> instead.</p> <p>The unary function is a bit tricky, as it needs to be converted into a unary function, which what <code>std::bind</code>/<code>std::mem_fn</code> is doing. If you are using C++11, you can use a lambda instead.</p> <hr> <p>Also from the previous question, @SingerOfTheFall's remark is valid:</p> <blockquote> <p>I also find it a little odd to save transactions inside of products. A better design would be having a separate class that could store them.</p> </blockquote> <p>If you keep this design, <code>Transaction Product::at(int)</code> and <code>int Product::size()</code> should be renamed to make the link with <code>Transaction</code> explicit, like <code>getTransaction</code> and <code>getNumberOfTransactions</code>.</p> |
34,730,376 | 0 | <p>PHPUnit do not has command <code>--run</code> which you used in last argument. Check your NetBeans configuration, maybe your IDE try to run PHPUnit older than 4 (actually is version 5) and you have installed newer version.</p> |
1,248,495 | 0 | <p>Have you tested the queries actually work with the values you are giving them? ie, use phpMyAdmin or similar and try the query manually?</p> <p>I have had situations where I thought my PHP was incorrect but a small error in my SQL was the problem. </p> <p>You might also want to set PHP's error mode to E_ALL. You can do that in php.ini or through the code by having</p> <pre><code>ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); </code></pre> <p>at the start of your script. It should [hopefully] give you an error that identifies your problem.</p> <hr> <p><strong>EDIT</strong></p> <p>I just noticed something with your conditions that may be the problem...</p> <p>You have:</p> <pre><code>if (!$playerLEVEL ==13) { levelUPSTATS (); $playerLEVEL = 13; //etc } </code></pre> <p>I rather suspect that if block will never run and there will be no call to levelUPSTATS(). </p> <p>You are asking <strong>if NOT $playerLEVEL is EQUAL to 13</strong> when you really want <strong>if $playerLEVEL is NOT EQUAL to 13</strong> which would make the condition:</p> <pre><code>if($playerLEVEL != 13) </code></pre> <p>Note where the <strong>!</strong> (NOT) goes.</p> <p>As an aside, you have a situation with your inequalities where certain edge cases would mean the player is two levels.</p> <p>For example, for level 2 you need between 100 and 200 EXP inclusive. But level 3 needs 200 and 400 EXP inclusive. If your player has 200EXP he is technically level 2 and 3. When the code runs it will match the 200 in the Level 2 section of code and not the Level 3 section...</p> <p>Your code:</p> <pre><code>if($playerEXPERIENCE >= 100 && $playerEXPERIENCE <= 200) //code to make them 2 if($playerEXPERIENCE >= 200 $$ $playerEXPERIENCE <= 400) //code to make them 3 </code></pre> <p>That to me seems wrong - though it might be what you intended, I don't know. If it wasn't intended you should change it to:</p> <pre><code>if($playerEXPERIENCE >= 100 && $playerEXPERIENCE < 200) </code></pre> <p>Notice the use of <strong><</strong> [LESS THAN] instead of <strong><=</strong> [LESS THAN OR EQUAL TO].</p> <p>I hope this solves your problem :)</p> |
10,661,858 | 0 | <p>It's saying that there are <code>virtual</code> fields in <code>Person</code> which are not defined. So far we can see your declarations, but not definitions. Check that every virtual field in <code>Person</code>, including those inherited, is defined.</p> |
23,988,358 | 0 | How to include .net framework 4.5.1 in VS 2013 <p>I want to create an installer for Windows application, and to include .NET Framework into that installation (I have selected * Download from the same site as my application). But in compilation of Setup project I get an error, saying that there is no framework installation exists. How do I fix it?</p> |
23,175,753 | 0 | <p><strong>Here's How It Works</strong></p> <p>You <strong>>>></strong> Forwarding Aggregator <strong>>>></strong> SMS Aggregator <strong>>>></strong> Mobile Operator <strong>>>></strong> Mobile Company <strong>>>></strong> Your Customer</p> <p><strong>3 Major Parties Are Involved in the Whole Process:</strong></p> <p><strong>1. Mobile Operators:</strong> They Manage SMSC (Short Message Service Centers). AT&T, Sprint/NEXTEL, T-Mobile USA, U.S.Cellular and Verizon Wireless are few of the major mobile operators in the whole world. They have deep connections with all major mobile phone companies. Most of them have 800 to 950 telecommunication/mobile companies in their pannel. All of your messages came to them via SMS Aggregators and they forward them to reciever's Mobile Company which send it to receiver in the end. </p> <p><strong>Cost of becoming a Mobile Operator:</strong> Billion Dollar Business if not Trillion.</p> <p><strong>2. SMS Aggregators:</strong> mBlox, air2web and motricity are few of them. They have deep connections with Mobile operators.</p> <p><strong>Cost of becoming SMS Aggregator:</strong> in Millions</p> <p><strong>3. Forwarding Aggregators/SMS Gateways:</strong> Clickatell, Twilio and esendex and few others are providing SMS Gateway APIs and most of the developers are using Clickatell to integrate its SMS API with their app. They charge different rates for different countries (NO FIXED RATE FOR ALL COUNTRIES). It would cost you rougly around $600-$700 for 100,000 messages (internationally). </p> <p><strong>Cost of becoming Forwarding Aggregator</strong>: May be in Millions</p> <p><strong>Bottom Line:</strong> I'm working on a FREE solution but till today there are no FREE reliable solution in the whole world to send Bulk Messages for FREE internationally. So stop wasting your time on searching for a FREE solution. You have to come up with a new technology in order to achive this.</p> <p>Though there are many options to send Bulk messages within your country for FREE or by spending little money but you simply can't achieve this if you're planning to send messages internationally. </p> <p>Usually I avoid adding comments in any forum but this man really forced me to put my legs in. Here's what he commented: "<strong><em>Can we own an SMSC with a small private GSM network?</em></strong>" </p> <p><strong>lol - Thanks for giving me first laughter of the day</strong> :)</p> |
6,560,218 | 0 | <p>if you are using <code>{% render_comment_form for object %}</code> tag in your template, just add something like <code>{% url object's_named_view object.id as next %}</code> or wrap it with <code>{% with object.get_absolute_url as next %}</code> ... <code>{% endwith %}</code> construction.</p> |
8,656,211 | 0 | <p>You just have to know that you might be reloading the page, and you may try to use the <br/></p> <pre><code>if(!IsPostBack) </code></pre> <p>in your <code>Page_Load(object sender, EventArgs e)</code></p> |
36,502,681 | 0 | <p>You've an answer how to do this with XML::Simple already. But I'd suggest not, and use <code>XML::Twig</code> instead, which is MUCH less nasty. </p> <p><a href="http://stackoverflow.com/questions/33267765/why-is-xmlsimple-discouraged">Why is XML::Simple "Discouraged"?</a></p> <p>I'm going to assume that your XML looks a bit like this:</p> <pre><code><opt Timeout="5"> <Roots> <Root Action="Reject" Interval="Order" Level="Indeterminate" Name="Sales"> <Profiles> <Profile Age="50" Name="Bill" Status="Active" /> <Profile Age="24" Name="Bob" Status="Inactive" /> </Profiles> </Root> </Roots> </opt> </code></pre> <p>I can't tell for sure, because that's the joy of <code>XML::Simple</code>. But:</p> <pre><code>#!/usr/bin/env perl use strict; use warnings; use XML::Twig; my $twig = XML::Twig -> new -> parsefile ( $configfile ); print $twig -> get_xpath ( '//Profile[@Name="Bob"]',0 ) -> att('Status') </code></pre> <p>This uses <code>xpath</code> to locate the attribute you desire - <code>//</code> denotes a 'anywhere in tree' search. </p> <p>But you could instead:</p> <pre><code>print $twig -> get_xpath ( '/opt/Roots/Root/Profiles/Profile[@Name="Bob"]',0 ) -> att('Status') </code></pre> <p>Much <em>simpler</em> wouldn't you agree? </p> <p>Or iterate all the 'Profiles':</p> <pre><code>foreach my $profile ( $twig -> get_xpath ('//Profile' ) ) { print $profile -> att('Name'), " => ", $profile -> att('Status'),"\n"; } </code></pre> |
13,642,262 | 0 | <p>A U-matrix is a visual representation of the distances between neurons in the input data dimension space. Namely you calculate the distance between adjacent neurons, using their trained vector. If your input dimension was 4 then each neuron in the trained map corresponds to a 4-dimensional vector. Lets say you have a 3x3 hexagonal map.</p> <p><img src="https://i.stack.imgur.com/XIztZ.png" alt="map lattice"></p> <p>The umatrix will be a 5x5 matrix with interpolated elements for each connection between two neurons like this</p> <p><img src="https://i.stack.imgur.com/8pHtC.png" alt="u-mat lattice"></p> <p>The {x,y} elements are the distance between neuron x and y and the values in {x} elements are the mean of the surrounding values. eg {4,5} = distance(4,5) and {4} = mean({1,4},{2,4},{4,5},{4,7}). For the calculation of the distance you use the trained 4-dimensional vector of each neuron and the distance formula that you used for the training of the map (usually Euclidian distance). So the values of the umat are only numbers (no vectors). Then you can assign a light gray colour to the largest of these values and a dark gray to the smallest and the other values to corresponding shades of gray. You can use these colours to paint the cells of the umat and have a visualized representation of the distances between neurons.</p> <p><a href="http://users.ics.aalto.fi/jhollmen/dippa/node24.html" rel="nofollow noreferrer">check also this</a></p> |
8,197,061 | 0 | <pre><code>var result=exampleList.GroupBy(p=>p.Name).SelectMany(p=>p.Select((value,index)=> new CartItem() { Name = value.Name + (p.Count() == 1?"": string.Format(" ({0} of {1})", index+1, p.Count())), UnitPrice=value.UnitPrice, Quantity=value.Quantity, } )).ToList(); </code></pre> |
16,247,577 | 0 | WPF UserControls: Image disappears even with 'x:Shared="False"' <p>I defined a style in a <code>ResourceDictionary</code> for a button with an image:</p> <pre><code><Style x:Key="BotonIrAInicioStyle" TargetType="Button"> <Setter Property="Margin" Value="0"/> <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource Self}, Path=ActualHeight}"/> <Setter Property="Content"> <Setter.Value> <Image Margin="2" Source="{StaticResource IconoDashboardBlanco}" MaxHeight="20" Stretch="Uniform" RenderOptions.BitmapScalingMode="HighQuality"/> </Setter.Value> </Setter> </Style> </code></pre> <p>The image source is defined in another <code>ResourceDictionary</code> in the same assembly, and marked as <code>x:Shared="False"</code>:</p> <pre><code><BitmapImage x:Key="IconoDashboardBlanco" x:Shared="False" UriSource="pack://application:,,,/QualityFramework;component/Images/dashboard64X64.png"/> </code></pre> <p>Since the style will be used in a different assembly, I used the <code>"pack://application:,,,"</code> notation to reference the image. The <code>Build Action</code> for the image is set to <code>Resource (Do not copy to output directory)</code>.</p> <p>In the main assembly I have two <code>UserControls</code> which display a button with identical style:</p> <pre><code><Button DockPanel.Dock="Left" Style="{StaticResource BotonIrAInicioStyle}" Click="BotonIrAInicio_Click"/> (Click event has nothing to do with the problem) </code></pre> <p><strong>PROBLEM:</strong></p> <p>I open <code>UserControl A</code> containing the button with the image and the image is displayed ok. Then I open <code>UserControl B</code> containing an identical button, image ok. I open <code>UserControl A</code> again, and the image is gone. Happens the same if I open <code>UserControl B</code> and then <code>UserControl A</code>, the last one "owns" the image.</p> <p>I went everywhere and all the solutions point to the <code>x:Shared="False"</code>, the <code>URI notation</code> and the <code>Build Action</code>... I applied all of them and the problem still happens. I also tried cleaning and rebuilding with no success.</p> <p>What am I missing? Thanks!</p> <p>PS: if I set the content of both buttons to the image directly it works ok, but the whole point of styling is to avoid exactly that!</p> |
8,358,196 | 0 | onfullscreenchange DOM event <p>as the title reads, I'd like to know what is the most reliable way to trigger an event when the Browser(s) enters/leaves in/out the fullscreen mode.</p> <p><strong>note :</strong> I'm not asking how to fullscreen the current page, I just want to know whether or not there is a way to queue some tasks if the user, for example, press F11 or any other related fullscreen-entering keys.</p> |
36,578,070 | 0 | Google Cloud Messaging IP address <p>I have made an android application with GCM enabled service in it which works on localhost. User needs to register in order save the device id in the database which would help administrator to send push notifications to the user. Since, the database is on localhost, registration works fine on emulator. But after installing the app on phone, the device does not get registered. Due to unsuccessful registration, the details do not get entered into the database. After searching a bit, found out the problem as the ip address. IP address on pc is different than the address taken by phone even via same router. Is there any solution for this problem? I really need to run the app on the phone and not just on emulator. Thanks in advance!</p> |
14,086,818 | 0 | <p>Add a button with text. </p> <p>Or add a <code>UITextView</code> and add a tap gesture recognizer to it with an action that performs the segue.</p> |
28,619,001 | 0 | How to migrate from Qt Creator to other IDEs, like Eclipse and Code::Blocks <p>I'm trying to develop a toolbox for System Identification and some other Engineering problems. I've managed to write source codes in C++ and they seem to be functional. </p> <p>Now I'm trying to create some GUI using Qt Creator. Using some tutorials I've found using Qt very simple, but I'm not sure what happens if I decide to change my IDE for some reasons. </p> <p>In my code there are a lot of code lines specific to Qt like: QtWidgets/QApplication, QtWidgets/QLabel, ...</p> <p>As a newbie in programming could someone explain me if there are some standard methods for migrating from Qt Creator to other IDEs.</p> |
27,921,143 | 0 | How to implement a slide down setting view in a sidebar view, jut like Gmail on iOS <p>I am searching for a easy or good way to implement a slide down setting view in sidebar view, just like what Gmail did on iOS. If you click the small down arrow on Gmail's side bar view, it will show a setting view with animation down to the bottom.</p> <p>I am using SWRevealViewController for side bar implementation.</p> <p>Want hear from you masters how to start implement it especially based on SWRevealViewController</p> |
6,528,889 | 0 | <p>See the detailed explanations from <a href="http://msdn.microsoft.com/en-us/library/bb385974.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/bb385974.aspx</a></p> |
26,503,419 | 0 | <p>I still don't know why, but if I use the @Configuration annotation, then it works... No GeoModule bean needed, but how can it be, that with the original config as XML bean definition it works, but with the subclass, it does not?</p> |
10,703,019 | 0 | Redis fetch all value of list without iteration and without popping <p>I have simple redis list key => "supplier_id"</p> <p>Now all I want it retrieve all value of list without actually iterating over or popping the value from list</p> <p>Example to retrieve all the value from a list Now I have iterate over redis length</p> <pre><code>element = [] 0.upto(redis.llen("supplier_id")-1) do |index| element << redis.lindex("supplier_id",index) end </code></pre> <p>can this be done <strong>without the iteration</strong> perhap with better redis modelling . can anyone suggest</p> |
40,001,669 | 0 | How it's possible to set the thread contextclassloader with spark? <p>How it's possible to manage the Thread context classloader with a Spark jobs ?</p> |
6,386,864 | 0 | <p>It is difficult to give a general advice not knowing any specifics. <a href="http://weblogs.asp.net/shijuvarghese/archive/2008/07/09/asp-net-mvc-vs-asp-net-web-form.aspx" rel="nofollow">Here's a brief overview of pros and cons</a></p> |
250,477 | 0 | <p>Lots of people use IOC in .NET, and there are several frameworks available to assist with using IoC. You may see it less in the WinForms side of things, because it's harder to just let the container wire everything together when you are designing forms in Visual Studio, but I can say that for server-side .NET applications, where I work at least, IoC is used very successfully.</p> <p>Why use it in .NET? For the same reason you use it everywhere else. The 2 biggest things I like are:</p> <ul> <li>Designing for IoC tends to enforce good coding practice - designing to interfaces, low coupling, high cohesion. This also leads to classes that are very easy to unit-test.</li> <li>System configuration can often be changed without recompiling.</li> </ul> <p>Some other posts discussing the different IoC/DI frameworks available for .NET:</p> <ul> <li><a href="http://stackoverflow.com/questions/21288/which-cnet-dependency-injection-frameworks-are-worth-looking-into">Which C#/.net Dependency Injection frameworks are worth looking into?</a></li> <li><a href="http://stackoverflow.com/questions/148908/which-dependency-injection-tool-should-i-use">Which Dependency Injection Tool Should I Use?</a></li> </ul> |
11,425,019 | 0 | <p>The same origin policy is applicable only for browser side programming languages. So if you try to post to a different server than the origin server using JavaScript, then the same origin policy comes into play but if you post directly from the form i.e. the action points to a different server like:</p> <pre><code><form action="http://someotherserver.com"> </code></pre> <p>and there is no javascript involved in posting the form, then the same origin policy is not applicable. </p> <p>See <a href="http://en.wikipedia.org/wiki/Same_origin_policy">wikipedia</a> for more information</p> |
1,104,625 | 0 | Cruisecontrol, deployment, folder permissions <p>We're using <a href="http://cruisecontrol.net" rel="nofollow noreferrer">cruisecontrol.net</a>, it builds the version, creates a zip file, then 15 min later, unzips the file on the Integration server. But when the folder gets to the integration server, often, the security permission on one of the folders is totally hosed. The Domain admin and folder owner can't even open the folder in explorer. We reboot and the folder permissions are good we can delete the folder and redeploy the zip file and it's okay.</p> <p>Does anyone have any idea what or how the folder permissions are getting so messed up? Any tools to use to diagnose/watch what exactly is messing it up?</p> |
23,111,106 | 0 | In My database my application form data not storing <p><strong>I developed one form.it will not work properly.here is my code all db,model,controller classes</strong></p> <p>here is database code.</p> <p><strong>database:</strong></p> <pre><code>CREATE TABLE users ( id INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , username VARCHAR( 40 ) NOT NULL , password VARCHAR( 40 ) NOT NULL , email VARCHAR( 255 ) NOT NULL , first_name VARCHAR( 40 ) NOT NULL , last_name VARCHAR( 40 ) NOT NULL ) </code></pre> <p><strong>model class:</strong></p> <pre><code><?php class User extends AppModel{ var $name='User'; } ?> </code></pre> <p><strong>view class:</strong></p> <pre><code><html> <form action="../users/register" method="post"> <p>Please fill out the form below to register an account.</p> <label>Username:</label><input name="username" size="40" /> <label>Password:</label><input type="password" name="password" size="40"/> <label>Email Address:</label><input name="email" size="40" maxlength="255" /> <label>First Name:</label><input name="first_name" size="40" /> <label>Last Name:</label><input name="last_name" size="40" /> <input type="submit" value="register" /> </form> </html> </code></pre> <p><strong>controller class:</strong></p> <pre><code><?php class UsersController extends AppController{ function register(){ if (!empty($this->params['form'])){ if($this->User->save($this->params['form'])){ $this->flash('Registration Successful','/users/register'); } else{ $this->flash('Not succeeded','/users/register'); } } } } ?> </code></pre> <p>please resolve my problem</p> |
25,915,897 | 0 | Android build cycle with eclipse and ant <p>First of all, <strong>my goal</strong>: On running the android application I want to create a new String with the current date/time to display in the application and/or store in the strings.xml. I tried to get into the build and run process with android, eclipse and ant.</p> <p><strong>What I did so far:</strong></p> <p>I did <code>android update project --target --path</code>, I tried eclipse -> export -> ant build files, I somehow managed to execute "ant" on cmd with the "BUILD SUCCESSFUL" result (but it didn't start the application because building and running is different as I learned later), I searched my android sdk for the android_rules.xml but couldn't find it.</p> <p>But my real struggle is <strong>understanding</strong> the build and run cycle of an Android project, additionally with ant.</p> <p>Can someone please help me with this? I haven't found anything understandable for basics. It would be nice to get an approach for my problem with the string on build.</p> <p>Zuop</p> |
8,120,401 | 0 | sbt: Unable to specify application configuration in mingw <p>I am trying to launch an application using sbt's <a href="http://code.google.com/p/simple-build-tool/wiki/GeneralizedLauncher" rel="nofollow">application launcher</a>.<br> This application is defined as: </p> <pre><code>#!/bin/sh java -jar /home/salil.wadnerkar/.conscript/sbt-launch.jar @"/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig" "$@" </code></pre> <p>However, when I launch it, it gives me this error: </p> <pre><code>$ ~/bin/cs n8han/giter8 Error during sbt execution: Could not find configuration file 'C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/n8han/conscript/cs/launchconfig'. Searched: file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/ file:/C:/Users/salil.wadnerkar/ file:/C:/MinGW/msys/1.0/home/salil.wadnerkar/.conscript/ </code></pre> <p>However, the file is present there. So, I think it's because of some quirk in the way sbt handles mingw file path. Does anybody know how I can get it working?</p> |
30,773,970 | 0 | Running msi causes “module failed to register” in 32bit win7,but works in 64bit win7 <p>I'm trying to deploy my project and create an installer. I've created a msi file in vs2005. When running the .msi setup wizard, i'm getting the error:</p> <blockquote> <p>"Module abc failed to register. HRESULT -2147010895. Contact your support personnel."</p> </blockquote> <p>The module that failed to register is a C++ com dll.But in x64 platform it works fine.while I changed the solution's targetPlatform to x86,and replace the dll to the version of win32 dll,then installed at a 32bit win7 computer, I got "Module failed to register". By the way ,I set the dll's register property to the vlaue of vsdrfCOMSelfReg.</p> <p>Does anyone know of a solution for this problem?Thanks!</p> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.