Posts

string - Saving struct to clipboard in C++ -

i have structure in c++ code: struct sdata { dword number; int currentnumber; bool gameover; }; i need save clipboard structure 1 process. , other process need load again structure . can easy cstrings/strings not structures . suggest me? this method setting cstring clipboard: bool settext(cstring text) { cstring source; source = text; //put text in source if (openclipboard(null)) { hglobal clipbuffer; char * buffer; emptyclipboard(); clipbuffer = globalalloc(gmem_ddeshare, source.getlength() + 1); buffer = (char*)globallock(clipbuffer); strcpy(buffer, lpcstr(source)); globalunlock(clipbuffer); setclipboarddata(cf_text, clipbuffer); closeclipboard(); return true; } else { return false; } } and getter: std::string gettext(void) const { ...

javascript - Regular expression improvement -

i trying write regular expression capture data, struggling finish it. from data: code:name another-code:another name i need array: ['code:name', 'another-code:another name'] the problem codes can space. i know how without using regular expressions, decided give them chance. update: forgot mention number of elements can vary 1 infinity. data: code:name -> ['code:name'] code:name code:name code:name -> ['code:name', 'code:name', 'code:name'] is suitable. just split input according space followed 1 or more non-space characters , : symbol. > "code:name another-code:another name".split(/\s(?=\s+?:)/) [ 'code:name', 'another-code:another name' ] or > "code:name another-code:another name".split(/\s(?=[^\s:]+:)/) [ 'code:name', 'another-code:another name' ]

c++ - gtest DEATH_TEST complains about fork() and threads, but only threads found had been joined -

i'm using gtest unit testing and, in particular, have death_tests assertions in debug builds. setup() test, have create object creates thread, goes off , work, returns data, , joins on object's thread. test fixture's setup() returns, allowing test body run. i've noticed death_test complain death tests use fork(), unsafe particularly in threaded context. test, google test detected 2 threads. is, of course, valid problem if there's multiple threads running . sometimes, however, no such warning exists. seems race condition. so looking it, discovered gtest using /proc/self/task pseudo filesystem discover threads. since of threads named, decided use /proc/self/task/[tid]/comm discover thread might lingering. indeed, it's exact same thread join() ed. came example source code reproduce issue 1) reproduces gtest's thread detection gtest, , 2) if target thread lingering, emits message stdout. // g++ test.cpp --std=c++11 -pthread #include <iostream...

jquery - Define a minimun height when collapsing in Bootstrap -

Image
in bootstrap, want set height when collapses. want keep collapsible area shown using .collapse.in class. when collapses won't set height zero. before collapse: after collapse: update: http://jsfiddle.net/r6eaw/1158/ css: #collapseone{ min-height:60px } jq: $('#accordion').on('hidden.bs.collapse', function () { $('#collapseone').removeclass('collapse').css({ 'overflow': 'hidden', 'height': '60px' }) })

sql - Different prices per state for product -

i trying run query price of item purchased customer. issue products built @ base level 'blank' state example see below. state product price x 5.00 oh x 5.25 ca x 5.75 y 6.00 i know if im getting somewhere type of case statement , place this going join statement (case when a.state= b.state a.state else 'blank' end) edit: select o.name, o.state, o.item, i.rate orders o left join on item_desc o.item = i.item , case when o.state = i.state o.state else null end = i.state revised works null isnt working need replace catch blank field (field empty/blank not null) in case rate null , can result doing correlated sub query in case statement. sql fiddle demo select o.name, o.state, o.item, case when i.rate null ( select rate item_desc item = o.item , coalesce(state,'') ='' ...

python - Row and column indexes of True values -

i have nxn pandas dataframe contains booleans. example: in[56]: df out[56]: 15 25 35 45 55 10 true false false false false 20 false true false false false 30 false false true false false 40 false false false true false 50 false false false false true what need collapse frame nx2 pandas dataframe has index , column values have true @ intersection record values. example: in[62]: res out[62]: 0 1 0 10 15 1 20 25 2 30 35 3 40 45 4 50 55 can't seem find simple way this. pd.melt "unpivots" dataframe wide long format: result = pd.melt(df.reset_index(), id_vars=['index']) mask = result['value'] == true result = result.loc[mask, ['index', 'variable']] result.columns = [0, 1] print(result) yields 0 1 0 10 15 6 20 25 12 30 35 18 40 45 24 50 55 ps. desired dataframe has 2 columns have values act coordinates. df.pivot method conver...

AngularJS Resolve a route based on a service promise -

i using ngroute , and trying routes resolve based on result of function in service have defined my service follows: app.factory('authservice', function ($q,$location,$http) { var isloggedin = false; return { hasloginsession: function(){ var defer = $q.defer(); if(isloggedin) { //user has valid session previous getsession.json request defer.resolve(isloggedin); } else { return $http.get('/session/getsession.json').success(function(data, status, headers, config) { isloggedin = data.success; if(isloggedin) { defer.resolve(isloggedin); } else { defer.reject("ex_login_session_is_unknown"); } }). error(function(data, status, headers, config) { isloggedin=false; ...