Tuesday, 15 April 2014

javascript - Can I get text source of link stylesheet? -



javascript - Can I get text source of link stylesheet? -

i seek css text link element. illustration style element simplest:

[].map.call(document.stylesheets, function(stylesheet) { var tag = stylesheet.ownernode.tagname.tolowercase(); if (tag == 'style') { homecoming stylesheet.ownernode.textcontent; } else if (tag == 'link') { //is possible receive source here without ajax? } });

is there way link source without loading text?

with document.stylesheets can interate through loaded stylesheets on page. each 1 list of css rules elements. can obtain csstext property of these css rules.

based on this post, i've come sample script css rules text loaded on page. hope helps...

http://jsfiddle.net/qmaw7/1/

var cssstyles = ""; //started @ index 1 index 0 browser's user agent stylesheet. for(var i=1; i<document.stylesheets.length; i++) { var style = null; (document.stylesheets[i]) { if (typeof cssrules != "undefined") style = cssrules; else if (typeof rules != "undefined") style = rules; } for(var item in style) { if(style[item].csstext != undefined) cssstyles = (style[item].csstext); } } alert(cssstyles);

javascript html css

Read many Excel files from R -



Read many Excel files from R -

it's first time r, maybe problem trivial

i need download date xls files url , each 1 should in 1 info frame. here .

i decided utilize gdata bundle (package ‘xlsreadwrite’ not available r version 3.1.0, rodbc not available win64)

downloading works great 1 file (year e.g = 2013 )

readxls<-function() { library("gdata") link<-paste0("http://nbp.pl/kursy/archiwum/archiwum_tab_a_",year,".xls") xlsdata <<- read.xls(link, sheet = 1, perl = "c:\\perl64\\bin\\perl.exe", header=true) }

i tried read many .xls list() using loop. (e.g. y_begin=2012, y_end=2014)

readxls<-function() { library("gdata") ldata<<- list() j=1 (i in y_begin:y_end) { link<-paste0("http://nbp.pl/kursy/archiwum/archiwum_tab_a_",i,".xls") xlsdata <<- read.xls(link, sheet = 1, perl = "c:\\perl64\\bin\\perl.exe", header=true) ldata[j] <<- xlsdata j<-j+1 } }

i thought after i'd able merge them, don't know how info single info frame in list illustration > view(ldata[2]) returns first collumn

avoid utilize for loop , specially side effect. improve utilize lapply here. r way things ( functional programming). here this:

library(gdata) readxls<-function() { ids <- seq(y_begin,y_end) links <-paste0("http://nbp.pl/kursy/archiwum/archiwum_tab_a_",ids,".xls") lapply (links,function(i) read.xls(link, sheet = 1, perl = "c:\\perl64\\bin\\perl.exe", header=true) ) }

this homecoming list of data.frame, merge them, assuming ll same:

ll <- readxls() do.call(rbind,ll)

r excel

c++ - Is VC++ still broken Sequentially-Consistent-wise? -



c++ - Is VC++ still broken Sequentially-Consistent-wise? -

i watched (most of) herb sutter's atmoic<> weapons video, , wanted test "conditional lock" loop within sample. apparently, although (if understand correctly) c++11 standard says below illustration should work , sequentially consistent, not.

before read on, question is: correct? compiler broken? code broken - have race status here missed? how bypass this?

i tried on 3 different versions of visual c++: vc10 professional, vc11 professional , vc12 express (== visual studio 2013 desktop express).

below code used visual studio 2013. other versions used boost instead of std, thought same.

#include <iostream> #include <thread> #include <mutex> int = 0; std::mutex m; void other() { std::lock_guard<std::mutex> l(m); std::this_thread::sleep_for(std::chrono::milliseconds(2)); = 999999; std::this_thread::sleep_for(std::chrono::seconds(2)); std::cout << << "\n"; } int main(int argc, char* argv[]) { bool work = (argc > 1); if (work) { m.lock(); } std::thread th(other); (int = 0; < 100000000; ++i) { if (i % 7 == 3) { if (work) { ++a; } } } if (work) { std::cout << << "\n"; m.unlock(); } th.join(); }

to summarize thought of code: global variable a protected global mutex m. assuming there no command line arguments (argc==1) thread runs other() 1 supposed access global variable a.

the right output of programme print 999999.

however, because of compiler loop optimization (using register in-loop increments , @ end of loop copying value a), a modified assembly though it's not supposed to.

this happened in 3 vc versions, although in code illustration in vc12 had plant calls sleep() create break.

here's of assembly code (the adress of a in run 0x00f65498):

loop initialization - value a copied edi

27: (int = 0; < 100000000; ++i) 00f61543 xor esi,esi 00f61545 mov edi,dword ptr ds:[0f65498h] 00f6154b jmp main+0c0h (0f61550h) 00f6154d lea ecx,[ecx] 28: { 29: if (i % 7 == 3)

increment within condition, , after loop copied location of a unconditionally

30: { 31: if (work) 00f61572 mov al,byte ptr [esp+1bh] 00f61576 jne main+0edh (0f6157dh) 00f61578 test al,al 00f6157a je main+0edh (0f6157dh) 32: { 33: ++a; 00f6157c inc edi 27: (int = 0; < 100000000; ++i) 00f6157d inc esi 00f6157e cmp esi,5f5e100h 00f61584 jl main+0c0h (0f61550h) 32: { 33: ++a; 00f61586 mov dword ptr ds:[0f65498h],edi 34: }

and output of programme 0.

the 'volatile' keyword prevent kind of optimization. that's it's for: every utilize of 'a' read or written shown, , won't moved in different order other volatile variables.

the implementation of mutex should include compiler-specific instructions cause "fence" @ point, telling optimizer not reorder instructions across boundary. since implementation not compiler vendor, maybe that's left out? i've never checked.

since 'a' global, think compiler more careful it. but, vs10 doesn't know threads won't consider other threads utilize it. since optimizer grasps entire loop execution, knows functions called within loop won't touch 'a' , that's plenty it.

i'm not sure new standard says thread visibility of global variables other volatile. is, there rule prevent optimization (even though function can grasped way downwards knows other functions don't utilize global, must assume other threads can) ?

i suggest trying newer compiler compiler-provided std::mutex, , checking c++ standard , current drafts that. think above should help know for.

—john

c++ multithreading visual-c++ concurrency compiler-optimization

how do I change the location of the httpd.conf for Apache on windows? -



how do I change the location of the httpd.conf for Apache on windows? -

i working on setting load balancing cluster on windows server 2012 , have shared drive want configuration files apache exist at. way each fellow member of lb can load exact same config files. how alter config file located independently of serverroot is?

start apache process -d parameter , give alternative serverroot argument, though i'd imagine much improve thought utilize mechanism sync files locally each server.

also read http://httpd.apache.org/docs/2.4/mod/core.html#mutex, it's advised if you're running networked file system.

if want specify main config file, start process -f parameter , path config file argument.

windows apache httpd.conf

inserting variables and looping over a python class call -



inserting variables and looping over a python class call -

i'm using flask-sqlalchemy , flask-wtf. want take string produced "row.form_field" query , place wtf form class call. ideas on how can pull off?

from forms import form_list models import form_value form = form_list values = form_value.query.filter_by(form_entry_id = id) row in values: print row.form_field, row.value #this works. form.row.form_field.data = row.value #this not! # form.???how insert "row.form_field" here???.data = row.value

you can utilize getattr:

getattr(form, row.form_field).data = row.value

but easier, can pass info instantiated wtforms class:

data = {row.form_field: row.value row in values} form_list = formlist(**data)

python class flask flask-sqlalchemy flask-wtforms

java - Why isn't Spring chaining ExceptionHandlers? -



java - Why isn't Spring chaining ExceptionHandlers? -

i have several spring @exceptionhandlers follows:

@exceptionhandler(mailerexception.class) @responsestatus(value = httpstatus.internal_server_error) public string mailerexception(mailerexception e, httpservletrequest request, locale locale) { flashmap outputflashmap = requestcontextutils.getoutputflashmap(request); if (outputflashmap != null) { outputflashmap.put("flashmessage", messagesource.getmessage("controller.internal_server_error", null, locale)); } homecoming "redirect:/index"; } @exceptionhandler(executionexception.class) public string executionexception(executionexception e) throws throwable { throw e.getcause(); }

when executionexception thrown mailerexception cause, executionexception handler invoked not mailerexception one...

i not sure why... can please explain?

here stacktrace:

grave: servlet.service() servlet [bignibou] in context path [/bignibou] threw exception [request processing failed; nested exception java.util.concurrent.executionexception: com.bignibou.mailerexception: messagingexception | mailsendexception] root cause com.bignibou.mailerexception: messagingexception | mailsendexception @ com.bignibou.service.preference.preferenceserviceimpl.sendpasswordresetinfo_aroundbody10(preferenceserviceimpl.java:122) @ com.bignibou.service.preference.preferenceserviceimpl$ajcclosure11.run(preferenceserviceimpl.java:1) @ org.springframework.transaction.aspectj.abstracttransactionaspect.ajc$around$org_springframework_transaction_aspectj_abstracttransactionaspect$1$2a73e96cproceed(abstracttransactionaspect.aj:59) @ org.springframework.transaction.aspectj.abstracttransactionaspect$abstracttransactionaspect$1.proceedwithinvocation(abstracttransactionaspect.aj:65) @ org.springframework.transaction.interceptor.transactionaspectsupport.invokewithintransaction(transactionaspectsupport.java:262) @ org.springframework.transaction.aspectj.abstracttransactionaspect.ajc$around$org_springframework_transaction_aspectj_abstracttransactionaspect$1$2a73e96c(abstracttransactionaspect.aj:63) @ com.bignibou.service.preference.preferenceserviceimpl.sendpasswordresetinfo_aroundbody12(preferenceserviceimpl.java:111) @ com.bignibou.service.preference.preferenceserviceimpl$ajcclosure13.run(preferenceserviceimpl.java:1) @ org.springframework.scheduling.aspectj.abstractasyncexecutionaspect.ajc$around$org_springframework_scheduling_aspectj_abstractasyncexecutionaspect$1$6c004c3eproceed(abstractasyncexecutionaspect.aj:58) @ org.springframework.scheduling.aspectj.abstractasyncexecutionaspect.ajc$around$org_springframework_scheduling_aspectj_abstractasyncexecutionaspect$1$6c004c3e(abstractasyncexecutionaspect.aj:62) @ com.bignibou.service.preference.preferenceserviceimpl.sendpasswordresetinfo(preferenceserviceimpl.java:111) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:317) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:190) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:157) @ org.springframework.aop.interceptor.asyncexecutioninterceptor$1.call(asyncexecutioninterceptor.java:128) @ java.util.concurrent.futuretask.run(futuretask.java:266) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1142) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:617) @ java.lang.thread.run(thread.java:745)

