Posts

Showing posts from August, 2014

ios - NSCalendar.components().minute returning inconsistent values -

original problem encountered during post, testing , code in link below https://stackoverflow.com/questions/27339072/working-with-nsdate-components-in-swift/30822018#30822018 here minimal test-case i creating date offset particular date (self in case in nsdate() extension) using nscalendar.datebyaddingunit(..., value:x, ...) i difference "fromdate" (created date or self) "todate" (current time nsdate()) using nscalendar.components(..., fromdate, todate, ....).minute if x>0, answer in step above x-1. if x<0, answer x. x defined in step 1 above. this has potential cause bugs in applications filter events using human readable attributes such events in past 3 hrs since 180 minutes not 3 hours due behavior. this not bug in step 1 since date prints correctly seen in printout @ end of post. is there option in nscalendar.components missing or bug? here code. // // nsdatetest.swift // nsdatetestcase // // created jitendra kulkarni on 6/13...

open source - Ideas for social projects involving programming -

i engaged on junior enterprise (je) @ college. have been thinking of having our je more social works involving programming on our community , since 1 of our goals increase relationship university-community . we have thought on giving programming classes lower-class kids. however, found out impracticable, because of complexity of training teachers on teach them, how treat them , expect them. alongside other issues. what ideas social projects relatively easy put practice might suggest? open-source projects idea, have realised wouldn't direct way of helping our community. also, junior enterprise, hence (but not necessary) if involve programming! looking forward ideas! unfortunately, question closed off-topic. site not suited questions answer list of things. (they really need leverage experience of user base site suited kind of thing... anyway.) before became programmer, worked several non-profits: conservation corps, food bank, , organization flips houses ,...

PHP with REST web services -

