Posts

javascript - Assigning method to variable and problems with this -

i have piece of code: function a(){ this.count = 0; } a.prototype.inc = function(){ this.count++; } var = new a(); a.inc(); var f = a.inc; f(); the last line deosn't work expected, because this object of type window . something, shouldn't - assign methods variables, in case make use of this ? when want use method argument, should omit fn(a.inc) , use regular function, , use insted following? fn(function(){ a.inc(); }); this famous "lost binding" of javascript. you have do: f = a.inc.bind(a); because if say f = a.inc; f(); then when f running, this not bound a . bound global object, window . the rule is, if a.fn() , inside of function, this bound a , if fn() or g() , when g === a.fn , inside of function, this bound global object, window . to bind this explicitly a when function invoked, have use a.inc.bind(a) if don't want use bind want use own function, that's fine too. do: function fn() { a.in...

asp.net web api - Using Forms Authentication with WebAPI when the client is in a different domain? -

related question: authentication in .net web api using mvc formsauthentication i have client application lives outside of webapi solution's domain (right 2 different solutions on localhost - 1 on port x, other on port y). i'm attempting use forms authentication code this: if (websecurity.login(model.username, model.password, persistcookie: true)) { var response = request.createresponse(httpstatuscode.ok, "logged in successfully"); return response; } in postman works, using client / js application, cookie not saved, user never authenticated. see _requestverificationtoken, never .aspxauth token. a requirement of application use forms auth setting cookies using websecurity. possible when client , server on different domains? if there's else can provide make issue clearer, please let me know. assuming using cors. default, cookies not enabled cors. in jquery, need set xhrfields: { ...

PowerShell Setting up a folder to open in -

Image
my teacher gave me instruction : "to set-up default folder powershell open in, right click powershell icon in tool tray , select properties. in properties dialog box , in start in: text box enter path new directory “c:\users\administrator\myscripts”, click ok." however when go properties tab not see talking :( . this see: how i wants? your teacher asking change properties of executable . looking @ powershell console properties. as can partially see mine located: %systemroot%\system32\windowspowershell\v1.0\powershell.exe

unix - Checking if a returned number is an integer in GP/Pari? -

this first time using gp/pari , having trouble completing question. i asked print if return of function 'wq()' integer. there function can determine if number passed in integer? if not how go checking? find syntax difficult , can't find information online it. i have included have far, appreciated. wq(x) = { [(x-1)! + 1]/x } test(r,s) = { (i=r, s, if(isinteger(wq(i)), print("integer"), print("not interger"))); } if understand correctly want check if (x-1)! + 1 multiple of x . can modulo operation: test(r,s) = { (i=r, s, if(mod((i - 1)! + 1, i) == 0, print("integer"), print("not integer"))); }

javascript - Issue with click event in Reactjs -

this going simple. having hard time figuring out wrong how react component written. here component code. import react, { component, proptypes } 'react'; import styles './menu.css'; import submenu './submenu'; import classnames 'classnames/bind'; let cx = classnames.bind(styles); export default class menu extends component{ static proptypes ={ menudata:proptypes.array.isrequired }; constructor(props){ super(props); this.state = {menuopenedlabel:""}; }; menuclick(label){ this.state.menuopenedlabel = label; }; render(){ let menus = this.props.menudata.map(function(menuitem){ let handleclick = this.menuclick.bind(this,menuitem.label); return (<li key={menuitem.label}> <a onclick={handleclick}>{menuitem.label}</a> <submenu submenu={menuitem.submenu} isvisible={this.state.menuopenedlabel === menuitem.label}/> </li>); }); return (<nav> <ul classname={styles.menu}>{(menus)}...

python - Pygame 2d tile scrolling edges don't load -

Image
im trying make 2d game in pygame kinda works pokemon. ive gotten stuck on problem dont know how solve. when move character scroll map instead player stays centered. i've created "animation" offsetting distance 2 pixels @ time instead of moving full tile size smooth movemen. problem have when move, screen doesn't load new tiles in edges i'm moving towards edges end white space until i've completed full animation. i'll link code , can me :) tilesize = 32 map_width = 25 map_height = 25 class player(pygame.sprite.sprite): def __init__(self, color, width, height): # call parent class (sprite) constructor super().__init__() self.name = "player" self.width = width self.height = height self.image = pygame.surface([width, height]) self.image.fill(color) self.rect = self.image.get_rect() self.rect.x = int(tilesize * (map_width / 2)) - tilesize / 2 self.rect.y = in...

How to locate the fonts being used by my Java Swing app on the system? -

Image
i noticed fonts different when run java swing app netbeans , when run jar file c: drive on windows 7. i told fonts used in jars apps come system, different fonts when run netbeans, keep app consistent ide , user perspective, how locate fonts being loaded app netbeans can copy them app , package them part of jar app, doable ? if after copy them app, how load them inside app ? here code , images : import java.awt.*; import java.awt.event.windowadapter; import java.awt.event.windowevent; import javax.swing.*; public class test_jpanel extends jpanel { public static final long serialversionuid=26362862l; static dimension screen_size=toolkit.getdefaulttoolkit().getscreensize(); thread empty_jpanel_thread; public test_jpanel() { setpreferredsize(new dimension(300,600)); string table="<html>\n"+ " <center><br>\n" +"test table<p>\n" +" <table border=...