Posts

php - how can i use relationship in laravel? -

my schema follows: channel table: id int unsigned primary key auto increment, name varchar(30) not null, ... category table: id int unsigned primary key auto increment, channel_id int unsigned index, name varchar(30) not null, ... article table: id int unsigned primary key auto increment, category_id int unsigned index, title varchar(90) not null, content text not null, ... so, every article belong specific category , category belongs specific channel. my question is: how can search articles category name , channel name (the relationship ready in code)? i have tried $articles = app\article::latest()->with('category')->with('channel')->get(); but not work, can me? thank time. if want search through related tables should use joins this: $articles = app\article::latest() ->select('article.*') ->join('category', 'category.id', '=', 'category_id') ->join('channel', ...

html - Table alignment with div -

i trying construct html table 6 rows. first row has 1 line of text heading. second row has 3 columns (set 3 td elements). third row has 3 values in 3 columns (set 3 td elements). 4th row has 3 images in 3 columns (again set 3 td elements). works correctly far. want add fifth row line of text spans entire div , has dotted underline. when add element draws the dotted border 1/3rd of div only. if set width 100%, elements above dragged right of screen. doing wrong? here complete html snippet: <div id="toysummary" style="border:solid; border-width:4px; border-color:gray; padding:4px; margin:10px"> <span style="font-family:calibri; font-size:large; color:midnightblue; text-align:right"><b>final results summary</b></span> <table style="width:100%"> <tr> <td style="width:33%; font-size:large"><i>result</i></td> <td style="width:33%; ...

numpy - Order of repetition per row and column in Python -

i have been trying figure order of repetition per-row , couldn't it. ok. lets consider ndarray of size (2, 11, 10) a = np.array([ [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 1, 1, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0, 1, 0], [1, 1, 0, 0, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 0, 0, 1, 0, 1, 1, 1, 0, 0], [1, 1, 0, 1, 1, 0, 1, 1, 0, 0], [0, 1, 1, 1, 0, 0, 1, 1, 0, 1], [1, 1, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 1, 0, 0, 1, 1], [0, 1, 1, 1, 0, 0, 1, 1, 0, 1] ], [ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 1, 1], [0, 1, 0, 1, 0, 0, 0, 1, 0, 0], [1, 1, 0, 1, 0, 1, 1, 1, 0, 0], [1, 1, 0, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 1, 1, 0, 0], [1, 0, 0, 0, 1, 1, 0, 0, 1, 1], [1, 1, 1, 0, 0, 1, 1, 1, 0, 1], [1, 0, 0, 1, 1, 0, 1, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0], ...

ios - How to optimize CPU and RAM usage on a UIView which uses `drawInRect:blendMode:`? -

i'm developing drawing app lets user draw 1 uibezierpath once on image has been drawn in uiview drawinrect:blendmode in drawrect method , it's uses on 80% of cpu , 55mb of ram , when traced down in time profiler, drawinrect:blendmode method causing of cpu usage. have done few optimizations further optimizations can both drawing uiimage being drawn using [image drawinrect:rect]; , uibezierpath user draws on top of it? in advance. @interface insideview(){ cgrect imagerect; cgrect targetbounds; } @property (strong, nonatomic) nsmutablearray *strokes; @property (nonatomic, strong) uiimage * img; @property (nonatomic, strong) uibezierpath *drawingpath; @end @implementation insideview -(void)drawrect:(cgrect)rect{ targetbounds = self.layer.bounds; imagerect = avmakerectwithaspectratioinsiderect(self.img.size,targetbounds); [self.img drawinrect:imagerect]; (int i=0; < [self.strokes count]; i++) { uibezierpath* tmp = (uibezierpath*)[self...

scipy - Calling MKL from Python : DSTEVR -

dstevr computes eigensolutions of triangular symmetric matrix. cool. except not 1 of routines ported wrapper scipy. i've followed instructions on how call mkl directly python , attached seems give correct answer. gosh.... there someway clean up?! import numpy np scipy import linalg ctypes import * c_double_p = pointer(c_double) c_int_p = pointer(c_int) c_char_p = pointer(c_char) mkl = cdll('mkl_rt.dll') dstevr = mkl.dstevr #subroutine dstevr( jobz, range, n, d, e, vl, vu, il, iu, abstol, m, # * w, z, ldz, isuppz, work, lwork, iwork, liwork, info) # character * 1 jobz, range # integer n, il, iu, m, ldz, lwork, liwork, info # integer isuppz(*), iwork(*) # double precision vl, vu, abstol # double precision d(*), e(*), w(*), z(ldz,*), work(*) dstevr.argtypes = [ c_char_p, c_char_p, c_int_p, c_double_p, c_double_p, c_double_p, c_double_p, c_int_p, c_int_p, c_double_p, \ c_int_p, c_double_p, c_double_p, c_int_p, c_int_p, ...

amazon web services - How do I log event and context information automatically on AWS Lambda function failures? -

i trying log lambda function failures in such way event , context information saved event information can, if deemed necessary, later manually republished function's trigger. not want handle logic in functions themselves. what i've tried far: cloudwatch alarms on error metric. tell me function has failed. looking in cloudwatch logs. see coded failure messages emitted each function. there no such setting, if that's you're looking for. if you'd these properties logged, have print them - way visible in cloudwatch , whatever service logs piped (logs can piped elasticsearch example, cloudwatch ). however, can done adding these 2 lines of code: exports.handler = (event, context, callback) => { console.log(json.stringify(event)); console.log(json.stringify(context)); // code }; as rule of thumb, logs way describing lambda went through @ each invocation.

algorithm - Reversing Alternate Levels of a perfect binary tree -

the problem statement is: given perfect binary tree, reverse alternate level nodes of binary tree. given tree: / \ b c / \ / \ d e f g / \ / \ / \ / \ h j k l m n o modified tree: / \ c b / \ / \ d e f g / \ / \ / \ / \ o n m l k j h solution 3 this site provides particularly elegant solution in uses swap method on nodes of numbered levels of tree:void preorder(struct node *root1, struct node* root2, int lvl) { // base cases if (root1 == null || root2==null) return; // swap subtrees if level if (lvl%2 == 0) swap(root1->key, root2->key); // recur left , right subtrees (note : left of root1 // passed , right of root2 in first call , opposite // in second call. preorder(root1->left, root2->right, lvl+1); ...