there rest web service exists. there 1 user: admin. once enter admin credentials while logging in, token generated internally security purposes , once token validated, suppose enter homepage. i have added php part of code simple login have done already. know how , add , invoke token part authentication, based on above situation. <?php session_start(); /* starts session */ /* check login form submitted */ if(isset($_post['submit'])){ /* define username , associated password array */ $logins = array('admin' => 'kcuf94!'); /* check , assign submitted username , password new variable */ $username = isset($_post['username']) ? $_post['username'] : ''; $password = isset($_post['password']) ? $_post['password'] : ''; /* check username , password existence in defined array */ if (isset($logins[$username]) && $logins[$username] == $password){ /* succes...

ruby on rails - Date not saving to database when using form_for -

i've seen bunch of questions this, when looked @ them, either using jquery or people saving dates string. in model :deadline in date format. in doubt whether should make date or datetime maybe that's went wrong. anyway have form: <%= form_for(@task) |f| %> <%= render 'shared/error_messages', object: f.object %> <div class="field"> <%= f.text_field :description, placeholder: "what do?" %> </div> <div class="input"> <%= f.date_field :deadline %> </div> <%= f.submit "create task", class: "btn btn-small btn-default" %> <% end %> the form appears normal, can pick date. however, doesn't save date database. i've tried <%= f.date_select :deadline %> as well. should change :deadline type, maybe leave string , parse when it's time display it? edit: tasks_controller.rb class taskscontroller < applicationcontrol...

java - Why is my MessageToMessage Encoder not sending data? (Netty 4) -

@override protected void encode(channelhandlercontext ctx, serverevent msg, list<object> out) throws exception { bytebuf data = ctx.alloc().buffer(); msg.encode(data); out.add(data); } the above method lives inside of messagetomessage encoder. server event takes bytebuf , writes data in appropriate order event. my client never receiving message. have encoder in pipeline , hit breakpoints inside of handler. doing wrong or missing?

actionscript 3 - How do I scroll with an object class that is added to the stage? -

hello people have small question: how make "map" object (platforms) moving (scrolling) when added stage , defined in own class? have scrolling text in code keeps giving me error saying i'm accessing property of null object. tried make definition object within class didn't help. can tell me i'm doing wrong? package { import flash.display.movieclip; import flash.events.keyboardevent; import flash.events.event; import flash.geom.point; public class bro extends movieclip { //define class determining variables private var moveup:boolean; private var moveleft:boolean; private var movedown:boolean; private var moveright:boolean; private var jumping:boolean; private var movespeedr:uint; private var movespeedy:number; private var hittestradius:number; private var hittestangle:number; private var convertframetosecond:number; private var checker:uint; private var barrier:obstacles; private var dsttomc:number;...

data structures - How to insert a item in sorted linked list within constant time complexity? -

i have problem in sorted linked list .i can't insert item in constant time. if possible how can solve it? and function time complexity big-o(n) template <class itemtype> void sortedtype<itemtype>::insertitem(itemtype item) { nodetype<itemtype>* newnode; nodetype<itemtype>* predloc; nodetype<itemtype>* location; bool moretosearch; location = listdata; predloc = null; moretosearch = (location != null); while (moretosearch) { if (location->info < item) { predloc = location; location = location->next; moretosearch = (location != null); } else moretosearch = false; } newnode = new nodetype<itemtype>; newnode->info = item; if (predloc == null) { newnode->next = listdata; listdata = newnode; } else { newnode->next = location; predloc->next = newnode; } length++; } it not possible inset item in sorted linked list within constant...

javascript - How to check if child element does not have a class using jQuery -

i trying figure out how check if parent div has child p element without class. so e.g. <div id="one" class="item"> <p class="a"></p> <p class="b"></p> <p class="c"></p> </div> <div id="two" class="item"> <p class="b"></p> <p class="c"></p> </div> if div not have p element class "a", want hide div. how this? i tried: if (jquery(".item > p.a").length <= 0){ //run code here } but not seem work thanks you can use jquery :has() , :not() like $('div:not(:has(p.a))').hide(); $('div:not(:has(p.a))').hide(); <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <div id="one" class="item"> ...

javascript - testing true or false if it has numbers 1-9 in array -

i'm trying test if array has numbers 1 through 9. have 9 different arrays test, i'm trying loop set of array 1 one , convert string , test array if has numbers 1 through 9. when output code, comes out [true, true, true, true, true, true, true, true, false] the last 1 should come out false, because array[8] not contain numbers 1 9. i'm not sure if regex coding wrong, test prints out true arrays should false. function doneornot(board){ var numbertest = /[1-9]/g; var boardstr = ""; var boardtest; var testresult = []; for(var = 0; < board.length; i++) { boardstr = board[i].tostring(); boardtest = numbertest.test(boardstr); testresult.push(boardtest); console.log(boardstr); } console.log(testresult); } doneornot([[5, 3, 4, 6, 7, 8, 9, 1, 2], [6, 7, 2, 1, 9, 0, 3, 4, 9], [1, 0, 0, 3, 4, 2, 5, 6, 0], [8, 5, 9, 7, 6, 1, 0, 2, 0], [4, 2, 6, 8, 5, 3, 7, 9, 1], [7, 1, 3, 9, 2, ...

javascript - You are given a square matrix of size N times N. Calculate the absolute difference of the sums across the two main diagonals -

Image
this question hackerrack.com, explanation of question i solved problem, unable find optimistic solution , can using object literals , come across optimal solution? function gettwodimention(input){ var input = input.split('\n'); var twodimarr=[]; for(var n=0; n<input.length; n++){ var subarr = input[n].split(' '); if(subarr.length > 1){ twodimarr.push(subarr) } } return twodimarr; } function getfristdiagonal(twodimarr){ var sum = 0; for(var i=0; i<twodimarr.length; i++){ for(var j=i; j<=i; j++){ sum += parsefloat(twodimarr[i][j]); } } return sum; } function getseconddiagonal(twodimarr){ var sum = 0;j=twodimarr.length-1; for(var i=0; i<twodimarr.length; i++){ sum += parsefloat(twodimarr[i][j--]); } return sum; } function processdata(input) { //enter code here twodimarr = gettwodimention(input); var firtdia = g...

asp.net - Submit a form and data after c# code has performed a function -

i've read lot of pages of questions , answers in regards form submitting in asp.net4.0 , fact ignores action="somepage.aspx" , posts only, none have touched on have issue: i have form posts details hosted payment page (i.e. not on server) , data stored inside <input type="hidden" ... > controls, these controls data code behind, confirmation page , data previous page. till form works fine, posted data through external hosted page on clicking submit button. great. now though need change <input type="submit" ... > button <asp:button ... > runs function in code behind log in database button clicked (it store click against users id) before posting data hosted page. here problem lies, need 2 forms on page, 1 runat="server" overall page , it's asp.net controls, form , action="externalpage" . gives following error control 'submit' of type 'button' must placed inside form tag runat=s...

javascript - Ajax Request Hit or Miss with PHP SQL Submit -

Image
i have form, after validation, executes 2 ajax requests , submits form create entry in mysql database. 2 ajax requests return urls (links) google documents created upload.php. however, ajax request "agenda" comes across error when form filled data meets unknown criteria. when same url accessed manually, url (link) of google document returned. so ultimate problem when ajax request comes across error, cannot submit form. after form validation, ajax requests sent upload.php , form submitted via post create.php . the responses ajax assigned hidden values can stored along form submit. form-validation.js submithandler: function(form) { $('#submitbutton').button('loading'); console.log('loading button'); $("#cancelbutton").prop("disabled", true); console.log('disable button'); success1.show(); error1.hide(); var ename = $('#create_event').find('input[name="eventname"]').val(); var ...

php - Regex - the difference in \\n and \n -

sorry add "regex explanation" question internet must know reason this. have ran regex through regexbuddy , regex101.com no help. i came across following regex ( "%4d%[^\\n]" ) while debugging time parsing function. every , receive 'invalid date' error during months of january , june. mocked code recreate happening can't figure out why removing 1 slash fixes it. <?php $format = '%y/%b/%d'; $random_date_strings = array( '2015/jan/03', '1985/feb/13', '2001/mar/25', '1948/apr/02', '1948/may/19', '2020/jun/22', '1867/jul/09', '1901/aug/11', '1945/sep/21', '2000/oct/31', '2009/nov/24', '2015/dec/02' ); $year = null; $rest_of_string = null; echo 'bad regex:'; echo '<br/><br/>'; foreach ($random_date_strings $date_string) { sscanf($date_string, "%4d%[^\\n]...

php - Issues having Facebook profile images -

i have been searching answer question hours couldn't find easy way it. i'm building android application using java , php show, update, insert , delete data database tables. i'm using parameters interact java php. my application using facebook sdk login, users can login , create accounts using facebook. i'm getting e-mail, name , profile image every user tries create account on app. but i'm getting issues when try image profile users. i'm receiving url that: http://graph.facebook.com/id_from_the_user/picture?type=large i these images using java, need save image specific directory using php. i'm following these steps. receiving image url profile. passing image url php file using parameters. saving image new directory on local computer. inserting database name image, , directory folder image located. and i'm stuck on third step because code can't recognize sending image. my code receive image: define('directory...

jquery - php delete from sql and directory form -

i have resolved issue of warning going if(!file_exists($file_to_delete) (as know in folder images needed user not other directories) have made check on id numeric & exists in db , sanitised query's believe please have though new code below , see if ok or if , further problems exist many thanks heres code <?php // include databse include ("common.php"); // varibles $delete = $_post['delete']; $id = $_post['id']; $filename = $_post['filename']; $ext = end(explode('.',$filename)); // check if form has been submitted if (isset ($delete)) { // check filename not empty if(empty($filename)) { $status = "please enter filename" ; $error = true; $filecheck = false; } else { $filecheck = true; } if ($filecheck) { //check user stays in correct directory & check image ext if(!preg_match('/^\/?[\w\s-_]+\.(jpe?g|gif|png|bmp)$/',strtolower($filename))) { $error = true; ...

swift - Int is not convertible to UIInterfaceOrientationMak for supportedInterfaceOrientations() -

i have problem xcode 7. have tried research cannot come solution. error int not convertible uiinterfaceorientationmask. code below: override func supportedinterfaceorientations() -> uiinterfaceorientationmask { if visibleviewcontroller kinwebbrowserviewcontroller { return int(uiinterfaceorientationmask.all.rawvalue) } return int(uiinterfaceorientationmask.portrait.rawvalue) } thanks swift 3.x override var supportedinterfaceorientations: uiinterfaceorientationmask { return visibleviewcontroller kinwebbrowserviewcontroller ? .all : .portrait }

html - Getting the correct href of the clicked link with javascript? -

this question has answer here: javascript closure inside loops – simple practical example 31 answers i have simple html menu: <div id="menulinks"> <ul> <li><a href="#link1">link 1</a></li> <li><a href="#link2">link 2</a></li> <li><a href="#link3">link 3</a></li> <li><a href="#link4">link 4</a></li> </ul> </div> and need write javascript - can't use jquery - gives me href of clicked anchor link. that's did: var = document.getelementbyid("menulinks").getelementsbytagname("a"); ( var o = 0; o < a.length; o++ ) { var clickedlink = a[o]; clickedlink.addeventlistener("click", function() { var b = clickedlink.getattribute("href...

ios - Facebook Login Keeps Returning Nil - Parse/Swift -

so i've been trying implement facebook login in app. using own interface , button. once user presses login button following code run try login user. let permissions = ["public_profile"] @ibaction func fbloginclick(sender:anyobject){ pffacebookutils.loginwithpermissions(self.permissions, block: { (user: pfuser?, error: nserror?) -> void in if error == nil { nslog("cancelled facebook login") nslog("fb login error: \(error)") }else if user!.isnew { nslog("user signed , logged in \(user)") self.performseguewithidentifier("login", sender: self) }else { nslog("user logged in through facebook \(user)") self.performseguewithidentifier("login", sender: self) } }) } it run code fine , launch facebook app ask permission user expect. when press agree returns same view controller saying tha...

JavaFX: How can I horizontally center an ImageView inside a ScrollPane? -

viewscroll.setcontent(new imageview(bigimg)); double w = viewscroll.getcontent().getboundsinlocal().getwidth(); double vw = viewscroll.getviewportbounds().getwidth(); viewscroll.getcontent().settranslatex((vw/2)-(w/2)); viewscroll.tofront(); i set imageview image inside scrollpane imageview goes far left corner. here i'm trying manually offset difference, doesn't work well. imageview goes far right plus updates once because it's inside eventhandler button. here example using label without need listeners: public void start(stage primarystage) throws exception { scrollpane scrollpane = new scrollpane(); label label = new label("hello!"); label.translatexproperty().bind(scrollpane.widthproperty().subtract(label.widthproperty()).divide(2)); scrollpane.setcontent(label); scene scene = new scene(scrollpane); primarystage.setscene(scene); primarystage.setwidth(200); primarystage.setheight(200); primarystage.show(); }...

monitoring - how to monitor mesos frameworks -

from mesos web ui under frameworks there list of running , terminated frameworks want monitor periodically (save list database ,etc.) wondering if there log file such list , api , etc. ? all events happen in mesos cluster captured in mesos master log. means parsing , analysing log, can reconstruct cluster state @ point of time. mesos webui based on /state.json master endpoint. in mesos 0.23 new endpoint /state-summary introduced. provides less information, needs less time return. think 1 of give need.

How to add reference to System.IdentityModel in Visual Studio 2015 RC -

in vs 2015 rc start new project using asp.net 5 preview template named "web site" , "no authentication". i need incorporate existing helper class have references microsoft.identitymodel. i run install-package microsoft.identitymodel error follows. install-package microsoft.identitymodel -verbose install failed. rolling back... uninstalling nuget package microsoft.identitymodel.6.1.7600.16394. install-package : error occurred while sending request.at line:1 char:1 + install-package microsoft.identitymodel -verbose + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : notspecified: (:) [install-package], exception + fullyqualifiederrorid : nugetcmdletunhandledexception,nuget.packagemanagement.powershellcmdlets.installpackagecommand something similar happens if use package manager ui. i tried instead adding reference directly in frameworks > dnx451 in project.json yields yellow triangle in references se...

ios - plist data after an update -

i've created plist stores user's data in app such amount of coins, best score, clothes internal store , on. , now, 1 day before release, realized after updating app user's data lost. right? if i'm not, how plists work? let's say, in version 1.0 of app have plist consists of amount of user's coins. decide add amount of diamonds plist, plist in version 2.0 consists of coins , diamonds. default value coins , diamonds 0. so, user downloads 1 version, has 0 coins. plays while , earns 100 coins. updates app 2 version. happens plist in case? deleted, new 1 added instead , user have default 0 coins , 0 diamonds? or not updated @ all? or he'll still have 100 coins, 0 diamonds? all in all, want know how other developers store user's data locally on device, without using external databases , on. p.s. how create plist: var paths = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true)[0] as! string var path = paths.strin...

c# - Cant Find Control Windows Phone 8.1 UAP -

i trying find control under xaml in hub control of windows phone 8.1. may case method works fine on desktop have testest in wpf before porting windows phone , may not work same. <grid> <hub header="lists" name="mainhub" > <hubsection minwidth="600" name="lattestlists" header="new lists"> <datatemplate> <grid> <listbox background="transparent" margin="6" height="auto" borderthickness="2" maxheight="580" grid.row="1" x:name="listboxobj" > <listbox.itemtemplate> <datatemplate> <grid width="350" > <border margin="5" borderbrush="white" borderthickness="1"> ...

android - Best practice when using fragments in activities? -

i have fragment opens various dialogs , starts async tasks. use listener pattern info dialogs or tasks. to open dialog following: public void selectdialog() { mydialog dialog = mydialog .newinstance(); dialog.setfragment(this); dialog.show(getfragmentmanager(), "selectdialog"); } and task: public void dotask() { mytask mytask = new mytask(getactivity(), this, criteria); mytask .execute((void)null); } the reason i'm passing activity , fragment task because task uses sqlite db , helper class needs context (ie activity) , opens alertdialog. fragment casting listener. with above implementation, can use dialogs , tasks within fragments now. is above correct way open dialogs , start tasks fragments? or should activity listener , pass info fragment?

c# - Counting total objects queued for garbage collection -

i wanted add small debug ui opengl game, updated various debugging options/output displays. 1 thing wanted constant counter shows active objects in each generation of garbage collector. don't want names or anything, total count; can eyeball when things within game. my problem, however, can't seem find way count total objects alive in various generations. i considered keeping global static field, incremented within every constructor , decremented within class finalizers. require hand-coding said functionality every class though, , not solve problem of "per-generation total". do know how go doing this? (question title:) "counting total objects queued garbage collection" (from question's body:) "my problem, however, can't seem find way count total objects alive in various generations. " remark: question's title , body ask opposite things. in title, you're asking number of objects can no longer reached vi...

cmd - Error with inner join mysql query -

please inner join error. done query in ms access - it's work, when in phpmyadmin or cmd - error select zakaz.c_id, count(zakaz.c_id) [counter] country join ((resort join hotel on resort.res_id = hotel.res_id) join ([number] join zakaz on (number.[num_id] = zakaz.[num_id]) , (number.[num_id] = zakaz.[cost])) on hotel.h_id = number.[h_id]) on country.c_id = resort.c_id group zakaz.c_id; in mysql, square brackets ( [ ] ) not valid characters identifier. in access, used enclose identifier. in mysql, use backtick characters enclose identifier needs escaped. (this allows include spaces or other characters not allowed in identifier, , allows use reserved words identifiers. in query, none of identifiers need escaped in backticks. also, in mysql, parens aren't necessary. the query expressed in form easier human reader decipher. example: select zakaz.c_id , count(zakaz.c_id) `counter` country join resort on resort.c_id = co...

python - Use decorators check user login in flask? -

i defined check user method: from functools import wraps def check_user(func): @wraps(func) def wrapper(*args, **kwargs): if session['logged_in']: return func(*args, **kwargs) else: return '<a href="/#/login">log in</a>' return wrapper @app.route('/test') @check_user def test(): return "hello" it not work. how can correct it? it seems don't know how create decorators in python. there many helpful answers on question: how can make chain of function decorators in python? below how can create decorator checks if user logged in. from functools import wraps def checkuser(func): """checks whether user logged in or raises error 401.""" @wraps(func) def wrapper(*args, **kwargs): if not g.user: abort(401) return func(*args, **kwargs) return wrapper the decorator above raise 401 erro...

wcf - WebSphere MQ - error running runivt on fresh install -

i trying execute runivt tests on fresh install of websphere mq 7.5.0.2 windows, hitting error: 14/06/15 08:48:28 - process(20900.1) user(bobble) program(amqswsdl.exe) host(bobblespc) installation(installation1) vrmf(7.5.0.2) amq9920: soap exception has been thrown. explanation: soap method encountered problem , has thrown exception. details of exception are: 'system.invalidcastexception: unable cast transparent proxy type 'mqsoaphost'. @ mqwsdl.main(string[] args)' action: investigate why soap method threw exception. ----- mqwsdl.main : 0 --------------------------------------------------------- when line: amqswsdl "jms:/queue?destination=soapn.demos@wmqsoap.demo.qm&connectionfactory=(connectqueuemanager(wmqsoap.demo.qm))&initialcontextfactory=com.ibm.mq.jms.nojndi&targetservice=stockquotedotnet.asmx&replydestination=system.soap.response.queue" stockquotedotnet.asmx generated\...

python - Convert escape characters in strings (like "\\n" - two characters) into ASCII character (newline) -

my program got string command line arguments, contains many escapes characters. ./myprog.py "\x41\x42\n" when print "sys.argv[1]". got on screen: \x41\x42\n is there simple way program print instead: ab[newline] try passing argument in following way: ./myprog.py $'\x41\x42\n' the $'...' notation allowed used \x00 -like escape sequences constructing arbitrary byte sequences hexadecimal notation. another way fix @ barak suggested here -- converting hex characters. depends on find easy you.

android - Determine by which process Application.onCreate() is called -

in application have local service, needs run in separate process. specified as <service android:name=".myservice" android:process=":myservice"></service> in androidmanifest.xml. subclass application object , want detect in it's oncreate method when called ordinary launch , when myservice launch. working solution have found described by https://stackoverflow.com/a/28907058/2289482 but don't want running processes on device , iterate on them. try use getapplicationinfo().processname context, unfortunately return same string, while solution in link above return: mypackage, mypackage:myservice. don't need processname @ first place, solution determine when oncreate method called ordinary launch , when myservice launch. may can done applying kind of tag or label somewhere, didn't find how it. you can use code process name: int mypid = android.os.process.mypid(); // process id inputstreamreader reader = null; t...

Does Go has out of the box priority queue? -

does go has out of box priority queue (the 1 can import module , start using python's priority queue )? i know priority queues implemented using heap data structure , go has heap package , suggests how use implement queue (in example (priorityqueue) ), can grab , use. my question recommended way this, or there out of box priority queue package failed find? quoting wikipedia: a priority queue abstract data type regular queue or stack data structure, additionally each element has "priority" associated it. [...] while priority queues implemented heaps, conceptually distinct heaps. priority queue abstract concept "a list" or "a map"; go provides basic data structures used in applications leave implementation of more specialized data structures programmer. example, go map can used trivially implement set. the example link uses slice []*item represent more abstract type heap.interface , (even more abstract) type priorityqueue ....

iOS (Xcode 6.2) Paypal (2.11.0) integration - 64 duplicate symbols for architecture arm64 -

i have integrated paypal 2.11.0 in ios app (for ios 7 , 8). paypal working fine when try distribute app (on archive) showing linker error "64 duplicate symbols architecture arm64". how fix it. valid architecture armv7,armv7s,arm64 duplicate symbol l034 in: /users/rajkumar/desktop/thrillcity 2 2/libpaypalmobile.a(paypalpaymentviewcontroller.o) /users/rajkumar/desktop/thrillcity 2 2/libpaypalmobile.a(pppaymentmethodcell.o) duplicate symbol l035 in: /users/rajkumar/desktop/thrillcity 2 2/libpaypalmobile.a(paypalpaymentviewcontroller.o) /users/rajkumar/desktop/thrillcity 2 2/libpaypalmobile.a(pppaymentmethodcell.o) duplicate symbol l036 in: /users/rajkumar/desktop/thrillcity 2 2/libpaypalmobile.a(pp2faviewcontroller.o) /users/rajkumar/desktop/thrillcity 2 2/libpaypalmobile.a(pppaymentmethodcell.o) duplicate symbol l037 in: /users/rajkumar/desktop/thrillcity 2 2/libpaypalmobile.a(pp2faviewcontroller.o) /users/rajku...