here gets displayed in browser:

etat http 500 - request processing failed; nested exception java.util.concurrent.executionexception: com.bignibou.mailerexception: messagingexception | mailsendexception

java spring exception exception-handling

RestKit , PUT complex JSON to server -



RestKit , PUT complex JSON to server -

the request json want set server

"type": "payment", "paymentoptions": [ { "type": "netbanking", "name": "netbanking - axis bank", "expirydate": null, "bank": "axis bank" } ]

class mapping

@interface ctspaymentdetailupdate : nsobject @property(nonatomic, strong, readonly) nsstring* type; @property(nonatomic, strong, readonly) nsmutablearray* paymentoptions; @interface ctspaymentoption : nsobject @property(nonatomic, strong) nsstring* type, *ownername, *number, *bankname, *expirydate;

code mapping

#define mlc_profile_update_payment_request_mapping \ @{ \ @"type" : @"type", \ @"bank" : @"bankname", \ @"owner" : @"ownername", \ @"number" : @"number", \ @"expirydate" : @"expirydate", \ @"name" : @"cardname" \ } rkobjectmapping* paymentoptionmapping = [rkobjectmapping mappingforclass:[ctspaymentoption class]]; [paymentoptionmapping addattributemappingsfromdictionary: mlc_profile_update_payment_request_mapping]; rkobjectmapping* paymentdetailreq = [rkobjectmapping requestmapping]; [paymentdetailreq addattributemappingsfromdictionary:@{ @"type" : @"type" }]; [paymentdetailreq addpropertymapping: [rkrelationshipmapping relationshipmappingfromkeypath:@"paymentoptions" tokeypath:@"paymentoptions" withmapping:paymentoptionmapping]]; rkrequestdescriptor* requestdes = [rkrequestdescriptor requestdescriptorwithmapping:paymentdetailreq objectclass:[ctspaymentdetailupdate class] rootkeypath:nil method:[self gethttpmethodfor:put]]; [objectmanager addrequestdescriptor:requestdes];

once utilize next set object server

[objectmanager putobject:object path:path parameters:queryparams success:^(rkobjectrequestoperation* operation, rkmappingresult* mappingresult) { //code } failure:^(rkobjectrequestoperation* operation, nserror* error) { //code }];

i nsunknownkeyexception on line 2014-06-22 11:12:22.587 restfulltester[1727:60b] *** terminating app due uncaught exception 'nsunknownkeyexception', reason: '[<ctspaymentoption 0x10bf2ae80> valueforundefinedkey:]: class not key value coding-compliant key owner.'

i think there wrong the way have made mapping not able understand,also there way test json code produce beforehand

this line:

withmapping:paymentoptionmapping]];

when creating relationship mapping should be:

withmapping:[paymentoptionmapping inversemapping]]];

json restkit restkit-0.20