Posts

php - Is there a way to specify only some optional function args? -

i have function public function test($arg1, $arg2 = "a", $arg3 = "b") is there way call specifying $arg1 , $arg3 leaving $arg2 default value? function test($arg1, $arg2 = "a", $arg3 = "b") { if (is_null($arg2)) $arg2 = "a"; return $arg1.' '.$arg2.' '.$arg3; } echo test(1, null, 3); output: 1 3 will point out in javascript quite common: function test (input, callback) { $.post( "example.com/endpoint", input, function(err, data) { if (error || response.statuscode !== 200) { callback(true, response) } callback(null, data) }) } test({ 'id': 1, 'name': 'mary' }, function (err, data) { if (err) { console.log.error('error!!') console.log(data) } console.log.info(data) })

java - How to log everything in 'when' part of Drools rule? -

i have log responsible fire rule in drools objects, conditions etc. i able objects using agendaeventlistener , writing below code in beforeactivationfired method of it. @override public void beforeactivationfired(beforeactivationfiredevent event){ event.getactivation().getobjects(); } but how conditions , methods called on object? have object used global variable used validate values against values in cache i.e. in when part of rules different methods on global object(have hundreds of methods in it) called. now want have information on methods called can log information before hand because after execution values in cache might change. for example - if in when part below condition there wish know condition value of both sides in condition i.e. value of $val $cache.getcurrenttimestamp()(please note method called on cache not known beforehand). $val : timestamp, $val == $cache.getcurrenttimestamp() how can achieve task?

utf 8 - Mystery UTF-8-like encoding -

i've been given file supposedly in utf-8, there weird encodings of non-english characters. example, in mystery encoding, hangul string 한국경북영덕군강구면 is encoded as: 0xed959c 0xeab5ad 0xeab2bd 0xebb63f 0xec983f 0xeb3f95 0xeab5b0 0xeab095 0xeab5ac 0xeba9b4 (differences in bold) rather standard utf-8: 0xed959c 0xeab5ad 0xeab2bd 0xebb681 0xec9881 0xeb8d95 0xeab5b0 0xeab095 0xeab5ac 0xeba9b4" i'm seeing same phenomena cyrillic , chinese characters--some characters have same encoding utf-8, different. garbled characters have same byte width non garbled ones , i've verified aren't part of extension set. also, i've verified not java "modified utf-8". any other ideas may be? btw: don't have access code or people wrote file. also, i'm on mac 10.11.6 in case has it. your example string consists of utf-8, byte values (namely x81 , x8d) replaced ascii question mark ? (x3f). plausible explanation example ...

go - Twitter oauth golang getting Error "code":32,"message":"Could not authenticate you." -

i trying implement signing in twitter account in golang. first step in trying request token. reference used mrjones's code available @ below link. https://github.com/mrjones/oauth/blob/master/examples/twitterserver/twitterserver.go i getting following error. please let me know going wrong: {"errors":[{"code":32,"message":"could not authenticate you."}]} var twitterconf = &twitterconfig{ clientid: " consumer key", clientsecret: "my consumer key secret", redirecturl: "http://localhost:8080/oauth/twitteroauth2callback", endpoint: serviceprovider{ requesttokenurl: "https://api.twitter.com/oauth/request_token", authorizetokenurl: "https://api.twitter.com/oauth/authorize", accesstokenurl: "https://api.twitter.com/oauth2/token", }, } func handletwitterlogin(res http.responsewriter, req *http.request, _ httprouter.para...

android - Can't build recovery image with AOSP 4.2.2 -

i trying build recovery.img aosp 4.2.2 following commands: cd myandroidsrc source build/envsetup.sh lunch make recoveryimage -j8 but keep running following error: find: `src': no such file or directory ... lot of "product_copy_files /frameworkds/base/data/.. .ogg ignored" messages ... cp -f /boot.img /device/myvendor/mydevice/boot/ cp: cannot stat `/boot.img': no such file or directory make: *** [out/target/product/mydevice/boot.img] error 1 make: *** deleting file `out/target/product/mydevice/boot.img' make: *** waiting unfinished jobs.... i tried build boot image with: make bootimage but results in same error @ make recoveryimage call. missing make call here or file structure wrong ? are using prebuilt boot.img if yes check path properly. cp -f /boot.img /device/myvendor/mydevice/boot/ can see above root of device tree should have boot.img being copied.

