Posts

Showing posts from July, 2011

php - Is there a setMethods() Equivalent in Mockery for Mocking Chained Methods -

i mocking chain of methods. can work fine phpunit's mockbuilder; however, wondering if there cleaner way mock them in mockery. my current code looks like: $this->repositorymock = $this->getmockbuilder('repository') ->setmethods(array('method1', 'method2', 'method3')) ->getmock(); $this->repositorymock->expects($this->any()) ->method('method1') ->will($this->returnself()); $this->repositorymock->expects($this->any()) ->method('method2') ->will($this->returnvalue(true)); $this->repositorymock->expects($this->any()) ->method('method3') ->will($this->returnvalue(true)); setmethods won't work when using mockery::mock, following code replacing setmethods mockery's version: $this->repositorymock = mockery::mock('repository') ->setmethods(&#

java - How to generate unique random numbers? -

i trying solve problem.i have define array 5 elements on , define random generator method 3 defined integersi1,i2,i3 different each other.so when variables generated have different .i hope clear.can please me ,or suggestion welcome. import java.util.*; public class array { public static void main(string[] arg) { int[] v = { 1, 2, 3, 4, 5 }; displayarray(v); array n = new array(); n.randomgenerator(); } private static void displayarray(int[] arr) { (int x : arr) system.out.print(x + " "); system.out.println(); } public int[] randomgenerator() { int[] = new int[3]; int i1; int i2; int i3; (int = 0; < a.length; i++) { a[i] = (int) (math.random() * 5); } i1 = a[0]; i2 = a[1]; i3 = a[2]; if (i1 != i2 && i2 != i3 && i1 != i3) { system.out.println(i1 + "," +

c - Is FLT_RADIX ever not 2 in c11 for modern general purpose computers? -

that's pretty question in title. seems totally unnatural else used. in researching found there historical examples of hardware support base 10, more modern examples of ibm power6 , system z9. in these cases, not know if flt_radix 10 on mainstream c compilers. particular concern writting code application ever ran on general purpose computers, , know if can statically assert "flt_radix==2" without serious concern, how statically asserting "!(unsigned char)256". annex f, "optional" part of c standard that's non-optional serious implementation floating point used, requires ieee single , double precision (binary32 , binary64) float , double , respectively, flt_radix should 2. on systems new decimal float stuff supported, it's separate extended type; flt_radix==10 not used it.

javascript - how to stop a fixed input at the top of a page from making the ipad browser scroll up on focus -

i have responsive site top navigation fixed scroll down age header stay @ top edge of browser. in header search input. on iphones , ipads, when user taps in field page scroll top. i want stop because user decides not search , taps out of search field, should bee left off versus @ top of page. i have found articles using overflows on scrollable divs, not case plain page. have anchor book marks allows user go sections of page, , lots of home page content. want user able drag way down page, or click on anchor. have ability click search , not have page zip top. how go javascript have tried preventdefault on focus of field no luck. any appreciated. thanks jeff

Google Form Responses in a Notification Email -

i'm using form notifications add-on in google form. i've edited code.gs , creatornotification.html files , works fine - when google form submitted email. i'm trying of fields form submission email. edits i've added below, email notification stops working. in code.gs script have: function sendcreatornotification() { var form = formapp.getactiveform(); var settings = propertiesservice.getdocumentproperties(); var responsestep = settings.getproperty('responsestep'); responsestep = responsestep ? parseint(responsestep) : 10; function onformsubmit(e) { //get information form , set variables var first_name = e.value[2]; // if total number of form responses multiple of // response step setting, send notification email(s) form // creator(s). example, if response step 10, notifications // sent when there 10, 20, 30, etc. total form responses // received. if (form.getresponses().

jquery - Matching rotating highlighted arrow divs -

using images in custom javascript jquery code display on page you can through plugin using dots property. i'm aware doesn't work initial slide. have wait go next slide work. http://codepen.io/anon/pen/gbzeaz $(function() { $('.banner').unslider( { speed: 500, // speed animate each slide (in milliseconds) delay: 5000, dots:true, complete:function () { var index = $('#hp-banner .dot.active').index (); $('#hp-banner-right li').removeclass ('active').eq (index).addclass ('active'); } } ); }); enabling dots add dots slider can click go specific slides. current dot have active class. can use complete callback find out index active dot is, give corresponding banner link appropriate class. i found method in issue. https://github.com/idiot/unslider/issues/168

http - Capture the URI, resource name,as seen in Developer Tools, from GET POST request method in Java -

i doing part of enhancing selenium webdriver script. have tried using httpclient java , lot of other things not able anywhere. please help! ths scenario: after action performed in webpage button click, get/post methods can seen in developer tools in chrome. i have taken example of google here. what need here collect resource names until resource appears (if open developer tools in chrome , navigate google.com , under network tab on leftmost column see tia.png , example). there 2 things should achieved: ensure resource loaded make sure page loaded (all / post methods have been transferred) before other action taken. the httpclient, httpurlconnection capture 1 request, page sends lot of requests. how capture of them? by using http apache client , can use :- solve problem, can response code "response.getstatusline().getstatuscode()" , check expected response code , can play outcome of response. uri url = new uri("string uri"); defaultht

javascript - How to make angular display an empty <p> tag? -

i'm using ng-repeat , trying create paragraph element has specific border on hovering, when element empty. however, when paragraph element empty, there's no hover functionality. , "inspect element" tool not showing presence of paragraph tag @ all. is there workaround? thank you. js: var members = [ {name: "john", dod: "december 8, 1980"}, {name: "paul", dod: ""}, {name: "george", dod: "november 29, 2001"}, {name: "ringo", dod: ""} ]; html: <table> <tr ng-repeat='member in members'> <p class='hoveroutline' ng-repeat="member in members"> {{member.dod}} </p> </tr> </table> css: .hoveroutline:hover{ border: 2px solid black; } you put p element inside tr . invalid markup, , browser sure refuse render expect. use td (or th ) direct child of tr . you should rethink layout: may

In this Java class hierarchy, how to use Generics so that type casts are unnecessary? -

suppose have 2 classes called realnumber , intnumber , , method called plus : public class realnumber<s extends realnumber> { public s plus(s realnumber) { ... } } public class intnumber extends realnumber<intnumber> { } when using plus method compiler warnings , errors: realnumber x = new realnumber(); intnumber y = new intnumber(); realnumber sum1 = x.plus(x); // warning: unchecked call 'plus(s)' member of raw type 'realnumber'. realnumber sum2 = x.plus(y); // warning: unchecked call 'plus(s)' member of raw type 'realnumber'. realnumber sum3 = y.plus(x); // error: plus (intnumber) in realnumber cannot applied (realnumber). realnumber sum4 = y.plus(y); // works fine. intnumber sum5 = y.plus(x); // error: plus (intnumber) in realnumber cannot applied (realnumber). intnumber sum6 = y.plus(y); // works fine. to fix this, modify plus method, follows: public <t extends realnumber> s plus(t

java - How do I set the Content-Type on a camel-restlet producer request? -

i need consume simple rest service, implementation breaks if request goes out content-type: application/x-www-form-urlencoded. need set "application/json"or faced status 415. i using restlet producer component because used throughout , far had hit sweet spot between functionality , simplicity. far. anyway, trying set header in route seems have 0 effect , content-type of request remains application/x-www-form-urlencoded. here test code: from("direct:getimg") .setheader(restletconstants.restlet_login, simple("admin")) .setheader(restletconstants.restlet_password, simple("admin")) .setheader(exchange.content_type, simple("application/json")) .to("restlet:http://requestb.in/12sowlx1?restletmethod=get&throwexceptiononfailure=false") i missing something, cant find example. can point right way it? thanks! you should call processor before call restlet , set

debugging - loading a file texture in FIRST frame of a feedback loop with swapped buffers in three.js -

i'm working on website in three.js using several feedback shader loops (texture pingpong). when visits site, loop should continue point (depending on when he/she visits). achieve intend load picture (eg jpeg) server in first frame, render pingpong buffers , continue normal feedback loop frame 2 onwards. here's stripped down version of problem, feedback function add small value color of pixel in previous frame. <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>feedbacktest</title> <style>canvas { width: 100%; height: 100%; }</style> </head> <body> <!-- main 3 includes --> <script src="js/three.min.js"></script> <script src="js/detector.js"></script> <!--------------------> <!-- shaders --> <!-------------------->

batch file - Using a loop to rar multiple subfolders in a main folder -

i have main folder 3 subfolders ... c:\users\admin\folder folder1 folder2 folder3 i want batch script grabs first subdirectory folder1 , copy location, example c:\temp\folder , winrar starts archive folder1 . after copying folder1 location can deleted in main folder. after winrar finished archiving folder1 can deleted in c:\temp\folder . .rar files remain. then script starts new folder2 , same folder1 . so far have , not know how implement above. "c:\program files\winrar\rar.exe" -ep1 -mt5 -v50m -r -df "name-of-the-rar-file" "c:\users\admin\folder\*.*" open command prompt window, type , execute for /? , read output command. option /d explained on first page executing commands on each subdirectory of directory. the batch file below archives each subfolder in c:\users\admin\folder using console version of winrar command m (move = archive , delete on success) instead of command a switch -df . @echo off /d %%f in

spatial - Confusion about Markov random fields in the mgcv package in R -

in order implement spatial analysis, tried simple markov random field smoother in example in mgcv package in r, manual here: https://stat.ethz.ch/r-manual/r-devel/library/mgcv/html/smooth.construct.mrf.smooth.spec.html this example tried: library(mgcv) data(columb) ## data frame data(columb.polys) ## district shapes list xt <- list(polys=columb.polys) ## neighbourhood structure info mrf b <- gam(crime ~ s(district,bs="mrf",xt=xt),data=columb,method="reml") however, when took @ estimated coefficients in b$coefficients, there 48 estimates markov random field smoother: > b$coefficients (intercept) s(district).1 s(district).2 s(district).3 s(district).4 35.12882390 -10.96490165 20.99250496 16.04968951 10.49535483 s(district).5 s(district).6 s(district).7 s(district).8 s(district).9 16.56626217 14.55352540 17.90043996 -0.60239588 13.41215603 s(district).10 s(district).11 s(district).12 s(district).13 s(

ruby on rails - Faraday::ConnectionFailed: connection refused while saving to mongo database -

hello ror + mongo(mongoid) application here what immediate error msg? faraday::connectionfailed: connection refused: localhost:9200 when happen? when try save user instance in console user.create!(email:"kevin@gmail.com",password:"helloworld123",password_confirmation:"helloworld123") i appreciate or input. have great day & reading. below details of related code 1) gemfile source 'https://rubygems.org' group :development, :test gem 'rspec-rails', '~> 3.1.0' gem 'factory_girl_rails', '~> 4.4.1' gem 'spring', '~> 1.2.0' end group :test gem 'faker', '~> 1.4.3' gem 'capybara', '~> 2.4.3' gem 'database_cleaner', '~> 1.3.0' gem 'launchy', '~> 2.4.2' gem 'selenium-webdriver', '~> 2.43.0' end gem 'geocoder', '~> 1.2.7' gem 'figaro', '1.0

datetime - Convert utc time to system current time using ruby -

how convert utc time current system using ruby? i'm using time.now.utc.iso8601 utc format in ruby, want convert system current time using ruby. can me sample code? the ruby time class has getlocal method: t = time.now.utc => 2015-03-21 00:29:47 utc t.getlocal => 2015-03-20 20:29:47 -0400 see here: http://ruby-doc.org/core-2.2.0/time.html#method-c-local

Before PHP session timeout run script -

when user leaves website, , right before session times out able run script send me email. i have looked few different ways, example, using javascript. found these methods unreliable. i came across session_set_save_handler not sure if should use or if there better method of doing this. thanks help. tutorial on how can awesome.

python - Pypi & PyPi Test Could not find any downloads that satisfy the requirement -

i trying release software through pypi, , while pip can search library, unable download library. i suspect issue setup.py file, doclines = __doc__.split("\n") open('requirements.txt') f: required = f.read().splitlines() setup( name='directory_caching', packages=find_packages(), version='1.0.6', description = doclines[0], long_description = "\n".join(doclines[2:]), author='benjamin schollnick', author_email='benjamin@schollnick.net', license="mit", maintainer='benjamin schollnick', maintainer_email='benjamin@schollnick.net', platforms=["any"], url='https://github.com/bschollnick/directory_caching', download_url = 'https://github.com/bschollnick/directory_caching/tarball/1.05', #install_requires=required, #requires=required, keywords = ['caching', 'files', 'directories', 'sc

android - How save state of checkbox? if is enabled or disabled -

i'm making app have lot of checkbox. wanted save states of these save if these checked, want save if enabled or disabled, since checkbox active states other checkbox. how can that? ... if (view.equals(contador11)){ if(contador11.ischecked()){ contador14.setenabled(true); }else{ contador14.setenabled(false); } } if (view.equals(contador12)){ if(contador12.ischecked()){ contador13.setenabled(true); contador26.setenabled(true); }else{ contador13.setenabled(false); contador26.setenabled(false); } } if (view.equals(contador7)){ if(contador7.ischecked()){ contador15.setenabled(true); }else{ contador15.setenabled(false); }

android - RecyclerView predictive item animations not working (APPEARING) -

i have recyclerview gridlayoutmanager (support lib v7). update adapter , make notifyitemmoved. if item source position on screen , destination position on screen - "move animation" played. in case if item @ position out of screen(position 1000, or other far viewport) , moved viewport appear "fade in animation". looks predictive item animations not working despite on fact supportspredictiveitemanimations() returns true. doing wrong? should override methods enable it? i reading source code of recyclerview, , in javadoc of dispatchlayout method written like: persistent views moved ({@link itemanimator#animatemove(viewholder, int, int, int, int)}) removed views removed ({@link itemanimator#animateremove(viewholder)}) added views added ({@link itemanimator#animateadd(viewholder)}) disappearing views moved off screen appearing views moved on screen nevertheless itemanimator doesn't distinguish added , appearing. possible fix predictif

android - How to know pre Uninstall of my application -

i using below code running background in service pre uninstall event calling applications, don't require. want event application. example: application "a" other applications "b","c".... when tries uninstall "a" application want pre uninstall event. but current code returning pre uninstall event other applications "b", "c"..... // info running task list<activitymanager.runningtaskinfo> taskinfo = mactivitymanager .getrunningtasks(10); string activityname = taskinfo.get(0).topactivity .getclassname(); log.d("topactivity", "current activity ::" + activityname); if (activityname .equals("com.android.packageinstaller.uninstalleractivity")) { // user has clicked on uninstall button under manage // apps settings

java - XMPP Connection with Smack 4.1 on Android Studio -

i trying xmpp connection smack 4.1.0 rc1 https://github.com/igniterealtime/smack followed guide https://github.com/igniterealtime/smack/wiki/smack-4.1-readme-and-upgrade-guide importing gradle. source code: package com.example.xmpp_app; import android.os.bundle; import android.support.v7.app.actionbaractivity; import android.view.menu; import android.view.menuitem; import org.jivesoftware.smack.abstractxmppconnection; import org.jivesoftware.smack.smackexception; import org.jivesoftware.smack.xmppexception; import org.jivesoftware.smack.tcp.xmpptcpconnection; import org.jivesoftware.smack.tcp.xmpptcpconnectionconfiguration; import java.io.ioexception; public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // create configuration new connection xmpptcpconnectionconfiguration.builder configbuilder

assembly - Embedded C: AVR; variable in header cannot be evaluated in main -

Image
thank taking time read. problem i'm seeing i have: main.h that declares: uint8_t u_newvar i have foo.h that writes: extern uint8_t u_newvar the application sits in infinite while loop in main.c until isr occurs. in foo.c, said isr calls function within foo.c. in function (foo_function() if will): 0x01 written u_newvar. finally, after returning interrupt , infinite while, there single "if" statement: while(1){ if(u_newvar == 0x01){ uarttx_sendarray(st_uartrx_messagecontents->u_command, (sizeof st_uartrx_messagecontents->u_command)); uarttx_sendbuttonpressdata(st_uartrx_messagecontents->u32_value); u_newvar = 0x00; } } however, application never enters if. "if" block work if in foo.c, after u_newvar = 0x01; line. stuff tried i looked @ compiled assembly, , found kind of stumps me. if @ "if" in main, see: so loads value address: 0x011d sram, can confirm 0x01. then "cpi&q

Add prefix to each line of output with sed -

okay after googling minutes seems regular way prefix each line of output sed but error don't understand. what mean , how can fix this? $ sed 's/^/#/' test.txt sed: -e expression #1, char 0: no previous regular expression what test.txt looks - it's test ### test.txt b c d e f g h oh yeah.. version $ sed --version gnu sed version 4.2.1 copyright (c) 2009 free software foundation, inc. free software; see source copying conditions. there no warranty; not merchantability or fitness particular purpose, extent permitted law. below code same using capturing group won't touch blank lines. sed 's/^\(.\)/#\1/' test.txt try if want add # @ start of blank line also. sed 's/^\(.\|\)/#\1/' file example: $ cat f b $ sed 's/^\(.\)/#\1/' f #a #b $ sed 's/^\(.\|\)/#\1/' f #a # #b

Meteor Iron:Router Template not Rendering -

i have main page lists few text items ("ideas"), clickable links. clicking on them should take page can edit them. here's html: <head> <title>ideas</title> </head> <body> </body> <template name="ideas"> <ul> {{#each ideas}} {{> idea}} {{/each}} </ul> </template> <template name="idea"> <li><a href="/idea/{{_id}}">{{text}}</a></li> </template> <template name="showidea">' <div class="editable" contenteditable="true">{{text}}</div> </template> i've added iron:router project allow moving between pages. here's javascript: ideas = new mongo.collection("ideas"); if (meteor.isclient) { router.route('/', function() { this.render('ideas'); }); router.route('/idea/:_id', func

c# - Int won't increment by 1 -

i'm trying increment value of int: counter 1 each time stakebtn pressed. here's i've tried far: private void stakebtn_click(object sender, eventargs e) { int counter = 0; counter++; currentstakes.text = counter.tostring(); } however, works 1 time- currentstakes label not go above 1. is able see going wrong? obviously, increase 1 time, declare outside click, int counter = 0; private void stakebtn_click(object sender, eventargs e) { counter++; currentstakes.text = counter.tostring(); }

html - Ruby on Rails redirect_to method -

let's have line in controller redirect_to "/sessions/try", provider: 5 and try.html.erb <h1>try</h1> <%= provider %> obviously doesn't work, how 'provider' show in html file? send provider params redirect_to "/sessions/try?provider=5" than at, try.html.erb <h1>try</h1> <%= params[:provider] %>

java - How to extract noun phrases from the parsed text -

i have parsed text constituency parser copy result in text file below: (root (s (np (nn yesterday)) (, ,) (np (prp we)) (vp (vbd went) (pp (to to).... (root (frag (sbar (sbar (in while) (s (np (prp i)) (vp (vbd was) (np (np (ex... (root (s (np (nn yesterday)) (, ,) (np (prp i)) (vp (vbd went) (pp (to to..... (root (frag (sbar (sbar (in while) (s (np (nnp jim)) (vp (vbd was) (np (np (.... (root (s (s (np (prp i)) (vp (vbd started) (s (vp (vbg talking) (pp..... i need extract nounphrases (np) text file. wrote following code extract first np each line. however, need extract noun phrases. code is: public class nounphrase { public static int findclosingparen(char[] text, int openpos) { int closepos = openpos; int counter = 1; while (counter > 0) { char c = text[++closepos]; if (c == '(') { counter++; } else if (c == ')') { counter--; }

node.js - meanjs routes tests not working -

i using meanjs 0.4.0 branch. , while performing routes tests gives error timeout of 2000ms exceeded . error comes code: before(function(done) { var app = express.init(mongoose); agent = request.agent(app); done(); }); i think problem express server not running. in there master version code is: var app = require('../../server'), agent = request.agent(app); they have exported app object in server.js in route tests gets app instance. in 0.4.0 branch have not exported app object. how solve problem

c - intro to x86 assembly -

i'm looking on example on assembly in csapp (computer systems - programmer's perspective 2nd) , want know if understanding of assembly code correct. practice problem 3.23 int fun_b(unsigned x) { int val = 0; int i; ( ____;_____;_____) { } return val; } the gcc c compiler generates following assembly code: x @ %ebp+8 // i've gotten far 1 movl 8(%ebp), %ebx // ebx: x 2 movl $0, %eax // eax: val, set 0 since eax return // value stored , val being returned @ end 3 movl $0, %ecx // ecx: i, set 0 4 .l13: // loop 5 leal (%eax,%eax), %edx // edx = val+val 6 movl %ebx, %eax // val = x (?) 7 andl $1, %eax // x = x & 1 8 orl %edx, %eax // x = (val+val) | (x & 1) 9 shrl %ebx shift right 1 // x = x >> 1 10 addl $1, %ecx // i++ 11 cmpl $32, %ecx // if < 32 jump loop 12 jne .l13 there similar post on same problem solution, i'm looking more of walk-through , explanation of assembly code line line. you seem have mea

Powershell command to compare 2 excel tabs -

can pls point me example can compare contents of 2 excel tabs , writing result in 3rd tab using powershell. pls check link you can column link compare string can use $a="soheil" $b="hidd3n" $a -eq $b false very simple read link , use object excel , compare them each other