Posts

compiler construction - Adding the inreg attribute to LLVM IR function parameters -

i'm working llvm , want recreate piece of ir api: declare void @fun(i32* inreg, i32 inreg) but can't seem it. my current attempt is: function* fun = cast<function>(m.getorinsertfunction("fun",type)); ((fun -> getattributes()).getparamattributes(0)).addattribute(c,0,attribute::inreg); ((fun -> getattributes()).getparamattributes(1)).addattribute(c,0,attribute::inreg); this code literally doesn't after line 1, lines 2 , 3 ignored , in ir output is: declare void @fun(i32* , i32 ) how work correctly? managing function attributes in llvm quite inconvenient attributes packed immutable , global sets. assigning attribute function argument means replacing set representing function , argument attributes new one. fortunately, there @ least helper functions makes job bit easier. suggest using llvm::function::addattribute() method. function* fun = cast<function>(m.getorinsertfunction("fun", type)); fun->addattrib...

c++ empty queue initialization isn't empty in Qt creator -

so queue not empty , there random number of elements filled in. reason why program crashes if try push element onto queue. output cerr statements in calculator.cpp : 0 12163576194217602005 calculator.cpp: void calculator::insertzero(){ cerr << input.empty(); cerr << input.size(); //input.push(0.00); } calculator.hpp: #ifndef calculator_h #define calculator_h #include <qstring> #include "widget.h" #include "ui_widget.h" #include <queue> #include <iostream> /* * class holds declarations of calculator. */ using namespace std; class calculator{ private: queue<double> input; queue<double> result; qstring display; public: //numbers void insertzero(); }; #endif // calculator_h widget.h: #ifndef widget_h #define widget_h #include <qwidget> #include <qstring> #include <qpushbutton> #include <qlabel> #i...

mongodb - MongoEngine - How to deference a List Field efficiently when converting to json -

class parent(document): name = stringfield() children = listfield(referencefield('child')) class child(document): name = stringfield() parents = listfield(referencefield(parent)) @app.route('/home/') def home(): parents = parent.objects.all() return render_template('home.html', items=parents) i have 2 collections similar above, maintain many many relationship. in template angular, i'm setting javascript variable list of parents so: $scope.items = {{ parents|tojson }}; this results in array of parents who'se chilren array of object ids (references), opposed dereferenced child objects: $scope.items = [{'$oid': '123', 'name': 'foo', 'children': [{'$oid': '456'}]}]; i want angular object contain of dereferenced children. there efficient way this? so far, approach works me, @ o(n^3). i've minimized list comprehensions clarity. multiple obj['_id']...

javascript - Starting with AngularJS using a ng-controller directive -

i'm trying make simple exercise doesn't work. think don't call controller variable appropriately. blocked. how can fix code? result page show me: {{dish.name}} {{dish.label}} {{dish.price | currency}} <html lang="en" ng-app="a"> <head>.... </head> <body> <div class="container"> <div class="row row-content" ng-controller="dishdetailcontroller dishdc"> <div class="col-xs-12"> <p>put dish details here</p> <div class="media-body"> <ul class="media-list"> <li class="media" ng-repeat="dish in dishdc.dishes"> <div class="media-left media-middle"> <a href="#"> <img class="media-object img-thumbnail" ...

winforms - Notification icon transparency issues when dragging -

Image
i have winforms app, major component of icon down in notification area. i've noticed if drag icon (to reorder it, or move to/from list of icons hidden windows) transparent pixels not respected correctly, unlike other icons. this illustrated in animation below; other icons ok when dragged, icon (the red circle) not (excuse animation's compression artefacts). looking @ more closely, icon looks this: looks when dragged: a notifyicon control used, , icon generated dynamically in various colours , different numbers overlaid. in order maintain translucency around edges of icon, png format used (using code sample codeproject ) take bitmap , return icon used notifyicon : private static readonly byte[] _pngiconheader = { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; using (var bmp = new bitmap(image, new size(image.width, image.height))) { byte[] png; using (var ms = new memorystream()) { bmp.save(ms, imageformat.png)...

c++ - Assinging pointer to string variable fails -

match give_word( const vector< vector<string> > * source_words, const vector< vector<string> > * target_words, ...) { string synonym1, synonym2; ... // choose synonyms (if available) synonym1=source_words[index][rand()%source_words[index].size()]; synonym2=target_words[index][rand()%target_words[index].size()]; ... i've made technical decision pass vector-in-vector objects pointers because don't want them copied , passed function. it's because vectors hold more 1000 strings. but don't understand why compile error @ 2 lines assignment sign (=) synonym1=source_words[index][rand()%source_words[index].size()]; synonym2=target_words[index][rand()%target_words[index].size()]; it says this: no operator "=" matches these operands synonym1 = source_words[index][rand() % source_words[index].size()]; synonym2 = target_words[index][rand() % target_words[index].size()]; would valid code if used...

java - Mock: when() requires an argument which has to be 'a method call on a mock' -

i writing unit tests rest-api , have problems entities creation mocking. don't know how can mock entitymanager. tried example below got error. my controllertest: public class mcontrollertest { private mockmvc mockmvc; @injectmocks a; @injectmocks b b; @injectmocks acontroller acontroller; @injectmocks private aserviceimpl aserviceimpl; @autowired webapplicationcontext webapplicationcontext; @autowired private filterchainproxy springsecurityfilterchain; @autowired @injectmocks private entitymanagerfactory entitymanagerfactory; @before public void setup() { mockitoannotations.initmocks(this); mockmvc = mockmvcbuilders.webappcontextsetup(webapplicationcontext) .addfilter(springsecurityfilterchain) .build(); } @test public void postatest() throws exception { a.setdddd("xxx"); entitymanagerfactory entitym...

c# - Deserializing .NET Dictionary using ISerializable -

i have problems getting de-/serialization of dictionary working when implementing iserializable in enclosing class. seems able automatically de-/serialize if apply serializableattribute. need check deserialized dictionary in process however, need iserializable working. i set little test sure wasn't due other problems. test class looks this: [serializable] class test : iserializable { private dictionary<string, int> _dict; public test() { var r = new random(); _dict = new dictionary<string, int>() { { "one", r.next(10) }, { "two", r.next(10) }, { "thr", r.next(10) }, { "fou", r.next(10) }, { "fiv", r.next(10) } }; } protected test(serializationinfo info, streamingcontext context) { // here _dict.count == 0 // found dictionary no content? _dict = (dictionary<string, int...

php - How to get the column name of the cell which returned by result::fetch_row if I use foreach on it? -

i have created simple php code print result of mysqli query no matter query , how many columns , rows in there. simplified php code is: $result = $mysqli->query ($query); while ($row = $result->fetch_row()) { if ($row["status"] == "0") continue; foreach ($row $cell) { echo $cell; } echo "\n"; } now want omit column (ex: column named "status") printed, have include column "status" in query because need check "status" value determine whether if entire row printed or not (the check little more complicated , it's impractical on query itself). if row printed, don't want column "status" printed along in table. have no means know whether $cell inside foreach named "status" or not, , have several other columns have similar value "status" can't check based on value either. how can this? i've read on php mysqli::fetch_row() manual doesn't seem each of $ce...

c++ - g++ - Finding appopriate Windows libraries to link so as to compile FANN library -

for various reasons have been trying compile fann library myself. i'm on windows 10 mingw. keep things simple going start with: g++ mushroom.c -o shroom.exe -lm -i src\ -i src\include\ src\doublefann.c ( mushroom.c includes <stdio.h> , "fann.h" .) using -i src\ -i src\include\ src\doublefann.c allowed me rid of various undefined reference errors resulting header files not being found, keeps throwing following undefined reference: doublefann.c:(.text+0x4ee9): undefined reference gettickcount() fyi, appears in fann.h (line 54): /* compat_time replacement */ #ifndef _win32 #include <sys/time.h> #else /* _win32 */ #if !defined(_msc_extensions) && !defined(_inc_windows) extern unsigned long __stdcall gettickcount(void); in short, seems error linking windows libraries, , don't know how proceed find relevant ones link. here full fann.h , full doublefann.c disclaimers , notes edit: since going bed last night, refine...

Silex Setting Middleware to a ControllerCollection -

i want this: $app->mount('dashboard', new travel\controllers\dashboard())->before(function() use ($app) { //check if logued... }) is possible? thanks! you can $controllers = $app["controllers_factory"]; $controllers->before(function(request $request){}); in controllerproviderinterface::connect method if need function defined in $app definition php file can create protected function $app['callback'] = $app->protect(function(){}); then $controllers->before($app["callback"]);

Makefile: read input variable and set several variables -

i have makefile want read file name input , make other names based on it`s name. have tried following code mlext = .ml testext = test.ml nativeext = test.native test: @read -p "enter file name: " file; \ echo $$file$(mlext); \ echo $$file$(testext); \ echo $$file$(nativeext) for example: if type: foo then want foo.ml , footest.ml , footest.native however, can foo.ml . rest 2 .ml , .native how can fix this? first, let see exact recipe given shell removing @ in makefile: read -p "enter file name: " file; \ echo $file.ml; \ echo $filetest.ml; \ echo $filetest.native; the issue content of $(testext) gets appended $$file , creating shell variable $filetest , (very probably) not exist, resulting in empty string in end. not occur $(mlext) , initial dot cannot part of variable name. to overcome this, use $${file} instead of $$file in makefile rule.

java - How to bring JLabels in GridBagConstrains at top -

Image
i trying code, , reason, appears in middle. here's code: string errormsg = "something went wrong."; final string title = "wall game"; this.setsize(400, 500); //sets screen this.setdefaultcloseoperation(jframe.exit_on_close); this.settitle(title); this.setvisible(true); this.setsize(401,501); try { font font1 = new font("comic sans ms", font.bold, 15); jpanel panel1 = new jpanel(new gridbaglayout()); //makes panels jlabel label1 = new jlabel("welcome wall game!"); //labels jlabel label2 = new jlabel("click button read instructions!"); jbutton button1 = new jbutton("start");//buttons button1.settext("start!"); label1.setfont(font1); button1.setlayout(new boxlayout(button1, boxlayout.y_axis)); gridbagconstraints gbc = new gridbagconstraints(); gbc.insets = new insets(15,10,10,10); gbc...

php - How to preg_match all style tags? -

this question has answer here: how parse , process html/xml in php? 27 answers regex match open tags except xhtml self-contained tags 35 answers how safe match all <style> blocks in body using preg_match_all()? google not friend today. $haystack = '<body> <style> .class { foo: bar; } </style> <p>hello world</p> <style> /* comment <p> */ .class > p { this: that; } </style> <p>some html</p> </body>'; preg_match_all('#<style>([^<]+)#is', $haystack, $matches, preg_set_order); var_dump($matches); preg_match_all('#<style>(.*)</style>#is', $haystack, $matches, preg_set_order); var_dump($matches); did not work, matched < in style comment. reg...

arrays - C program skipping over user input? -

i'm making program takes input user of how many numbers want in array , numbers in arrays compare 2 find unions in intersections. i have written reason after user inputs how many numbers want , numbers first array(a), skips entire user input second array(b). the computations union , intersection correct(not shown) can't figure out i'm missing. i'm quite new @ c there minor issue i'm missing. thanks help! int main(void){ int i, j, x, y; int elema, elemb; int a[10] = {0}; int b[10] = {0}; // prompts user enter amount of numbers in array // asks user enter values (0-9) inputted. printf("enter number of elements in set a: \n"); scanf("%d", &elema); printf("enter %d number(s) set a: \n", elema); scanf("%d", &x); if(x < 10) a[x]=1; // sets index in array 1 if //corresponding number has been inputted // prompts user enter ...

php - naming Laravel events, listeners and Jobs -

i have event called userwasregistered have listener called userwasregistered there intned develop job commands called: emailregistrationconfirmation notifyadminsnewregistration createnewbillingaccount all these jobs executed within userwasregistered event listener class. is correct approach or should have multiple listeners userwasregistered ? feel using jobs approach enabled me call "jobs" other areas in application @ different times. e.g. calling createnewbillingaccount might called if user changed details...? i recommend change listener names that's more explicit what's happening, i'd avoid directly pairing listeners events. we're using anemic event/listener approach, listeners pass actual task "doers" (jobs, services, name it). this example taken real system: app/providers/eventserviceprovider.php : orderwaspaid::class => [ provideaccesstoproduct::class, startsubscription::class, ...

How do I store information about a many-to-many relationship without the concept of a join table in Firebase? -

my firebase app contains many-to-many relationship between groups , users. i'd store information when user joined group - how go without concept of join table? i'm using firebase example reference: https://examples-k9xbyc0bhfwtlkdgfhs.firebaseio-demo.com/ do recommend doing this? app: { groups: { group1: { members: { user1: { joindate: '2016-01-22t02:43:27.817z', iscreator: true }, user2: { joindate: '2016-01-23t02:43:27.817z', iscreator: false } } } }, users: { user1: { firstname: 'adam', lastname: 'soffer', groups: { group1: { joindate: '2016-01-22t02:43:27.817z', iscreator: true } } }, user2: { firstname: 'joe', lastname: 'shmoe', groups: { group1: { joindate: '2016-01-23t02:43:27.817z', i...

VB.net mySQL How to use DateAdd in sql query -

i'm getting error when form load , said function databasename.dateadd not exist con.open() cmd.connection = con cmd.commandtext = "update pawn set status = 'renewed', date_added = dateadd(month,4,date_added), first_date = dateadd(month,5,first_date), second_date = dateadd(month,6,second_date), due_date = dateadd(month,7,due_date)" dr = cmd.executereader con.close() you've used vb.net's dateadd() inside query won't work mysql because mysql doesn't has inbuilt function syntax mysql date add function date_add(date,interval expr type) cmd.commandtext = "update pawn set status = 'renewed' " & _ ",date_added = date_add(date_added,interval 4 month)" & _ ",first_date = date_add(first_date,interval 5 month)" & _ ",second_date = date_add(second_date,interval 6 month)" & _ ",due_date =...

App crashes despite handling Android M GPS permission -

i have been using android m model time now, manually revoked permissions location , storage in mobile settings see whether app ask user again permissions @ run time. since then, been crashing. please have @ code- public class mapsactivity extends fragmentactivity implements com.google.android.gms.location.locationlistener, googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener { string[] perms={"android.permission.access_fine_location","android.permission.write_external_storage"}; int permsrequestcode = 200; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); mgeofences = new arraylist<geofence>(); mgeofencecoordinates = new arraylist<latlng>(); // double string0=prefencesettings.getstring("latlng0", "34"); setcontentview(r.layout.activity_maps); showhelpforfirstlaunch(); supportm...

Vertical dotted line in between a column in html table -

Image
i have created html table shown below: now want draw vertical dotted line in between column in table. see can me this? here code row 1 : #myprogress { height: 20px; position: relative; border: 1px solid #ccc; background-color: #4675a1; display: inline-block; } <tr> <td align="center">1</td> <td>2014-03-05</td> <td>2014-03-05-m01117</td> <td><div class="col-xs-3">32</div></td> <td><div class="col-xs-4"><div style="width: 200px;"><div id="myprogress" style="width:10%"> </div> </div></div></td> <td>78.3</td> </tr> do check below html , css add vertical line in html table .myprogress { height: 20px; position: relative; border: 1px solid #ccc; background-color: #4675a1; display: inline-block; } .borde...