Posts

c++ - Why do college computer science classes promote 'using namespace std'? -

i've taken 2 classes on c++ far, 1 each @ different school, , both of them have used 'using namespace std;' teach basic programming. may coincidence had go out of way find out it's not practice so. because best practices when writing sample code not best practices when writing large projects. in c++ course, write small programs (up few hundred lines of code) have solve relatively small problem. means little no focus on future maintenance (and avoiding sources of confusion future maintainers). because many teachers not have coding experience in large projects, problem doesn't acknowledged (let alone discussed) in c++ courses.

android - Do I need to call getWritableDatabase() everytime I manipulate data -

i have newbie question sqlite databases in android: do need retrieve writeable database everytime manipulate data? so can write dao this: class dao { private final sqlitedatabase database; public dao(sqliteopenhelper databasehelper){ database = databasehelper.getwritabledatabase(); } public void insert(...){ contentvalues cv = new contentvalues(4); database.insertorthrow(table, null, cv); ... } public void update(...){ contentvalues cv = new contentvalues(4); database.update(....); } } or must write dao this: class dao { private final sqliteopenhelper databasehelper; public dao(sqliteopenhelper databasehelper){ this.databasehelper = databasehelper } public void insert(...){ sqlitedatabase database = databasehelper.getwritabledatabase(); contentvalues cv = new contentvalues(4); database.insertorthrow(table, null, cv); ...

javascript - ng-repeat performance over thousands of elements without limit filter -

i'm generating svg graph in angular template based on array of following format: [{x: 0, y: 1}, {x: 1, y: 2}, ...] -- array contain thousands of points. while can render <path> element thousands of points, unacceptable performance occurs when use ng-repeat create <circle> element each point. to ensure performance not due svg performance , copied angular generated svg output , created static .html file included 5 graphs containing 10,000 <circle> elements. static file rendered instantly. confirmed it's not boiler plate code generating , scaling points because without <circle> elements (only 2 <path> elements) performance exceptional. i've narrowed down either ng-repeat 's dom injection mechanics or fact ng-repeat creates child scope each element own dirty checking watchers. based on exhaustive research appears it's more latter. here's template generates graph: <svg width="1020" height="220...

xml - How to compare the value of the current for-each element? -

xml: <a>1</a> <a>2</a> <b>3</b> <a>4</a> <b>5</b> desired output: value value value b value value b xslt: <xsl:for-each select="a | b"> <xsl:if test="? = 'a'"> value </xsl:if> <xsl:if test="? = 'b'"> value b </xsl:if> </xsl:for-each> how compare value of current element in line <xsl:if test="? = 'a'"> , <xsl:if test="? = 'b'"> ? you need name() , strange way of going it. posted, want output names of nodes. in case: <xsl:apply-templates select='a|b' /> <xsl:template match='a|b'> value <xsl:value-of select='name()' /> </xsl:template>

Python: Create a "Table Of Contents" with python-docx/lxml -

i'm trying automate creation of .docx files (wordml) of python-docx ( https://github.com/mikemaccana/python-docx ). current script creates toc manually following loop: for chapter in mychapters: body.append(paragraph(chapter.text, style='listnumber')) does know of way use "word built-in" toc-function, adds index automatically , creates paragraph-links individual chapters? thanks lot! the key challenge rendered toc depends on pagination know page number put each heading. pagination function provided layout engine, complex piece of software built word client. writing page layout engine in python not idea, not project i'm planning undertake anytime :) the toc composed of 2 parts: the element specifies toc placement , things heading levels include. the actual visible toc content, headings , page numbers dotted lines connecting them. creating element pretty straightforward , relatively low-effort. creating actual visible content, @...

javascript - FormData Object Parsing Only One Input -

i have formdata object create using form's id. form has multiple input values. send formdata using xmlhttprequest(). however in request (which have debugged using google chrome's developer tool) can see in form data, when view "parsed" version sending first input value. when view source of formdata input values there. my question why when viewing parsed version of formdata can see 1 value whereas viewing source can see of them? this may cause of other issues on server end not retrieving of parameters correctly. edit - code form <form id='properties'> <input type='text' name='name' value='previous'/> <input type='text' name='occupation' value='unknown'/> <input type='hidden' name='id' value='23'/> </form> javascript xmlhttprequest method function sendrequest() { var request = gethttprequest(); request.onreadystat...

python - Improving Performance of Multiplication of Scipy Sparse Matrices -

given scipy csc sparse matrix "sm" dimensions (170k x 170k) 440 million non-null points , sparse csc vector "v" (170k x 1) few non-null points, there can done improve performance of operation: resul = sm.dot(v) ? currently it's taking 1 second. initializing matrices csr increased time 3 seconds, csc performed better. sm matrix of similarities between products , v vector represents products user bought or clicked on. every user sm same. i'm using ubuntu 13.04, intel i3 @3.4ghz, 4 cores. researching on read ablas package. typed terminal: ~$ ldd /usr/lib/python2.7/dist-packages/numpy/core/_dotblas.so which resulted in: linux-vdso.so.1 => (0x00007fff56a88000) libblas.so.3 => /usr/lib/libblas.so.3 (0x00007f888137f000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8880fb7000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8880cb1000) /lib64/ld-linux-x86-64.so.2 (0x00007f888183c000) and underst...