Posts

Showing posts from February, 2012

Python Program Freezes computer -

i have been programming in python little while now, , decided teach friend well. asked him make method return list of factors of number, gave me script little inefficient still looked should have worked me. when run program freezes both , computer (i have top of line gaming pc don't think using many resources). showed him how fix it, still cannot pinpoint causing problem. here code, time! def factors(numb): facs = [] in range(1,int(numb // 2)): if numb % == 0: facs.append(i) in facs: facs.append((numb / i)) return facs.sort() p.s. never throws error, after having been let run while. in python 3.4 the problem in fragment: for in facs: facs.append((numb / i)) you have self-incrementing sequence here.

tsql - SQL server random row for each unique result in column -

i have table contains multiple colleague names , sales transactions. @ end of day colleague may have had 100 sale records, need pick 1 @ random each colleague for example if there 100 colleagues working day result give 1 random record each colleague, returning 100 in total i have looked @ newid() can't figure out how return 1 record per colleague you can try this: with summary ( select o.id, o.client, o.ammount, row_number() over(partition o.id order newid()) rn orders o) select s.* summary s s.rn = 1

arrays - Swift count string size in for loop -

for homework assignment have convert sentence user has typed in 3 different ways. convert letters uppercase(completed) convert letters lowercase(completed) convert uppercase letters lowercase , vice versa(having trouble) i believe logic correct don't know wrong. this code: // // viewcontroller.swift // lower upper converter // // created mac user on 9/27/15. // copyright © 2015 omid nassir. rights reserved. // import uikit class viewcontroller: uiviewcontroller { private var input = "" private var = 0 var sentense = [string]() //var sentensechar: [character] = [] //input fields @iboutlet weak var input1: uitextfield! @iboutlet weak var input2: uitextfield! //caps button @ibaction func capsbtn(sender: anyobject) { if input1.text != nil { input = input1.text!.uppercasestring input2.text = input } else { input2.text = "" ...

c# - Application Insights Exceptions and Failures -

Image
i'm trying work application insights in azure preview portal , visual studio 2015 community edition. i'm encountering 3 different problems suspect related. i'm wondering if others encountering these issues. in 1 of test web applications, app-insight tool partially working. in i'm getting errors concerning irretrievable data. in third, i'm running deployment failures when use app-insight resources in new resource group. i present 3 in question, because suspect may have same root cause. partial results the first app tried retrofit app-insight work , display app-insight telemetry...or @ least works. half telemetry data shows, , rest not make it. the sequence of setting follows: i started installing sample mobile-mvc app came msdn magazine article , june 2015. after fiddling around adding bootstrap make responsive pages, decided commit code vs online git , deploy azure web app. i followed instructions view logs in application insights , ran a...

SSRS: Trouble understanding Grouping in Report -

i have relatively simple report 'working'. has main group based on expression - 1 sort in group - , 'group' named 'details' under in row groups pane. the main group repeating no reason can figure. expect if there group called 'a' - detail rows in group display till next group - right? like this: a bob 1 texas jane 2 california devin 4 new york b jack 3 texas mary 6 maine peter 5 michigan c . . . instead, report doing this: a bob 1 texas jane 2 california devin 4 new york b jack 3 texas b mary 6 maine peter 5 michigan c . . . if delete details group lose data & report goes 5 pages [57 detail recs] 2 pages. if delete main group - go down 1 record in entire report. i need keep data on report - have group correctly main group [without repeats of group header] , within each group - sort couple of different fields. any idea how should go troubleshooting issue? ...

iphone - Screen scale/size is right in iOS 8 but wrong in iOS 9 on same device -

Image
i've updated xcode 7 start developing against ios 9. upon first launching application, noticed screen size/scale off compared how looks on ios 8, both on iphone 6 device. here how looks correct on ios 8: here how looks incorrect on ios 9: if notice, both of images same exact size. note how admob banner has white space on left/right, i'm assuming admob knows center it. big white space right of table view , button down on bottom. also, when in ios 8, , putting break point in main delegate method, main window has frame of (0 0; 320 568). layer on window same. on flip side, when in ios 9, , putting break point in main delegate method, main window has frame of (0 0; 375 667). layer on window same. that explains why difference in of app in ios 8 vs. ios 9, not know why ios 8 looks way want , ios 9 doesn't. there setting i'm missing? edit: i've since figured out bounds of mainscreen different between when runs in ios 8 vs. ios 9. screenbound...

ajax - API web site for forms-based data for all the countries, states and cities of the world -

good day all. i making application have list on form, countries, states , provinces, cities, , made me quite laborious having manually add these. my questions are: they know online application allows me list api countries, states , provinces, cities, , give me option integrate them form , bring information dynamically through ajax. it more advisable have information in database or work online service through api. having site allows ahcer this, recommended , easy integrate. much appreciate support. are talking ? https://restcountries.eu/ i have not used service personally.

url routing - Symfony CMF RoutingBundle - PHPCR Route Document - Multiple Parameters -

tried find solution, got stuck docs or @ answers include other bundles. in documentation of dynamic router can find hint: "of course can have several parameters, normal symfony routes. semantics , rules patterns, defaults , requirements same in core routes." thats it. ... /foo/{id}/bar i tried (seems not) done. same tries: i tried apply variable pattern , child route. use symfony\cmf\bundle\routingbundle\doctrine\phpcr\route phpcrroute; $dm = $this->get('cmf_routing.route_provider'); $route = new phpcrroute(); $route->setposition( $dm->find( null, '/cms/routes' ), 'foo' ); $route->setvariablepattern('/{id}'); $dm->persist( $route ); $child = new phpcrroute(); $child->setposition( $route, 'bar' ); $dm->persist( $child ); $dm->flush(); with or without default value , requirement '/foo/bar' , '/foo/*' return matches, '/foo/1/bar' prompts me 'no route found...

r - Adding a scatterplot to a coefficient plot in ggplot -

Image
i trying create coefficient plot scatterplot of data points laid overtop of it. portion of data listed below: print(dat) lower upper mode condition obsmean p100 p102 p103 p104 p105 ob.h.black.650 0.693595 0.950305 0.8849853 h.black.650 0.8122302 0.85 1.00 0.85 0.85 0.85 ob.h.white.650 0.649625 0.930375 0.8306119 h.white.650 0.7852518 0.70 0.95 0.80 0.80 0.90 ob.h.black.800 0.833255 0.993105 0.9701335 h.black.800 0.9035971 0.95 1.00 0.95 0.95 1.00 ob.h.white.800 0.802110 0.983230 0.9469604 h.white.800 0.8762590 0.95 0.95 0.80 1.00 0.85 ob.h.black.950 0.869375 0.995800 0.9804180 h.black.950 0.9165468 0.90 1.00 0.85 1.00 1.00 ob.h.white.950 0.862895 0.991750 0.9694811 h.white.950 0.9046763 1.00 1.00 0.95 1.00 0.90 ob.h.black.1100 0.879340 0.996550 0.9885382 h.black.1100 0.9323741 1.00 1.00 0.90 0.75 0.85 ob.h.white.1100 0.853110 0.994405 0.9773240 h.white.1100 0.9140288 0.95 0.95 1.00 0.90 0.90 my code produces output shown below: ggp...

amazon web services - AWS Javascript Uploading Multiple Files with progress reported -

scenerio.... i'm trying upload number of files aws through javascript api. while number of files may many (100 - 500), managing first sending file information web server (via ajax) parse name, size, etc... , insert information database. return id of newly created record web page , send file s3 using 'id' file name. way, believe creating unique records , file names. problem... since ajax routine in loop, file upload s3. cannot script give me valuable feedback on upload progress (the upload works fine). any of following make me happy... a div total upload size (all files) , total progress reported. a list of files being uploaded totals , amounts loaded. a div reports "20 out of 520 files loaded" my code... var aj = $.ajax({ url: 'handler.php', type: 'post', data: { packnameid: packnameid, number: number, name: name }, succe...

javascript - How to expand all nodes that has a children on page load by default in wix angular tree control -

has tried expand nodes has children on page load default in tree created angular tree control. packed lots of features lacks one. having expanded nodes property. need find array of nodes has children other logic , has pass same expanded nodes? correct logic or missing inbuilt functionality in directive? please help http://wix.github.io/angular-tree-control/ in order load nodes expanded, have create list of node objects should expanded default , pass expanded-nodes attribute in html controller script as: $scope.dataforthetree = [{ text: "data sources", children: [{ text: "hard drive health", children: [] }] }, { text: "diagrams", children: [{ text: "hard drive failure example", children: [] }] }]; $scope.expandednodes = [vm.dataforthetree[0],vm.dataforthetree[1]]; html element as: <treecontrol class="tree...

python - Piecewise function not working -

i defined piecewise function : def c1(d,x): if ((x<d/2) , (x>-d/2)): return (1/d) else: return 0 but return me 0 in [23]: c1(1000,1) out[23]: 0 in python, division sign operator (/) performs integer division, meaning decimal points truncated, if numerator , denominator both integers. when (1/d), both 1 , d integers does, example, 1/1000 0.001 in integer division lose decimal instead 0. fix this, make of defined numbers floats adding .0. example, (x < d/2.0), , (x > -d/2.0) , (1.0/d) should give proper results.

Change background to random colors on click - Javascript/jQuery -

i'm trying change body's background color random color every time nav-bar link clicked. i got random color gets changed first time link clicked - when different link clicked, nothing changes. any tips? html: <div class="nav"> <ul id="show"> <li id="link1"><a href="#portfolio">portfolio</li></a> <li id="link2"><a href="#about">about</li></a> <li id="link3"><a href="#email">contact</li></a> <hr/> </ul> </div> js: $(function() { var colors = ['red', 'blue', 'green', 'grey']; var randcolor = colors[math.floor(math.random()*colors.length)]; $('.nav a').click(function() { $('body').css('background-color', randcolor); }); }); because generate 1...

How do I change the timeout for PHP ApaiIO Amazon library? -

how change timeout amazon product library php client? searched code timeout , it's not obvious how pass different timeout value. https://github.com/exeu/apai-io/search?utf8=%e2%9c%93&q=timeout based on link provided, there no way pass in parameter timeout. can see it's hardcoded right there in constructor. can extend class , re-write constructor this. call erequest instead of request . you can see $options private, know it's not being edited elsewhere , simple ctrl-f can tell it's not being changed anywhere else in class, these options changing it. class erequest extends request{ __construct(array $options = array(), $timeout=10){ $this->options = array( self::useragent => "apaiio [" . apaiio::version . "]", self::connection_timeout => $timeout, self::timeout => $timeout, self::follow_location => 1 ); $this->set...

Android Listview item Partially Visible -

i created custom listview adapter viewholder , used listfragment, reason dont know, last listview item not render totally adapter code public class listviewadapter extends arrayadapter<listitem> { public listviewadapter(context context, list<listitem> items) { super(context, r.layout.row, items); } @override public view getview(int position, view convertview, viewgroup parent) { viewholder viewholder; if(convertview == null) { layoutinflater inflater = layoutinflater.from(getcontext()); viewholder = new viewholder(); viewholder.ivicon = (imageview) convertview.findviewbyid(r.id.ivicon); viewholder.tvtitle = (textview) convertview.findviewbyid(r.id.tvtitle); viewholder.tvdescription = (textview) convertview.findviewbyid(r.id.tvdescription); convertview.settag(viewholder); } else { // recycle inflated view viewholder = (viewholder) convertview.gettag(); } ...

java - my program doesn't run completely -

for reason, program stops when reaches part asks user if know it's exam 1 score. need user able enter yes or no. why program stop? need work properly. have if-else statements. able enter percentage weights, program do. more must done. code extends far beyond entering percentage weights. please me. import java.util.scanner; public class gradecalculation { public static void main(string[] args) { // todo auto-generated method stub scanner grade = new scanner (system.in); // new scanner must created. scanner essential program performing properly. double = 90-100; double b = 80-89; double c = 70-79; double d = 60-69; double f = 0-59; string lettergrade; string yes; string no; double exam1, exam2, finalexam, labs, projects, attendance, quizzes; double exam1grade, exam2grade, finalexamgrade, labaverage, projectsaverage, attendanceaverage, quizzesaverage; d...

javascript - Reading from Page Albums to integrate website -

i have public website , have corresponding facebook page. restorations public website needs have images related each restoration. keep album each restoration within facebook , leverage same images instead of duplicating effort. use javascript sdk read albums page. can via graph api explorer /{pageid}/albums using token generator. however, users visiting public website should not prompted login facebook. there way can generate token allow me read , display images these albums without requiring them login? this want solve server-side, not client-side, because expose token publicly. if album public can generate app token server side , read images album using token.

python - Create a multivariate AR model in MATLAB -

i want create 2 vector time series in matlab, or python following. variances = 1 , 0.7 , respectively. x(t) = 0.9x(t − 1) − 0.5x(t − 2) + ε(t) y(t) = 0.8y (t − 1) − 0.5y (t − 2) + 0.16x(t − 1) − 0.2x(t − 2) + η(t) how go doing this... know x(t), can code following in matlab: xmodel = arima('constant', 0, 'ar', {0.9, -0.5}, 'variance', 0.1); x = simulate(xmodel, 500); can provide insight how y(t) in both matlab and/or python. thank you! in matlab can use arima beta property account additional regression coefficients: ymodel = arima('constant',0,'ar',{0.8,-0.5},'beta',[0.16,-0.2],'variance',0.7) ymodel = arimax(2,0,0) model: --------------------- distribution: name = 'gaussian' p: 2 d: 0 q: 0 constant: 0 ar: {0.8 -0.5} @ lags [1 2] sar: {} ma: {} sma: {} beta: [0.16 -...

c - address out of bounds about buffer overflow -

recently, trying use point clobbering utilize vulnerability of xp vm. thing that, has changed address function pointed to function address(in case function arc injection(r)), when program jump function "arc injection(r)", gdb tells me r address 0xbalbala out of bounds? kind of known may relate scope of variable. can 1 tell me how can use point clobbering jump function , use argument? thank much. void arcinjection(char *r) { printf("in arcinjection()\n"); system(r); } void (*funcptr)(int,int, char **); here part of switch: case 5: arcinjection(command); break; case 6: funcptr(argv[++i][0]-48,argc,argv); // changed address function pointed to address of case 5, in case case 5 cannot use argument command, has been defined in main program.

c# - Update and Delete from DataGridView not functioning -

i have datagridview displays 3 rows, when try update records says changed records. when check database records not updated. and in delete button says must select record delete selected row in datagridview using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.data.sql; using system.data.sqlclient; namespace rfg_inventory_and_management_system { public partial class adminform : form { sqlcommand cmd; sqlconnection con = new sqlconnection(@"data source=.\sqlexpress;attachdbfilename=c:\users\acer\documents\visual studio 2010\projects\rfg inventory , management system\rfg inventory , management system\database1.mdf;integrated security=true;user instance=true"); sqlcommandbuilder cmdbl; sqldataadapter adap; dataset ds; int id = 0; public adminform() { ...

reactjs - React.js how to return commented video tag for ie9 support -

let's in react want support ie9 wrapping code, example picturefill does: <picture> <!--[if ie 9]><video style="display: none;"><![endif]--> <source srcset="examples/images/extralarge.jpg" media="(min-width: 1000px)"> <source srcset="examples/images/large.jpg" media="(min-width: 800px)"> <!--[if ie 9]></video><![endif]--> <img srcset="examples/images/medium.jpg" alt="…"> </picture> in react, be: return ( <picture> <!--[if ie 9]><video style="display: none;"><![endif]--> <source type="image/webp" classname="full-photo2 slide-init" srcset={"./build/assets/images/photos/responsive/webp/" + image.id + "-400.webp 400w, ./build/assets/images/photos/responsive/webp/" + image.id + "-800.webp 800w, ./build/ass...

flash - How drag a Sprite smoothly on-screen in actionscript -

first of all, question same one: how drag image move smoothly on screen, actionscript? i want dragged sprites keep mouse on-screen, smoothly, without lagging behind. and notice in old actionscript 3 cookbook way-back-when used similar solution draggablesprite used in above link. namely, use stage instance listen mousemove event , read event.stagex , stagey properties. i've done that. but sprite still doesn't stay locked mouse cursor. lags behind. feel must missing something. however, if solution posted above (ie listen stage's mousemove , use event.stagex/y) still current , problem i'm describing should not occurring, please let me know. though it's not supposed work, i've tried event.updateafterevent() , doesn't seem have positive effect. any or advice appreciated. here's simple example of how i've written handlers. should work as-is if pasted new project. i should add i'm compiling desktop application using adobe air. run ti...

java - Sequence File in Spark - Read And Write Custom -

we had data pipeline earlier built on hadoop. trying port of our application spark. in our data pipeline had used sequence file op each stage , passed next stage. there custom classes written hadoop implements writable interface storing these data. if trying use in spark creating object of class , save sequence file getting errors like text/intwritable or other writable class not serializable. there way save sequence file in spark using these custom classes. the class present in java , don't want modify sample example public class abc implements writable,serializable{ private text requestid; private text requesttype; //constructor , other methods @override public void write(dataoutput out) throws ioexception { requestid.write(out); requesttype.write(out); } @override public void readfields(datainput in) throws ioexception { requestid.readfields(in); requesttype.readfields(in); } } its giving error...

print contributors to prediction in adaboost model built in R -

i have 'ada' model trained using r package ada, , gives predictions. > class(model) [1] "ada" > predict(model,testdata,type="prob")[,2] 0.54 however, given row in 'testdata', wondering if there way print out top contributors attributes, affected prediction. when print out model using modelname$model , bunch of numbers, i'm not sure of how make sense of it.

javascript - getting a method as a json data in angularjs and how to use it in html view -

i have been working on ui chart takes data json , show it.. json file job.json demo link hardcoded want dynamic getting data database json link { "days": [{ "dayname": "sun,23 aug 2015", "date": "2015-08-23", "hours": "hoursarray()" }, { "dayname": "mon,24 aug 2015", "date": "2015-08-24", "hours": "hoursarray()" }, { "dayname": "tue,25 aug 2015", "date": "2015-08-25", "hours": "hoursarray()" }, { "dayname": "wed,26 aug 2015", "date": "2015-08-26", "hours": "hoursarray()" }] in hoursarray() method while using in code expression not giving resu...

java - What is the most stylistically correct way to declare these variables? -

i new computer science , have written project uses lot of variables. have code in main method , @ beginning of main method, have of variables declared. think pretty ugly. don't want change around whole code , mess scope. there way declare these same variables , have more efficient/professional? int numplain; int numpepperoni; int pizzasordered = 0; int slicesordered = 0; int charmsordered = 0; int totalslices = 0; int totalcharms = 0; int totalplain = 0; int totalpepperoni = 0; double plaincost = 0.0; double pepperonicost = 0.0; double slicecost = 0.0; double piecost = 0.0; double charmcost = 0.0; boolean flag = true; double totalcost = 0.00; double paymentamt = 0.0; int numpies = 0; you could try inline of variable declarations/initializations this: int numplain, numpepperoni; int pizzasordered = 0, slicesordered = 0, charmsordered = 0; int totalslices = 0, totalcharms = 0, totalplain = 0, totalpepperoni = 0; double plaincost = 0.0, pepperonicost = 0.0, slice...

javascript - How to print directly in a HTML page using PHP? -

i'm developing billing software. can print receipt again click print button in print page printing for ex: i'm clicking print button in html page, next automatically open google chrome print window. and again click print button, now printing, want print directly. how remove 2nd , 3rd step via programmatic. how rectify problem help. <script type="text/javascript"> function printpage() { window.print(); } </script> i'm using above code output redirected google chrome print page. and again click print button printing, i want print directly for example click print button in html page means automatically printing. cannot ask inputs. and cannot display other dialog boxes. anyone me please. explaining am click print button in html page: yes have click on print button request browser perform action next automatically open google chrome print window: of course, opened printer/page settings asked in...

php - Where to set environment variables for Ubuntu running on Vagrant? -

i'm running php app on heroku, , have no issues retrieving environment variables heroku:config command, need have separate variables locally. i'm vagrant ssh-ing ubuntu, life of me can't figure out set variables. i've tried using ~/.bashrc , putting variables in provisioning script, can't $_env (or getenv() ) function in php retrieve variable. when call functions told variables not set in environment. any ideas how set environment variables in local environment php heroku app? i guess should work ~/.bashrc file might depend bash use. you can put env variables .profile example: export java_home=/library/java/javavirtualmachines/jdk1.8.0_51.jdk/contents/home you need user runs apache (if apache or nginx or other web server use) make sure add variables user runs apache (if apache or nginx or other web server use), not vagrant user. the difference heroku heroku user own process including web server variable define can accessed, standard ubun...

python - must build Spark with Hive (spark 1.5.0) -

downloaded spark 1.5.0 pre-built , run via pyspark simple code from pyspark.sql import row l = [('alice', 1)] sqlcontext.createdataframe(l).collect yields error: 15/09/30 06:48:48 info datastore: class "org.apache.hadoop.hive.metastore.model.mresourceuri" tagged "embedded-only" es not have own datastore table. traceback (most recent call last): file "<stdin>", line 1, in <module> file "c:\bigdata\spark-1.5\spark-1.5.0\python\pyspark\sql\context.py", line 408, in createdataframe jdf = self._ssql_ctx.applyschematopythonrdd(jrdd.rdd(), schema.json()) file "c:\bigdata\spark-1.5\spark-1.5.0\python\pyspark\sql\context.py", line 660, in _ssql_ctx "build/sbt assembly", e) exception: ("you must build spark hive. export 'spark_hive=true' , run build/sbt assembly", py4jjavaerror(u'an error occurred while calling none.org.apache.spark.sql.hive.hivecontext.\n', javaobje...

ios - Separate a String By Semicolon -

i using following code separate string multiple strings , getting error nsarray *arr = [randomstr componentsseparatedbystring:@";"]; error: -[__nsdictionarym componentsseparatedbystring:]: unrecognized selector sent instance 0x1758f230 -[__nsdictionarym componentsseparatedbystring:]: unrecognized selector sent instance 0x1758f230 this sample data nsarray *data = { { name = "name1"; address = "rwp"; id = 0; }, { name = "name2"; address = "rwp"; id = 1; }, { name = "name3"; address = "rwp"; id = 2; },} nsstring *randomstr = data[0]; what's wrong in code you have array of dictionaries, not strings. there nothing split. you want this: nsdictionary *dict = data[0]; nsstring *name = dict[@"name"]; nsstring *address = dict[@"address"];

lock free - LockFree MultiConsumer/MultiProducer Queue -

i've written simple lock-free single-consumer/-producer queue. it's supposed work this: at time many consumers may read it at time multiple producers can write it, added elements made available later after write modification finished, call "makepushedelementsavailable()", consumers can read newly added elements . template<typename t, int size> class mcmpqueue { public: mcmpqueue(); bool trypushlater(const t &element); bool trypop(t &element); void makepushedelementsavailable(); protected: private: t elements[size]; std::atomic<int> ihead, itail, iwrite; }; template<typename t, int size> mcmpqueue<t, size>::scmpqueue() : ihead(0), itail(0), iwrite(0) { } template<typename t, int size> void mcmpqueue<t, size>::makepushedelementsavailable() { itail.store(iwrite.load()); } template<typename t, int size> bool mcmpqueue<t, size>::trypop(t &element) { int newindex; ...

postgresql - Creating Grouped features in sql -

i have sample records particular trialid table below: personid trial orgid orgtypeid 90 106 72001 4 682 106 188787 4 717 106 187761 4 830 106 64776 4 845 106 71795 3 1130 106 215441 22 1199 106 25148 22 1488 106 84256 4 1656 106 31456 22 2427 106 71864 22 2535 106 40687 3 2558 106 93306 4 2792 106 114207 18 3105 106 13967 22 3267 106 22634 18 3352 106 22 3516 106 9847 12 3981 106 2341 4 3993 106 126593 3 4025 106 29789 4 4395 106 75068 3 ...

java - How can I sort an ArrayList of objects? -

i have , arraylist 2 strings , integer , need sort string name , string lastname , tried method collections.sort this collections.sort(myarraylist, (contact v1, contact v2) -> v1.getname().compareto(v2.getname())); but sorts arraylist names, , doesn't include last name, how can add sort last names? well need change comparison function include other fields this collections.sort(contacts, (contact c1, contact c2) -> { int firstnamecomparisonresult = c1.getfirstname().compareto(c2.getfirstname()); if (firstnamecomparisonresult != 0) { return firstnamecomparisonresult; } else { return c1.getlastname().compareto(c2.getlastname()); } }); warning: assumes there no nulls. full code used if want take look: class contact{ final string firstname; final string lastname; final int age; public string getfirstname() { return firstname; } public string getlastnam...