jquery datatables custom ajax client -

i have custom javascript client works remote api using ajax. suppose myapiclient below: var myapiclient = function() { this.invoke = function (config, callback) { // ... } } how can configure jquery datatables can use myapiclient rather built-in ajax working jquery datatables provides internally? that is, suppose loading remote data, need call client way: var client = new myapiclient(); client.invoke({ url: '/api/app/v1/some-entity/all', function(result, err) { // ... } }); thank already use ajax option define function retrieve data through own ajax call. as function, making ajax call left allowing complete control of ajax request. indeed, if desired, method other ajax used obtain required data, such web storage or firebase database. when data has been obtained data source, second parameter ( callback here) should called single parameter passed in - data use draw table. for example: $('#example').datatable( {...

java - Spring boot with Spring Security and custom database -

sorry in advance bad english.. since have changed database configuration don't succeed log me on application. using spring security. before making changes worked. i have 2 entities : user.java userrole.java user.java package betizy.models; //imports @entity @table(name = "use_user") public class user { @id @generatedvalue(strategy = generationtype.auto) @column(name="use_id") private long id; @notnull @column(name = "use_username") private string username; @notnull @column(name = "use_password") private string password; @notnull @column(name = "use_email") private string email; //getters , setters } userrole.java package betizy.models; //imports @entity @table(name = "usr_user_role") public class userrole { @id @generatedvalue(strategy = generationtype.auto) @column(name="usr_id") private long id; @manytoone @joincolumn(name = "usr_use_id") private user user; @notnul...

excel vba - UserForm Close button fails after form launched for second time -

i have userform , a, command button opens userform b using below code: private sub cmd_click() me.hide b.show end sub b, when closed via x button, runs following: private sub userform_terminate() unload me a.show end sub after: opening b (from a) closing b , returning and opening b again the close button on b ceases work. userform menu form leads several others, navigating , forth between menus pretty basic requirement. behaviour reproducible every form linked a, tertiary forms open those. given target demographic of older generation, want userforms intuitive use, means preserving regular close button functionality. does have info on this? may google-fu lacking, can't seem find has had same issue. input @ stage appreciated! use variable refer 2nd userform in first gives greater control on second forms status - can unset variable after have closed 2nd form , returned event handler instantiated in first place. guarantees each tim...

c++ - Data File Handling - find count of word in file -

i have homework question: write function in c++ count presence of word ' do ' in text file. what have tried: i tried first search word ' d ' in text file, search ' o ' if present after it. #include <iostream> #include <fstream> using std::fstream; using std::cout; using std::ios; int main() { char ch[10]; int count=0, a=0; fstream f; f.open("p.txt", ios::in); while(!fin.eof()) { fin.get(ch) if (ch[a]=='d') { if ((a++)=='o') count++; } a++; } cout << "the no of do's is" << count; f.close(); } but idea useless. cannot think of other ideas. love have hint regarding in 2 scenarios: 1.count word 'do' independently existing. 2.count word 'do' present anywhere in text. this data file handling question. the algorithm follows have. structure while-loop ...

evaluation - Controlling Prolog variable value selection -

inspired an earlier question tried implement enumerate possibilities boolean expression. however, i'm having trouble variable choice. here's intended outcome: ?- eval(x^y, r). r = 0^0; r = 0^1; r = 1^0; r = 1^1; no. here's code: :- op(200, yfx, ^). split(v, r) :- var(v), r = 0. split(v, r) :- var(v), r = 1. split(x ^ y, xp ^ yp) :- split(x, xp), split(y, yp). this doesn't want simple case: ?- split(y, r). r = 0 ; r = 1 ; y = _g269^_g270, r = 0^0 ; y = _g269^_g270, r = 0^1 ; y = _g269^ (_g275^_g276), r = 0^ (0^0) ; y = _g269^ (_g275^_g276), r = 0^ (0^1) ; y = _g269^ (_g275^ (_g281^_g282)), r = 0^ (0^ (0^0)) . so, can see problem here, on way through split(y, yp) prolog has exhausted first 2 clauses, winds in split(x^y, ...) again, unifying y x'^y' , essentially. not sure need close off path except @ outset have structure ^/2 . i'd work nested structures, can't eliminate recursive processing of branches. edit : without operators ...

javascript - i am storing an array in sessionstorage and retrieving through sessionstorage. I am getting the data but i am unable to repeat the array -

var x=[ { "xyz":1, "abc":"dashboard", "def":0, }, { "xyz":2, "abc":"facility", "def":0 }] this original data.then storing data using session storage below--- $window.sessionstorage.setitem("useritems", json.stringify(x)); then retrieving data using sessionstorage--- $window.sessionstorage.getitem("useritems") i getting data correctly-- [{ "xyz":1, "abc":"dashboard", "def":0, }, { "xyz":2, "abc":"facility", "def":0 }] but unable repeat data , displaying data. you need wrap json.parse() : json.parse($window.sessionstorage.getitem("useritems"));

math - MATLAB: ways to compute the settling time of a signal in Matlab -

i compute settling time of signal y in matlab. should give amount of time required before signal reaches steady state error |y(t)-y_{ss}| smaller absolute value x , stays smaller x future times. i tried use matlab function stepinfo, defines value x "a fraction 2% of peak value future times" , not want. is there way adjust matlab function stepinfo, or way code myself?

c# - How to correlate data from datatables -

i have 3 datatables contains data follows. posting small part of these datatables. first datatable dtnc rnlidentifier(bsc) userlabel 3 test_123 5 fasi_123 6 kira_123 second datatable dtsite rnlsupportingid sitename {bsc 3,btsrdn 68} vm_ao_3980 {bsc 3,btsrdn 69} vm_ao_3981 {bsc 5,btsrdn 70} vm_ao_3975 {bsc 5,btsrdn 71} vm_ao_3976 {bsc 6,btsrdn 74} vm_ao_3233 {bsc 6,btsrdn 75} vm_ao_3234 third datatable dtcell cellmanager cellname {bts{bsc 3,btsrdn 68}} am_an_1000 {bts{bsc 3,btsrdn 68}} am_an_1001 {bts{bsc 6,btsrdn 74}} am_al_1200 {bts{bsc 3,btsrdn 68}} am_an_1201 the relation 1 row of dtnc contains many dtsite , 1 row of dtsite contains many dtcell .now if want push cell information in database cellname,sitename,userlabel ,but don't know how correlate them. if have 2 ...

python - Scraping using Beautiful Soup leads to error only in a particular section (NullType object encountered) -

i'm trying list of injuries of particular team (liverpool in case) following website http://www.physioroom.com/news/english_premier_league/epl_injury_table.php it works fine teams(swansea), exits following errors (liverpool, everyon) typeerror: can't convert 'nonetype' object str implicitly here code using. from bs4 import beautifulsoup import urllib.request url = "http://www.physioroom.com/news/english_premier_league/epl_injury_table.php" html = urllib.request.urlopen(url).read() soup = beautifulsoup(html, "html.parser") #lp = soup.find(alt="liverpool away shirt").parent.parent.parent.next_sibling.next_sibling lp = soup.find(alt="swansea city away shirt").parent.parent.parent.next_sibling.next_sibling player_info = "" player_list = [] while true: if(lp.has_attr('id')): break else: tdlist = lp.find_all('td')# player_info = tdlist[0].string+"\t...

php - how to restrict registered user from trying to vote again -

this question has answer here: how restrict registered user trying vote twice [closed] 1 answer i'm new php coding , website designing. i'm trying develop online voting system, registered users only, allowed vote. have done , it's working fine, need after user have logged out, how can make user not able login again , vote twice? or how can redirect user second time? you can manage user taking field in database table. applying condition on field @ time of login able restrict user had given vote.

c# re-throw exception in a method designed to handle exceptions and preserve stacktrace -

i want write method handle exceptions , called inside catch block. depending on type of exception passed, exception either passed inner exception of new exception or re-thrown. how preserve stack trace in second case ? example : public void testmethod() { try { // can throw exception specific project or .net exception someworkmethod() } catch(exception ex) { handleexception(ex); } } private void handleexception(exception ex) { if(ex specificexception) throw ex; //will not preserve stack trace... else throw new specificexception(ex); } what not is, because pattern repeated in many places , there no factorization : try { someworkmethod(); } catch(exception ex) { if(ex specificexception) throw; else throw new specificexception(ex); } you need use throw without specifying exception preserve stack trace. can done inside catch block. can return handleexception w...

android - Repeating alarm is not working in marshmallow -

i using following code start service periodically whether app foreground or not . intent getalertintent = new intent(getapplicationcontext(), getalertalarmreceiver.class); pendingintent getalertpendingintent = pendingintent.getbroadcast(getapplicationcontext(), 0, getalertintent, 0); alarmmanager getalertmanager = (alarmmanager) getapplicationcontext().getsystemservice(context.alarm_service); getalertmanager.setinexactrepeating(alarmmanager.rtc_wakeup, system.currenttimemillis(), 10000, getalertpendingintent); the code receiver following public class getalertalarmreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { intent = new intent(context, getalertserviceintent.class); context.startservice(i); } } and , service public class getalertserviceintent extends intentservice { public getalertserviceintent() { super("getalertserviceintent"); } @override public voi...

Color-coded timeline plot in R -

i working on visualising user touch interactions within mobile application. plot them in one-dimensional timeline color-coded action type. i.e., 2 variables time (in ms, on x-axis) , type of touch (used color-code line). colors should able repeated. ideally plot this , , have found this previous question delivers similar, i'm wondering if there isn't better. is there other methods using r allow me this? i have workings of base r method. it's bit hacky, tweaking should work nicely. have removed reliance on data.table , timeline , , ggplot packages, opting using polygon function. df <- data.frame(set=c("x","y","z","x","y","z","x","y","z","x","y","z","x"), startdate=c(1380708900,1402963200,1420070400,1421280000,1410912000,1396310400,1397520000,1418860800,1404172800,1405382400,1395100800,1412121600,1413331200), ...

android parsing using php genrated JSON -

i have created php script , pick java im having trouble converting format can use. php <?php //pdo extension defines lightweight, consistent interface accessing databases in php. $db=new pdo('mysql:dbname=mydb;host=localhost;','root',''); //here prepare query analyzing, prepared statements use less resources , run faster $row=$db->prepare('select * drinks'); $row->execute();//execute query $json_data=array();//create array foreach($row $rec)//foreach loop { $json_array['drinks_id']=$rec['drinks_id']; $json_array['drink_name']=$rec['drink_name']; $json_array['description']=$rec['description']; //here pushing values in array array_push($json_data,$json_array); } //built in php function encode data in json format //print_r($json_array); echo json_encode($json_data,json_force_object); ?> json sample(each row accumative instead of being...

python - How to insert QWidgets in the middle of a Layout? -

Image
i'm using qt framework build graphical user interface. use qgridlayout position qwidgets neatly. gui looks this: my application regularly adds new widgets gui @ runtime. these new widgets not added @ end of qlayout, somewhere in middle. the procedure bit cumbersome. applied on figure above, need take out widg_c , widg_d , ... qgridlayout. next, add widg_x and widg_y , , put other widgets again. how remove widgets qgridlayout: for in reversed(range(mygridlayout.count())): self.itemat(i).widget().setparent(none) ### as long you're dealing small amount of widgets, procedure not disaster. in application display lot of small widgets - perhaps 50 or more! application freezes second while procedure ongoing, annoying user. there way insert widgets somewhere in qlayout, without need take out other widgets? edit: apparently solution qvboxlayout simple. use function insertwidget(..) instead of addwidget(..) . docs can found link: http://doc.qt.io/qt-5/qboxlayou...