Posts

python - unittest testcase setup new object -

i'm using pydev in classic eclipse 4.2.2 python2.7. please consider code , result below read. suppose create object variable of predefined value. now, suppose change value , create new object of same name (i.e., old name points new object). expect old name point new object value not differ predefined value given in class definition. not case. suggestions why? code: class example(object): veryimportantdict = {'a': 0} def __init__(self): pass def set_veryimportantnumber(self,key,val): self.veryimportantdict[key] = val if __name__ == '__main__': test = example() print "new object: ", test print "new object's dict: ",test.veryimportantdict test.set_veryimportantnumber('a',5) print "old object's dict: ",test.veryimportantdict test = example() print "new object: ", test print "new object's dict: ",test.veryimportantdict which ...

c - showing verticies in openGL -

i have program renders 3d wire mesh model using code fragment in loop. glbegin(gl_lines); glcolor3f(.0f, 0.0f, 0.0f); glvertex3d(xs,ys,zs); glvertex3d(xe,ye,ze); glend(); i need add functionality vertices line starts , ends can rendered if user desires, using small shaded circle. circle should of constant screen size, 4-6 pixels across , rendered @ size independent of camera is, or how close is. can suggest how render such vertex? you can use gl_points in glbegin glpointsize function.

c++ - std::regex_match() freezes my program -

so here program: #include "stdafx.h" #include <iostream> #include <string> #include <regex> #include <windows.h> using namespace std; int _tmain(int argc, _tchar* argv[]) { string str = "<link rel=\"shortcut icon\" href=\"http://joyvy.com/img/favicon.png\" />"; regex expr("<link rel=+(\"|')+shortcut+(.*?(\"|'))+(.*?)href=(\"|')+(.*?)+(\"|')"); smatch matches; cout << "start..." << endl; regex_match(str, matches, expr); cout << "this not printed"; } and here output of program: start... the std::regex_match() function call freezes program. after lapse of 2 or 3 minutes trows error: unhandled exception @ at 0x7515b760 in regex.exe: microsoft c++ exception: std::regex_error @ memory location 0x001d9088. so what's wrong? looks regular expression complex, , takes forever process. , ...

c# - DateTime is not in proper format -

i have property follows: [datatype(datatype.datetime)] [displayformat(applyformatineditmode = true, dataformatstring = "{0:dd/mm/yyyy}")] public datetime ? enddate { set; get; } when use @html.displayfor(modelitem => item.enddate) i result follows: 17.07.2013 why happening? there's several ways this. either: change regional settings user running web application use correct cultureinfo object when formatting set default cultureinfo object on current thread escape slashes to provide cultureinfo object when formatting: @html.displayfor(modelitem => item.enddate.tostring("dd/mm/yyyy", cultureinfo.getculture("en-us"))) to set default cultureinfo object: thread.currentthread.currentculture = cultureinfo.getculture("en-us"); to escape slashes, use single quotes: [displayformat(applyformatineditmode = true, dataformatstring = "{0:dd'/'mm'/'yyyy}")] note code ends in date...

How to remove extra symbols from CURL in PHP? -

i have simple curl request socket, returns process pid. problem there chars/symbols witch unseen. code is: for ($i = 0; $i < 3; $i++ ) { $ch = curl_init($server); curl_setopt($ch, curlopt_ssl_verifyhost, 0); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, '<ping></ping>'); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_connecttimeout ,0); curl_setopt($ch, curlopt_timeout, 400); $output = array( 'result' => curl_exec($ch), 'info' => curl_getinfo($ch), 'error' => curl_error($ch) ); curl_close($ch); var_dump($output['result']); var_dump(trim($output['result'])); var_dump($pid); echo "----------------\n"; if (trim($output['result']) == $pid) die('true'); sleep(2); } die('false'); ...

database - Random "SELECT 1" query in all requests on rails -

Image
i'm profiling rails 3.2 app miniprofiler, , shows me a select 1 query @ beginning of each page load or ajax call. takes 0.4ms, still seemingly unnecessary database query. anyone know why query happening or how rid of it? select 1 ping - cheapest query test whether session alive , kicking. various clients use purpose. may useless in case ...

javascript - Knockout binding for toggle switch -

i need bind jquery toggle switch knockout observables , please me correct approach mine not working my html file looks : html: <select name="toggleswitch1" id="toggleswitch1" data-theme="b" data-role="slider" data-bind="option:activatenotification"> <option value="false">no</option> <option value="true">yes</option> and view model : javascript: function selectvm(){ self = this; self.activatenotification = ko.observable(true); } not 100% sure you're trying if trying bind selected option have use value: activatenotification