Posts

Showing posts from March, 2014

javascript - Angular Get data from $http request gives undefined -

so, want data api (provided laravel). using $http in angular data, , when send forward view, works fine, when want use data inside controller, doesn't: html: <!doctype html> <html ng-app="todoapp"> <head> <script src="http://code.jquery.com/jquery-1.10.2.js"></script> <script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="/js/maincontroller.js"></script> </head> <body ng-controller="maincontroller mycontrol"> <h1>todo-list:</h1> <div> <table> <tr> <th>note:...

Access properties of Javascript variable -

Image
i want access specific properties of response object received request server. getrespondersinrange: function() { this.$http.get('v1/responders?'.concat("latitude=" + this.latitude + "&longitude=" + this.longitude)).then(function(response) { this.responders = response.data["data"]; console.log(this.responders); }.bind(this)); }, the console.log returns this: i want access field "userreference", can't find out how. tried: console.log(this.responders["userreference"] console.log(this.responders.userreference it returns array, try access property way: this.responders[0]["userreference"];

download - downloading a file in python and cancel -

i trying make simple function download file in python code like def download(url , dest): urllib.urlretrieve(url, dest) my issue if want cancel download process in middle of downloading how approach??? this function runs in background of app , triggered button. trying trigger off button. the platform xbmc. a simple class same download function: import urllib import threading class downloader: def __init__(self): self.stop_down = false self.thread = none def download(self, url, destination): self.thread = threading.thread(target=self.__down, args=(url, destination)) self.thread.start() def __down(self, url, dest): _continue = true handler = urllib.urlopen(url) self.fp = open(dest, "w") while not self.stop_down , _continue: data = handler.read(4096) self.fp.write(data) _continue = data handler.close() self.fp.close() ...

mysql - Import Excel in Yii2 -

