Posts

php - Can't Understand 1 Line of Code in C++ STL Source: Lower_Bound/Upper_Bound -

i writing code find last key value no more given integer php. e.g.,array(0=>1,1=>2,2=>3,3=>3,4=>4). given integer 3, find key 3.(binary search) and looked references binary search on internet. find this, find first key value no less given integer c++. says: template <class _forwarditer, class _tp, class _distance> _forwarditer __lower_bound(_forwarditer __first, _forwarditer __last, const _tp& __val, _distance*) { _distance __len = 0; distance(__first, __last, __len); _distance __half; _forwarditer __middle; while (__len > 0) { __half = __len >> 1; __middle = __first; advance(__middle, __half); if (*__middle < __val) { __first = __middle; ++__first; __len = __len - __half - 1; } else __len = __half; // <======this line } return __first; } well, why using "__len = __half;" rather "__len = __half + 1;"? won't ...

Get NSImage from NSTextField in Swift -

i used retrieve nsimage in subclass of nstextfield obj-c this: nsdictionary *attributedval = [[self attributedstringvalue] attributesatindex:i effectiverange:&effectiverange]; if ([[attributedval allkeys] containsobject:nsattachmentattributename]) { nstextattachment *attachment = [attributedval valueforkey:nsattachmentattributename]; nscell *attachmentcell = (nscell *)[attachment attachmentcell]; ... [[attachmentcell image] name] ... } when try same in swift can't seem able cast attachmentcell compiler error: let attributedval = attributedstringvalue.attributesatindex(i, effectiverange: effectiverange) if let attachment = attributedval[nsattachmentattributename] as? nstextattachment { let attachmentcell = attachment.attachmentcell nscell // not work ... } thanks nate cook. following works: let attributedval = attributedstringvalue.attributesatindex(i, effectiverange: effectiverange) if let attachment = attributedval[nsa...

python - How to get the value from a timedelta? -

when sqlalchemy returns: {u'age': datetime.timedelta(12045),} how 12045? i've tried str() , strftime() , , bunch of others, nothing works. from docs , use .total_seconds() length of timedelta. note timedelta you've provided showing days value, timedelta includes seconds , microseconds well. if want days, use .days . age = datetime.timedelta(12045) print(age.total_seconds()) # 1040688000.0 print(age.days) # 12045, not full value represented delta

Capturing Splunk dashboards to PDF -

i want capture splunk dashboard pdf sending periodic email. inbuilt pdf generator doesn't creates pdf in splunk. there open source tools can used cutycapt can capture screen via linux commands pages authentication. you try phantomjs . it uses webkit internally , has screen capture capability allowing export web page png/jpeg/pdf.

regex - How to insert a string between particular characters in Python? -

say have large parent string containing many characters. how can insert string between match of characters (and additionally, erase characters between matching characters)? for example, largestring guaranteed contain single set of ###### 's (6 hash characters). how can insert smallstring between it, ending similar (i guess better 'create string', since strings immutable): largestring = "lorem ipsum ###### previous text erased ###### dolor sit amet" smallstring = "foo bar" newstring = "lorem ipsum ###### foo bar ###### dolor sit amet" any ideas? assume use bit of regex... something like >>> import re >>> largestring = "lorem ipsum ###### previous text erased ###### dolor sit amet" >>> smallstring = "foo bar" >>> re.sub(r'(?<=###### ).*(?= ######)', smallstring, largestring) lorem ipsum ###### foo bar ###### dolor sit amet' (?<=###### ) postive b...

Entity Framework and One to Many Relationships not saving right -

i worked entity framework several years ago, , may me being bit rusty. have detached entities, in turn have multiple child entities. in case it's person entity , each person has multiple addresses. myperson.firstname="update first name"; //assuming have address in first entry //with appropriate primary keys , foreign key ids, do: myperson.addresses.first().line1="update line 1"; myperson.addresses.add(new address(){line1="weee",line2="aaaa" postal="12345", type="work"}); mydb.person.attach(myperson); mydb.entry(myperson).state=entitystate.modified; mydb.savechanges(); when scenario this, expect first name. updates first name, , expected blanks out other fields (lastname, birthday etc etc) in above code. doesn't create new address person, nor update existing address. i don't recall requiring work database context know how update related entities associated person above. in google searches seem hearin...

python - pandas read frame and subsequent type manipulation issue -

hello rookie pandas , have particular behavior want know reason for sqlnew = 'select fund_no,start_date,end_date,cash,bond,small_cap,large_cap,international odsact.act_src_fund_mapping;' actualfundmapping = psql.read_frame(sqlnew,cnxn) 'everyworks fine until above' actualfundmapping.dtypes:: fund_no object start_date object end_date object cash float64 bond float64 small_cap float64 large_cap float64 international float64 'so since want stuff datetime.datetime(2013,1,1) in actualfundmapping['start_date'] try changing dtype below actualfundmapping['start_date'] = pd.to_datetime(str(actualfundmapping['start_date'])) actualfundmapping['end_date'] = pd.to_datetime(str(actualfundmapping['end_date'])) actualfundmapping['fund_no'] = actualfundmapping['fund_no'].astype(np.int64) 'but existence tests come false datetime.datetime(20...