Posts

c# - ForEach extension method -

i'm bit confused on line of code: enumerable.range(1,10).tolist().foreach(console.writeline); this line says does, prints out each number 1 10 line break inbetween each of them, 1 neat little line of code.. now i'm c# novice @ best, looks foreign me, how can call console.writeline() without providing arguments? how know it's going print? syntax it's not clear me we're calling on method (considering lack of paranthesis around writeline ). i'm assuming there's lot of stuff going on "behind scenes" here i'm not @ reading il code, i've gathered reading msil seems foreach calls generic delegate( system.action ) on each element in collection, guessing passes element argument system.action delegate that's guess.. there implicit conversion method group ( console.writeline in case) , compatible delegate type. code same as action<int> f = console.writeline; enumerable.range(1,10).tolist().foreach(f); the delegat...

jquery - Anyway to start animate smoothly? -

so, instead of using plugin wanted make basic marquee. fair enough. easy enough. works decent. thing bugs me way animate starts little slow , speeds up. there anyway solid speed out of animate function? slow down @ beginning it's no fluid. var marquee = $('#marquee'), marqueetext = marquee.find('span:first'), marqpos = marquee.position(), marqtextpos = marqueetext.position(), runmarquee = settimeout(startmarquee, 1000); function startmarquee() { marqueetext.css('left', (marqpos.left - marqueetext.width() - 8)).animate({ 'left': (marqpos.left + marquee.width() + marqueetext.width() + 8) }, { duration: 5000, complete: function () { startmarquee(); } }); } update as adeneo pointed out below, adding easing animate setting linear linear movement remedy problem. not need timeout loop. see updated fiddle. jsfiddle demo add linear easing (the default swing ) e...

java - Is there any Comparable not comparable to itself? -

in contract of comparable , there's nothing forcing object comparable itself. it's just strongly recommended, not strictly required (x.compareto(y)==0) == (x.equals(y)) which implies it's recommended x.compareto(x) not throw. it's possible write a class x implements comparable<y> { ... } where x , y 2 unrelated classes. can't see for, in java 8 version of hashmap there's corresponding check. is allowed implement x implements comparable<y> 2 unrelated classes? does make sense? i guess answers yes , no, it's guess comparable promotes contract comparisons should consistent equals, i.e. (a.compareto(b) == 0) == a.equals(b) . not force , weird contract can enforced. so create a: class dumbinteger implements comparable<dumbinteger> { private final int i; public dumbinteger(int i) { this.i = i; } public int compareto(dumbinteger di) { return 0; } public boolean equals(object other) { /...

No results with PHP search in MongoDB? -

i have database store dns logs. data stored in collection dnslog . document structure: { "_id" : objectid("53539df1e4b076aa8975840a"), "dateandtime" : isodate("2014-04-09t03:42:48z"), "client" : "222.29.72.224", "query" : "www.google.com", "other" : "aaaa" } i stored week's log database , total count 821943936; have following php script search results: $m = new mongoclient(); echo "connection database successfully"."<br />"; $db = $m->dns; echo "datebase dns selected"."<br />"; $collection = $db->dnslog; echo "collection selected succsessfully"."<br />"; $startdate = new mongodate("2014-04-09 11:42:00"); $enddate = new mongodate("2014-04-09 11:43:00"); $result = $collection->find(array("dateandtime"=>array('$gte'=>$startd...

c - Unable to understand the spacefree function in scullpipe driver -

i reading "linux device drivers 3" , having trouble understanding following code: /* how space free */ static int spacefree(struct scull_pipe *dev){ if(dev->rp == dev->wp) return dev->buffersize - 1; return ((dev->rp + dev->buffersize - dev->wp) % dev->buffersize) - 1; } based on understanding: 1. *buffer beginning of buffer. 2. *end ending of buffer. 3. end = buffer + buffersize 4. so, buffersize total size of buffer. if(dev->rp == dev->wp) return dev->buffersize - 1; the above code correct, if both read pointer (rp) , write pointer (wp) @ beginning of buffer. because if no data written buffer, write pointer (wp) @ beginning of buffer (unless write pointer (wp) has wrapped), hence, total amount of free space equal buffersize . but not sure whether above code correct, if both read pointer (rp) , write pointer (wp) point end of buffer (or point memory location in middle of buffer). if write pointer (wp) points end of ...

ssh - Find (by name) and delete a directory and its contents -

i have been able create following command, works extent: find . -type d -name "thumbs" -delete however, deleted empty folders. if found folder called 'thumbs' wasn't empty, didn't delete it. how can find folders called 'thumbs' , delete them, including contents? found answer! use following (with caution): find . -type d -name "thumbs" -exec rm -rf {} \;

c++ - Can boost::lockfree::stack accept string pointers safely? -

i've discovered passing string pointer boost::lockfree::queue cause memory leak because string pointer cannot released. is situation same boost::lockfree::stack ? the requirement boost::lockfree::stack is: t must have copy constructor if regular string pointer cannot used, there other way string can put boost::lockfree::stack ? regular string when try this boost::lockfree::stack<string> my_stack(128); i these errors boost_static_assert(boost::has_trivial_assign<t>::value); boost_static_assert(boost::has_trivial_destructor<t>::value); which seems strange me, because of inexperience, because requirements boost::lockfree::queue strangely has no documentation t must have copy constructor t must have trivial assignment operator t must have trivial destructor the missing documentation doxygen bug, documentation page gets name macro :(, , here: http://www.boost.org/doc/libs/1_55_0/doc/html/boost/lockf...