i have yii2 application using advanced template , database mysql, make function import excel file 1 of table, made function in controller named student contains crud of students data.this code public function actionimportexcel() { $inputfile = 'uploads/siswa_file.xlsx'; try{ $inputfiletype = \phpexcel_iofactory::identify($inputfile); $objreader = \phpexcel_iofactory::createreader($inputfiletype); $objphpexcel = $objreader->load($inputfile); } catch (exception $e) { die('error'); } $sheet = $objphpexcel->getsheet(0); $highestrow = $sheet->gethighestrow(); $highestcolumn = $sheet->gethighestcolumn(); for($row=1; $row <= $highestrow; $row++) { $rowdata = $sheet->rangetoarray('a'.$row.':'.$highestcolumn.$row,null,true,false); if($row==1) { continue; } $siswa = new siswa(); $siswa->nis = $rowdata[0][0]...

javascript - using _.map and async.map together -

i'm using both _.map , async.map in node portion of application i'm working on. i'm running confusion while using these libraries together. i have array of arrays called results looks this: [[1, 2, 3], [2, 4, 6], [1, 3, 5]] i use _.map access each inner array, , async.map make api call each value within each of these inner arrays. use results of api call replace each integer within inner arrays object. so @ end array of arrays of integers instead array of arrays of objects based on api call results. [[{id: 1, email: 'test@example.com', state: 'active'}], ...] this current code have, , believe i'm on right path. first console.log gives me object i'm aiming for, second returns integer: _.map(results, function(result) { async.map(result, function(user, callback) { db.users.getbyid(user, function(err, userdetails) { if (err) { callback(null, null); } else { user = _.pick(userdetails, 'id',...

autohotkey - Show the GUI every time the Notepad window is opened -

i trying create code, show foo window every time notepad opened. problem is, if close foo once, not shown again (when open notepad next time). using following code: settitlematchmode, 2 winwaitactive, notepad gui, add, button, w200 h25 gtest1 , button 1 gui, add, button, w200 h25 gtest2 , button 2 gui, show,, foo return test1: run test1.ahk return test2: run test2.ahk return #persistent settimer, show_gui, 300 return show_gui: ifwinnotexist, ahk_class notepad { gui, destroy return } ; otherwise: settimer, show_gui, off gui, add, button, w200 h25 gtest1 , button 1 gui, add, button, w200 h25 gtest2 , button 2 gui, show,, foo winwaitclose, ahk_class notepad settimer, show_gui, on return test1: ; sth return test2: ; sth return https://autohotkey.com/docs/commands/settimer.htm#examples

Opengl stripped surface when viewed under angle -

Image
i have problem stripped surface in program. i render surfaces using opengl(tao). use triangle_strip. have 3d impression use lighting. normals set correctly thing. at first used crossproduct, use derivation of implicit function. both methods seem give right results, derivation may better because of precision. see on surface vertical stripes. 2 neighbor triangles in strip have different hue/shade. 1,3,5,7 ... , 2,4,6... have same hue/shade. smaller viewing angle bigger difference is. @ 90° it's ok. how can rid of stripes? here can see images: initialization: private float[] materialambient = { 1.0f, 1.0f, 1.0f, 1.0f }; private float[] materialdifuse = { 0.6f, 0.6f, 0.6f, 1.0f }; private float[] materialodlesky = { 0.2f, 0.2f, 0.2f, 1.0f }; private float[] materialshininess = { 50.0f }; private float[] light_position = { 0.0f, 0.0f, 1.0f, 1.0f}; private float[] light_color = { 0.7f, 0.7f, 0.7f } gl.glshademodel(gl.gl_smooth); gl.glenable(gl.gl_depth_test); gl.g...

python - double input and extra letter in list in Sagemath -

Image
i'm newbie in python , sagemath , it's confusing me. with following code, i've got u character before each element of list. str = raw_input() chr = list(str) print chr # input: "alma" # output: [u'a', u'l', u'm', u'a'] furthermore when run project input field appears twice. first when have write, , after when press enter (appears entered text)

python - Rank elements in a data frame while keeping index -

i'm using following formula gather top 20 elements each row in data frame. works great dropping index column df_returns i'd keep them. using dates index in df_returns data frame , i'd have same dates corresponding new data in df_rank data frame. df_rank = pd.dataframe({n: df_returns.t[col].nlargest(21).index.tolist() n, col in enumerate(df_returns.t)}).t for example, let's wanting top 3 following data frame: b c d e 1/1/2014 5 4 6 8 1 2/1/2014 2 1 6 3 1 3/1/2014 8 2 3 5 1 the results i'm getting are: 0 d c 1 c d 2 d c the results i'd are: 1/1/2014 d c 2/1/2014 c d 3/1/2014 d c you use set_index set index of new dataframe original one: df_rank.set_index(df_returns.index)

c# - Binding doesn't subscribe to PropertyChangedHandler -

alright i've been on ages , can't see why doesn't work. i have binding usercontrol label onto property in class cell . class implements interface inotifypropertychanged . there everytime set method called call onpropertychanged("value) which expected update label it's binded to. not case. i did research on stack clarify of problems i've checked: i have datacontext set since use mvvm light set viewmodel locator. this property outside of viewmodel it's suppose in order not make more expandable towards other sizes of sudoku. edit: property changed fired handler null suspect it's not being subscribed to, hence title. edit 2 code sudoku game grid of 3x3 grids of 3x3 hiarchy here outtergrid has innergrids , innergrids have cells thought better not include these codes since same. snipit of datacontext declared mainwindow.window: <window x:class="sudokuwpf.mainwindow" xmlns="http://schemas.microsoft.com/winfx/2006/xam...

c# - How to achieve centred box in xaml responsive grid -

Image
i place box in centre of screen in xaml grid layout. however, able use grid place objects inside box also. see below. how this? if red box span 5 rows, of different height, row above , below must same height. there similar arrangement columns. must responsive, such code works on wide range of device sizes. using xamarin. i don't know if xamarin introduces different behavior, vanilla xaml, should able set verticalalignment , horizontalalignment center , box should centered (you need provide explizit size or put box). if want layout content in box, should define separate gridlayout inside box (maybe taking @ sharedsizegroup if need share sizes between 2 grids).

c# - Unity3D android app, UI shows completely black, only once built to Android device -

i'm building 3d virtual pet app android mobile phones using unity 5. below screenshot of scene while running through unity itself. however when app built android phone (running android version 5.0.1), green window on right black, leaving neither of 2 progress bars visible. each object 'image', added canvas. main window green rectangle. each progress bar black rectangle white rectangle on top of that, coloured rectangle on top of white(this re sizes show progress). i don't know causing issue. if there further information please let me know, i've been struggling issue while now. i stuck on same issue images took on expected color in unity editor not when game running on android phone. to fix issue set "source image" something. unity comes couple simple images can use. try setting "source image" property of canvas image "uisprite" sprite. once done change "image type" "simple" , should work on and...

multithreading - Exception in Application constructor -

i wanna write snake game javafx , there exception don't know , want know how fix it. ( know it's not complete yet ) and want know , class extends application ( start override ) main in other programs? see , here not static void main bc didn't need, if want add main shoud do? it's exeption... exception in application constructor exception in thread "main" java.lang.nosuchmethodexception: main_snake.main([ljava.lang.string;) @ java.lang.class.getmethod(class.java:1819) @ com.intellij.rt.execution.application.appmain.main(appmain.java:125) and code : import javafx.animation.animationtimer; import javafx.application.application; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.canvas.canvas; import javafx.scene.canvas.graphicscontext; import javafx.scene.input.keyevent; import javafx.scene.layout.borderpane; import javafx.scene.paint.color; import javafx.stage.stage; import java.util.arraylist; /** * creat...

excel - How do I sum up the value of a column where a given value exists in another column? -

each row in sheet represents transaction. 1 column (g) contains client name , column (h) contains gp exchange. i'm trying make report in sheet references these cells gp info each of our clients. the formula i'm trying accomplish this: sum gp (column h) every row containing [clientid] in column g the clientid on column g , gp on column h i make process automated each time transaction entered, client gp sheet automatically updated. thanks. only can closed out: as per comments use sumif() function: =sumif(g:g,[clientid],h:h) references: google , excel

Complement Graph - prolog -

i have question. have continuous undirected graph. , need code in prolog give me complementary graph. for example graph: edge(1,2). edge(2,3). edge(3,4). edge(4,5). edge(5,1). rot(x,y):- edge(x,y). rot(x,y):- edge(y,x). please, :) thanks. this should work issuing ground queries , enumerate possible edges. complement(x, y):- ((var(x);var(y)) -> setof(v, z^rot(v,z), vertices);true), % if either vertex not ground, compute set of vertices (ground(x) -> (once(rot(x, _)), verticesx=[x]) ; verticesx=vertices), % determine list of candidate x (ground(y) -> (once(rot(y, _)), verticesy=[y]) ; verticesy=vertices), % , candidate y member(x, verticesx), member(y, verticesy), x \= y, % generate , test \+(rot(x,y)). % possible candidates

Ansible: How do I avoid registering a variable when a "when" condition is *not* met? -

i have following ansible playbook code: - name: users | generate password user (debian/ubuntu) shell: makepasswd --chars=20 register: make_password when: ansible_distribution in ['debian', 'ubuntu'] - name: users | generate password user (fedora) shell: makepasswd -m 20 -m 20 register: make_password when: ansible_distribution in ['fedora', 'amazon'] - name: users | generate password user (centos) shell: mkpasswd -l 20 register: make_password when: ansible_distribution in ['centos'] - name: debug debug: var=make_password which outputs: task: [users | debug] ok: [127.0.0.1] => { "var": { "make_password": { "changed": false, "skipped": true } } } ... because every register block gets executed regardless of when cond...

c# - Group by year descending, order by month and total on another column Linq query -

Image
have linq query working, can't figure out how descending order. here have far: list.groupby(grp => grp.year) .selectmany(g => g.orderby(grp => grp.month)) .tolist(); which produces following results: month in correct order except year needs in descending order. this: this might ask need run total of days per grouped year. appreciate help! the data looks this: the answer worked me this: list.orderbydescending(grp => grp.year).thenby(grp => grp.month).tolist() two comments: you "grouping" data, turning around , un-grouping via selectmany , throws away grouping; puts data groups, not in configurable order. select of data in 1 go, ordering year descending, month: list.orderbydescending(l => l.year) .thenby(l => l.month)); adding "group footers" show subtotals job of presentation layer, not data layer. could create hybrid list inserts total "row" data, more straightforward add group ...

symfony 2.1 - How do you include a plugin in Compass (through Assetic) for Symfony2? -

i have installed compass-rgbapng plugin, struggling to include plugin use in symfony2. i need add require "rgbapng" compass config file, unsure how through symfony2. does know how can this? i think in app/config/config.yml should helps: # assetic configuration assetic: filters: compass: plugins: - rgbapng

javascript - Node EJS passing data to an include -

currently i'm messing around node , ejs templates. however have hit problem. im building page made of multiple components , im calling these components index page so: <% include components/header.ejs %> my question how can pass data (json) specific include? i want able reuse components show different content coming json. thanks try: <%- include('components/header.ejs', {data: 'data'}); %>

javascript - Div not expanding with content inside -

basically, in #main-content div, expand, de facto content of div fits inside , not overlapping, see in codepen. i don't know how implement clearfix solution or overflow:hidden solution. i've tried failed. i don't know why, p tag not overlapping, javascript/jquery progress bars are. :/ codepen: http://codepen.io/docrow10/pen/hjikq snippet: body { margin: 0; } #nav-bar { width: 100%; height: 50px; background-color: rgb(40, 40, 40); border-bottom-style: solid; border-bottom-color: rgb(238, 0, 0); border-bottom-width: 7.5px; padding-top: 14px } #logo { position: relative; bottom: 5px; font-size: 30px; padding-left: 8px; float: left; font-family: bebas; } #word-1 { color: rgb(0, 154, 205); } #word-2 { color: rgb(255, 250, 250); } ul#main-links { list-style: none; margin: 0; padding-right: 50px; float: right; height: 100%; border-bottom: 7.5px solid transparent; display: block; font-size: 0; ...

html - Create a "complex" background in CSS -

Image
i know if possible create background in css3. background should span header div , gradient should go white black independent of screen width (always white on left side , black on right side). reason not using image takes longer load , can't resize it's width when making browser smaller 1920px (the width of image). have tried linear-gradient can't work... regards, jens if want black bar @ top should give dimensions background, stop repeating , position want ( treat normal background image ) div { background-color: black; background-image: linear-gradient(to right, white, black); background-repeat:no-repeat; background-size:100% 20px; /*full width, 20px height*/ background-position:0 100%; /*gradient @ bottom*/ /*just give size demo*/ min-height:50px; } <div></div>

image - Bicubic interpolation in C -

Image
im trying deal bicubic image interpolation in c . therefore i've built small script. 1. "resize_image"-function: void resize_image(ppmimage *source_image, ppmimage *destination_image, float scale) { uint8_t sample[3]; int y, x; destination_image->x = (long)((float)(source_image->x)*scale); destination_image->y = (long)((float)(source_image->y)*scale); (y = 0; y < destination_image->y; y++) { float v = (float)y / (float)(destination_image->y - 1); (x = 0; x < destination_image->x; ++x) { float u = (float)x / (float)(destination_image->x - 1); sample_bicubic(source_image, u, v, sample); destination_image->data[x+((destination_image->y)*y)].red = sample[0]; destination_image->data[x+((destination_image->y)*y)].green = sample[1]; destination_image->data[x+((destinatio...

PHP Equivalent of Java's @Override When Implementing Interface (For check style) -

phpcs complaining php doc implementations of interfaces have php doc provided in interface. my question is, how cleanly phpcs ignore interface method implementations, similar java's @override ? below example of how in java , have in php. goal able ignore methods interfaces have php doc. if method not implementation, should still required have php doc provided. how works in java in java, can have interface so: public interface sandbox { /** * description of method. */ void somemethod(); } and class implements so: public class sandboximpl implements sandbox { @override public void somemethod() { // concrete implementaiton. } } with above, java picks java doc without issues , @override helps past check style checks. what have in php in php, have interface like: interface sandbox { /** * php doc. * * @return mixed */ public function somemethod(); } with class implements like: class sandb...

c# - XSD: Using Visual Studio xsd.exe not generating fixed/default values from base element set through restriction in the child element -

what want achieve have base complex type defines id , have child-specific value id along each child having additional child-specific elements. know can't achieved in 1 block defined base type, defined type sets id through restriction, , have type definition extends restricted type adding more elements. the schema validates, when use xsd.exe tool generate classes, restricted class not set id in code @ all, resulting in id value not being set in extended class. i have defined base complex element in following manner: <xs:complextype name="baseelem" abstract="true"> <xs:sequence> <xs:element name="elemid" type="xs:int"/> </xs:sequence> </xs:complextype> next, added child element sets elemid value through restriction: <xs:complextype name="baseelemfoo"> <xs:complexcontent> <xs:restriction base="baseelem"> <xs:sequence> <xs:elemen...

telnet login using batch -

Image
i have created bat file open telnet session. problem couldn't send keys username {enter} ; password{enter} have tried many things similar blogs, unfortunately dint work me far. i tried download expect. printf user name password. echo user name password. telnet -l ftpcmd.dat:teftpcmd.dat %servername% | -m telnet -l ftpcmd.dat:teftpcmd.dat %servername% | -f file name ( "echo username"; sleep 2; echo "password") | telnet -l 10.89.193.2 please suggest.

javascript - Add Easing effect to Accordion Opening / Closing -

i'm super new js wanted simple accordion built one. reason @ loss when trying add easing effect opening / closing of it. appreciated. thank you! codepen of accordion js code: (function(){ // class added expanded item var activeitemclass = 'accordion-expanded'; var accordionitemselector = '.accordion-section'; var toggleselector = '.accordion-head'; $(toggleselector).on('click', function() { $(this) .closest(accordionitemselector) // go accordion item element .toggleclass(activeitemclass) .siblings() .removeclass(activeitemclass); }); })(); since you're using jquery, why not this: var accordionitemselector = '.accordion-body'; var toggleselector = '.accordion-head'; $(toggleselector).on('click', function() { if (!$(this).next(accordionitemselector).is(":visible")) $(toggleselector).not($(this)).next(accordionitemselector).slideup(); ...

javascript - Dynamically expanding width of a dynamically loaded DIV -

i've created tooltip loaded dynamically based on server side data. it's been working until got larger skus. there overflow. i'm trying use either css or js dynamically change width eliminate overflow shown in this fiddle . my html: <div class="ext-tooltip 12345-789-1456789-431535" data-sku="12345-789-1456789-431535"> <div class="tooltip-stock">12345-789-1456789-431535 :: 5</div> </div> <div id="invoice-lines"> <div id="progress-container" class="hide" style="display: none;"> <div class="progress-bar-container"> <div id="progress-bar" class="progress-bar-progress" style="width: 100%;"></div> </div> <div class="example ta_center">loading...</div> </div> <table cellspacing="0" id="invoice-time" class=...

hyperlink - Trouble with a:visited pseudoclass... Links all showing as the same color after they are "visited" despite having different colors in css -

i having trouble a:visited (or 1 of other maybe?) pseudoclass. want have links show different colors in different elements (black in .link-box , red in #main-menu regardless of if have been visited or not), @ first, once "visited" links, same color (red). any idea i've done wrong here? .link-box { background-color: blue; } .link-box a:link, a:visited, a:active { color: black; padding-left: 10px; font-weight: bold; } .link-box a:hover { color: #d31900; text-decoration: none; } #main-menu { height: 60px; background-color: black; } #main-menu a:link, a:visited, a:active { color: red; text-transform: uppercase; } #main-menu a:hover { color: #ff6600; } <div class="link-box"> <a href="">link box link</a> </div> <div id="main-menu"> <a href="">main menu link</a>...

jquery - How to use select2 infinite scroll with coldfusion? -

http://ivaynberg.github.com/select2/#infinite example given isn't explained , have no idea happening on end produce results. edit : have changed cfc return limited amount of rows query. appended total row count hoping called ajax in data.total . cfc: <cffunction name="getclientsbyname" access="remote" returntype="string" output="true" hint="get clients search term"> <cfargument name="name" type="string" required="yes"> <cfargument name="page" type="numeric"> <cfargument name="page_limit" type="numeric"> <cfset var start = (arguments.page * arguments.page_limit) - arguments.page_limit + 1> <cfset var end = start + arguments.page_limit> <cfset var util = createobject("component", "/surveymanagement/jsonutil")> <cfset var results = arraynew(1)...

perl - Parse::FixedLength Trimming Issue -

in earlier question had asked how avoid parse::fixedlength trimming zeros. code @bolav suggested worked sample data using somehow not seem work new data. it seems should work somehow trimming zeros data. making obvious mistake cannot figure out is. appreciate help. #!/usr/bin/perl use strict; use warnings; use parse::fixedlength; use data::dumper; $parser = parse::fixedlength->new([ field1 => '12r0:1:12', field2 => '2:13:14', field3 => '5r0:15:19', field4 => '10r0:20:29', field5 => '2r0:30:31', field6 => '3r0:32:34' ], {trim => '1'}); $parser->{tpad}[0] = qr/^0+(?=\d)/; # modification suggested @bolav while (<data>) { warn "no record terminator found!\n" unless chomp; warn "short record!\n" unless $parser->length == ...

associations - Left outer join a nested select in Rails -

i'm trying set classic 'like' model posts on blog, users can create 1 post. have following models: class post < applicationrecord belongs_to :user has_many :likes end class user < applicationrecord has_many :posts has_many :likes end class < applicationrecord belongs_to :user belongs_to :post, counter_cache: true end in controller monitor logged in user, current_user . i add column posts model indicates whether or not current_user has liked each post. i tried adding method posts model looks likes: class post < applicationrecord belongs_to :user has_many :likes def user_liked !likes.empty? end end and using includes in controller method. @posts = post.includes(likes: { user: current_user }).where(safe_params).order(order) render json: @posts however following error: argumenterror (#<user id: 1, username: "pete", ... > not recognized preload): app/controllers/posts_controller.rb:51:in `index' ...