Posts

Showing posts from April, 2010

c++ - Validation for error -

while developing personal library stumbled upon think error inside libstdc++6. because i'm quite sure library has been reviewed lot of higher skilled people came here validate finding , assistance on further steps. consider following code: #include <regex> #include <iostream> int main() { std::string uri = "http://example.com/test.html"; std::regex reg(...); std::smatch match; std::regex_match(uri, match, reg); for(auto& e: match) { std::cout<<e.str() <<std::endl; } } i have written regex parse url into protocol user/pass (optional) host port (optional) path (optional) query (optional) location (optional) i used following regex (in c++): std::regex reg("^(.+):\\/\\/(.+@)?([a-za-z\\.\\-0-9]+)(:\\d{1,5})?([^?\\n\\#]*)(\\?[^#\\n]*)?(\\#.*)?$"); this worked quite fine in online tester , msvc++ 2015 update 3 fails on build host host part ma...

json - Get information from a JavaScript object that has a number as an index -

this question has answer here: unable access json property “-” dash 1 answer how can retrieve information javascript object has numeric value index? "element_count": 69, "near_earth_objects": { "2016-10-29": [ ... ] i need access data inside "2016-10-29" array. i have no problem accessing other elements this: $.getjson(call, function(data1){ console.log(data1.element_count); }); like mix notation , retrieve sub-array element in property of json object : var data = { "element_count": 69, "near_earth_objects": { "2016-10-29": ["subelement1", "subelement2", "subelement3"], "2016-10-30": ["subelement11", "subelement12", "subelement13"] } }; console.log(data.near_earth_objects[...

xslt - xmlstarlet extract values from Office 365 XML Files -

i attempting extract ipv4 addresses , urls each product in office 365 portfolio http://go.microsoft.com/fwlink/?linkid=533185 . create input file updating firewall , proxy server rules. snippet xml file <?xml version="1.0" encoding="utf-8"?> <products updated="8/31/2016"> <product name="wac"> <addresslist type="ipv6"> <address>2a01:111:f406:8800::/64</address> <address>2a01:111:f406:400::/64</address> <address>2a01:111:f406:1c01::/64</address> <address>2a01:111:f406:9400::/64</address> <address>2a01:111:f406:2402::/64</address> <address>2a01:111:f406:a804::/64</address> <address>2a01:111:f406:b401::/64</address> <address>2620:1ec:c11::204</address> <address>2a01:111:202c::204</address> <address>2620:1ec:c11::205</address>...

Android app created by unity3d is more likely to crash after playing a video -

i'm creating android app can play videos , view models. decide use unity3d finish it. set 2 functions in several scenes , each scene has funciton. enter different scene, when want see different video or model. if see models, no matter how many models, can run successfully. if app more crashed when view models after see video(maybe 10m). use handheld.playfullscreenmovie() play videos in unity3d. error in android following. 11-05 22:33:51.589 14794-14807/? i/adreno: dequeuebuffer: dequeuebuffer failed 11-05 22:33:51.609 14794-14807/? w/adreno-gsl: : ioctl fd 29 code 0xc0140933 (ioctl_kgsl_timestamp_event) failed: errno 24 many open files 11-05 22:33:51.609 14794-14807/? w/adreno-gsl: : (1e, 14, 92844) fail 24 many open files 11-05 22:33:51.619 14794-14807/? e/surface: dequeuebuffer: igraphicbufferproducer::requestbuffer failed: -2147483646 it maybe there may open files? there video , should has been removed memory when change scene in unity3d. if have ideas it...

java - Connecting arduino to an android app which uses libgdx (using Bluetooth) -

so i'm trying little unusual, it's fun. have game created using libgdx, consists of ship can shoot. want use external push buttons move it. push buttons send signals arduino, in turn sends them hc-05 bluetooth module. i'm doubtful android side of things. did following: because i'm working on libgdx created interface called bluetoothdude, 3 methods setbluetooth() (which set bluetooth particular platform),string whatisthemessage() (which tell what's been sent phone), , boolean isactive(), know if bluetooth active of course. the maingame receive bluetoothdude particular classes ship have access message , able react it. then did particular implementation of bluetooth android, in setbluetooth() followed guide closely: https://developer.android.com/guide/topics/connectivity/bluetooth.html i'm sure connecting properly, because when creates socket can print "connection success hc-05" (it print if method creates sockets, called btconnect() returns ...

Prolog dependencies: include vs ensure_loaded -

i'm writing program in prolog. have 3 files: class.pl, main.pl, utilities.pl. class.pl: :- include('utilities.pl'). main.pl: :- include('utilities.pl'). :- include('class.pl'). when compile main.pl warning "clauses ... not together". however, if switch include ensure_loaded, doesn't give me warning anymore. i'm assuming has circular dependencies , predicates in utilities.pl being rewritten? ensure_loaded work #pragma once in c++? but i've read somewhere include includes code, while ensure_loaded consults it? if clear things me , let me know should doing, i'd grateful :) roughly, directive include/1 means #include , ensure_loaded/1 means #include include guard. #include-once . well, roughly. you warning because utilities.pl included twice. here relevant parts standard iso/iec 13211-1:1995: 7.4.2.7 include/1 if f implementation defined ground term designating prolog text unit, prolo...

algorithm - 3n+1 Optimization Idea for Larger Integers -

i got book "programming challenges" skiena , revilla , surprised when saw solution 3n+1 problem, brute forced. it's algorithm generates list of numbers, dividing 2 if , multiplying 3 , adding 1 if odd. occurs until n=1 reached, base case. trick find maximum length of list between integers , j in problem ranges between 1 , 1,000,000 both variables. wondering how more efficient (if so) program dynamic programming. basically, program 1 pass on first number, i, find total length, , check each individual number within array , store associated lengths within hashmap or other dictionary data type. for example: let's = 22 , j = 23 for 22: 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 this means in dictionary, structure store (22,16) , (11,15) , (34,14) , on... until (1,1) now 23: 23 70 35 106 53 160 80 40 ... since 40 hit, , in dictionary program length of 23 80, 7, , add length stored 40 9 resulting in total list length of 16. , of course program store lengt...

javascript - Error with nodemon debug -

it reports me error ➜ express-basics git:(requests) ✗ nodemon --debug src/app.js [nodemon] 1.11.0 [nodemon] restart @ time, enter `rs` [nodemon] watching: *.* [nodemon] starting `node --debug src/app.js` error: listen eaddrinuse :::5858 @ object.exports._errnoexception (util.js:907:11) @ exports._exceptionwithhostport (util.js:930:20) @ agent.server._listen2 (net.js:1250:14) @ listen (net.js:1286:10) @ agent.server.listen (net.js:1382:5) @ object.start (_debug_agent.js:21:9) @ startup (node.js:70:44) @ node.js:974:3 a minute ago ok, what's going wrong? thanks

python 3.x - When I use string,find[::] in another def, the string.find() says it's attribution doesn't work -

when use find() string.find[::] in def function, says says attribution error. why not work? def parts(phrase): space=phrase.find(' ') first_word=phrase[0:space] return first_word def rest_of_phrase(phrase): space=phrase.find(' ') rest_of_phrase=phrase[space+1:] return rest_of_phrase def jesus_this_part_is_hard(first_word,rest_of_phrase): total_num=len(rest_of_phrase) count=0 savepoint=[] while total_num<count: in total_num: if i==' ': savepoint+=[i] count+=1 print(first_word," ") x=savepoint[::-1] in x: if i==x[0]: print(rest_of_phrase[i:]," ") p=i elif i!=x[0]: print(rest_of_phrase[i:p],"") p=i def main(): phrase = input("enter phrase") parts(phrase) parts(rest_of_phrase) jesus_this_part_is_hard(first_word,rest_of_phrase) the r...

java - Eclipse 'generate entities from tables' and 'many to one' relation -

i developing simple java ee application, uses database. has 2 tables (admin , session signature) connected many 1 relation. when used eclipse generate entities tables, attribute links both tables generated this: //bi-directional many-to-one association admin @manytoone @joincolumn(name="owner") private admin admin; problem is, owner attribute integer in database, , has been created admin type. now when want pass integer variable input database error: the method setadmin(admin) in type signaturesession not applicable arguments (int). or when want cast (admin) (taking session): (admin)session.getattribute("adminid") i jboss error: javax.servlet.servletexception: java.lang.classcastexception: java.lang.integer cannot cast com.podpisy.entities.admin javax.faces.webapp.facesservlet.service(facesservlet.java:606) secure.securitycheckfilter.dofilter(securitycheckfilter.java:100) i sure can done easy, i'm bad using java. thanks help. edit:...

c# - List of various IReliableDictionaries -

using ireliabledictionary in service fabric application. trying organise dictionaries in class, there way have list of ireliabledicionary use different keys? ireliabledictionary<guid, user> x = await getdictionaryasync<guid, user>("userdict"); ireliabledictionary<string, guid> y = await getdictionaryasync<string, guid>("emailtouser"); var dicts = new list<ireliabledictionary<object, object>> { x, y }; only doesn't work, because key of ireliabledictionary has implement icomparable , iequatable . not had experience generics in c#. think of how in java, ? extends notation. possible in c#? i'm not sure you're going this. you're not going compiler enforce type safety dictionaries in list. you'll have write reflection code. run problems trying maintain references dictionaries yourself. the statemanager object manages dictionaries - that's it's for. thing should need keep track o...

f5 - I am getting this error while executing Chef Mixlib::ShellOut::ShellCommandFailed -

when execute chef recipe through work station error , i'm not able understand missing? > knife bootstrap 10.192.74.59 --ssh-user scs --ssh-password 'cisco123' --sudo --use-sudo-password --node-name webserver10.192.74.59 --run-list 'recipe[f5-node-initiator]' > node webserver10.192.74.59 exists, overwrite it? (y/n) y > client webserver10.192.74.59 exists, overwrite it? (y/n) y > creating new client webserver10.192.74.59 > creating new node webserver10.192.74.59 > connecting 10.192.74.59 > 10.192.74.59 [sudo] password scs: -----> existing chef installation detected 10.192.74.59 starting first chef client run... 10.192.74.59 starting chef client, version 12.15.19 10.192.74.59 resolving cookbooks run list: ["f5-node-initiator"] 10.192.74.59 synchronizing cookbooks: 10.192.74.59 - f5-node-initiator (0.0.1) 10.192.74.59 installing cookbook gems: 10.192.74.59 compiling cookbooks... 10.192.74.59 converging 4 resources 10...

C# Switch between program, and a java program -

i need figuring out how switch between programs, first application can taskmgr process. second program launches java applet , described multiple java.exe's maybe there lays solution around getting process name windowtitle since not advanced in c# seeking help. private void button1_click(object sender, eventargs e) { if (prog1) { var prc = process.getprocessesbyname("progam1"); if (prc.any()) { setforegroundwindow(prc[0].mainwindowhandle); showwindow(prc[0].mainwindowhandle, showwindowemum.program); prog1 = false; } } else { var prc = process.getprocessesbyname("a java applet"); if (prc.any()) { setforegroundwindow(prc[0].mainwindowhandle); showwindow(prc[0].mainwindowhandle, showwindowemum.java); prog1 = true; } } to clarify why needed both application run in fullscreen borderless setting, , no...

angularjs - ng-class add depending on group date data -

i have data in array name $scope.data variable. [ {date:'02-05-2016'}, {date:'02-05-2016'}, {date:'04-05-2016'}, {date:'04-05-2016'}, {date:'05-05-2016'}, {date:'05-05-2016'}, ... ... ] i have 2 css class (color1,color2). want add class in ng-repeat of each date group like 02-05-2016 => color1 04-05-2016 => color2 05-05-2016 => color1 ... ... i can't figure out how in ng-repeat if have mapping between dates , colors, simple. here do: var app = angular.module("sampleapp", []); app.controller("samplecontroller", ["$scope", function($scope) { $scope.dates = [{ date: '02-05-2016' }, { date: '02-05-2016' }, { date: '04-05-2016' }, { date: '04-05-2016' }, { date: '05-05-2016' }, { date: '05-05-2016' }]; } }]); .color1 { background-color: #121212; col...

java - Using genio with array -

hi i'm trying program work ask user input arrays using bluej, planning on using genio when type code below following message: incompatible types: int cannot converted int[] public class arrays { public int[] numbers; public void testintegerarray() { numbers = new int[4]; (int = 0; < numbers.length; i++) { numbers = genio.getinteger(); system.out.println(numbers[i]); } } } genio.getinteger(); // returns integer your assigning integer array can't. add integer array need: numbers[i] = genio.getinteger(); //your forgot [i]

python - Make function recursive -

i trying convert function below recursive 1 keep getting error when try it. typeerror: unsupported operand type(s) *: 'float' , 'nonetype' def turtle_spiral(forward): minus = 8 t = turtle.turtle() t.pendown() t.shape("turtle") #while forward > 10: randm = random.randrange(5) colours = ["blue", "orange", "yellow", "green", "purple","black","red","pink"] t.goto(-100,0) if forward <= 10: return false else: t.color(colours[randm]) #t.speed(10) t.fd(turtle_spiral(forward*minus)) #t.circle(forward, 360) t.right(90) #forward -= minus turtle_spiral(100) wd.mainloop() i've had go @ modifying code think want do: import turtle import random def turtle_spiral(forward): minus = 8 randm = random.randrange(5) colours = ["blue", "or...

sql server - How is "create view" evaluated in SQL? -

i have - maybe simple - question how create view , select ... viewname evaluated. know how create views , use them, have explain procedure of 2 commands graphically , text school. well, following (i using microsoft sql server 2012 @ moment, should not matter, it? know mysql too, if there differences): -- create schema test create schema temp go -- create view create view temp.vlt select lnr,tnr,menge ltp.ltp go -- select data view select * temp.vlt a view alias select query, evaluated in subquery, right? if so, right, that select * temp.vlt is same as select * (select lnr,tnr,menge ltp.ltp) vlt ? i mean, know gives same result, evaluated same way, or wrong? thank responsing! eisenbahnfan your understanding correct @ high level. first, views can differ among databases. mysql, in particular, has bunch of limitations such no subqueries in from clause. but, in fact, mysql pretty operates way describe. you have right understanding in general. code o...

ASP.NET Loading images to my page.aspx causing some weird errors ( sometimes! ) -

Image
as can guess title, loading players database (microsoft sql server 2012) players.aspx page, , ofcourse every player has photo.. and happening when i'm trying load players.aspx..? weird errors happening, 1 after another, that's weird. i explain more detailed: i'm loading 100 players in same time (still no paging), means i'm loading 100 photos page @ once, guess encumber page , caused issue, changed stored procedure returning me players database select top (10) reduced number of players should load in page, issues repated on , over, , when commented part getting image, works well, don't understand why happening, , why app keeps breaking when images loaded rest of attributes... and have issues not happen everytime, example run app - hitting f5 - debug, fine, did again, boom boom, , on... here code - players.aspx -code behind page i'm loading players photos. public partial class players : system.web.ui.page { protected void page_load(object s...

scala generic function return type -

i tried writing function generic return type doesn't work unless cast return type. please see function getsomething() below expected work without casting. might doing wrong here? trait sup class sub extends sup { def getstring = "i sub" } class sub2 extends sup { def getint = 100 } def getsomething[a <: sup](str: string) : = { str match { case "sub" => getsub.asinstanceof[a] case "sub2" => getsub2.asinstanceof[a] } } def getsub(): sub = { new sub } def getsub2() : sub2 = { new sub2 } val x = getsomething[sub]("sub").getstring val y = getsomething[sub2]("sub2").getint as alexey mentions, instanceof needed force link between expected type , type of object returned. it's equivalent of saying: "compiler, trust me, i'm giving 'a'" , it's not safe depends of provide correct type. if want type system figure things out us, need give additional information. ...

user interface - Make a gameobject appear after dialogue text finishes being typed out? -

so i'm creating dialogue system game , i'm trying achieve gameobject/image appear after text said npc. wanted achieve typewriter effect the dialogue text each character of text typed out during specific amount of frames/time in dialogue box. question want indicate sentence has ended showing "nextbutton" appear after sentence has been typed out. realize math , add button timed after x amount of frames/time each sentence seems convoluted , time consuming each piece of dialogue. wondering if there way show nextbutton after text finishes function. please , thank you! unityengine; using system.collections; using unityengine.ui; public class timeautotext : monobehaviour { // attach ui text component (with full text there) text txt; string story; public gameobject nextbutton; private gameobject t1; public gameobject t2; void awake() { nextbutton.setactive (false); ...

c# - Easy way to Print Values of a dictionary? -

i have below code: static void main(string[] args) { // add 5 employees dictionary. var employees = new dictionary<int, employee>(); employees.add(1, new employee(1, "john")); employees.add(2, new employee(2, "henry")); employees.add(3, new employee(3, "jason")); employees.add(4, new employee(4, "ron")); employees.add(5, new employee(5, "yan")); } is there easy way print values of dictionaries in easy way in java? example, want able print like: employee key 1: id=1, name= john employee key 2: id=2, name= henry .. etc.. thank you. sorry, used java! you can use foreach statement: foreach(var pair in employees) { console.writeline($"employee key {pair.key}: id={pair.value.id} name={pair.value.name}"); }

Do I need to set the default timezone for a Rails app on Heroku? -

a timepicker in rails app on heroku, showing wrong time. looks it's showing server time somehow. how should correct time? need configure rails app, or there setting on heroku server? app used in 1 timezone. thanks. yes, think still works command line heroku config:add tz="america/chicago"

Algolia Update Index On Relational Database change with Laravel Scout -

i have implemented aloglia movies table actors relational table , works fine. problem: when update movie updating algolia index (its good). how can update index if made change in relational table (for example update actor of movie). how push specific record manually laravel scout. thanks the issue lies in laravel's events. whats happening scout listening 'updated' event occurs in laravel when model object saved , dirty (aka value differ in db). there 2 ways can this. the bad lazy way add ->touch() model prior save - force updated_at field update , trigger updated event. bad you're wasting db query. the second , preferable way register observer on 'saved' triggers regardless of whether or not object dirty. either want check if model dirty , index when not (to prevent double indexing updated event) or de-register 'updated' listener comes in scout.

laravel 5.2 - Trying to get property of non-object, exactly i don't this error -

this controller questions , it's category, should displayed users category, category user select must displayed , count questions users answered ,but when want apply section mentioned error displaying don't error contrller public function start() { $category = db::table('question_type')->get(); return view('frontend.start',compact('category')); } public function questionscategory(request $request) { $ctid = $request->input('selected-category'); $langid = $request->input('language'); $time = db::table('question_type')->select('time')->where('type_id', $ctid)->first(); $hours = 0; $minutes = 0; $scs = 0; if ($ctid == 1) { if ($time->time > 60) { $hours = 1; $minutes = $time->time- 60; } else { ...

Creating a matrix of vectors with apply (or other iterative function) in R -

i need run orthogonal encoding function on set of octamers (sets of 8 letters), , return them matrix of nx160 numbers (where n number of octamers on data). the orthogonal coding functions is: orthocode <- function(octamer){ matcode <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) octamer_char <- as.character(octamer) octamer_split <- strsplit(octamer_char,"")[[1]] (letter in octamer_split){ ifelse (letter == "a", (matcode = rbind(matcode,c(1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))), ifelse (letter == "r", (matcode = rbind(matcode,c(0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))), ifelse (letter == "n", (matcode = rbind(matcode,c(0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))), ifelse (letter == "d", (matcode = rbind(matcode,c(0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0))), ifelse (letter == "c", (matcode = rbind(matcode,c(0,0,0,0,1,0,0,...

excel vba - VBA- Sum values in Column B if name in column A is the same -

i try edit macro summing values in column b, doesnt work correctly: here is, have: option explicit sub main() collectarray "a", "d" dosum "d", "e", "a", "b" end sub ' collect array specific column , print new 1 without duplicates ' params: ' fromcolumn - column need remove duplicates ' tocolumn - reprint array without duplicates sub collectarray(fromcolumn string, tocolumn string) redim arr(0) string dim long = 1 range(fromcolumn & rows.count).end(xlup).row arr(ubound(arr)) = range(fromcolumn & i) redim preserve arr(ubound(arr) + 1) next redim preserve arr(ubound(arr) - 1) removeduplicate arr range(tocolumn & "1:" & tocolumn & range(tocolumn & rows.count).end(xlup).row).clearcontents = lbound(arr) ubound(arr) range(tocolumn & + 1) = arr(i) next end sub ' sums valu...

c++ - Time Complexity in singly link list -

Image
i studying data-structure: singly link list. the website says singly linked list has insertion , deletion time complexity of o(1) . missing something? website link i in c++, , have root pointer . if want insert @ end, have travel way back, means o(n) . the explanation is, big o notation in linked table refers function implementation itself, not including list traversal find previous reference node in list. if follow link wikipedia article of singly-linkedlist implementation becomes more clear: function insertafter(node node, node newnode) function removeafter(node node) the above function signatures take predecessor node argument (same other variants implicitly). finding predecessor different operation , may o(n) or other time complexity.

ruby - Deploying a Padrino app using capistrano (bundler: failed to load command: padrino) -

i'm trying deploy padrino application using capistrano, when run command: cap deploy following output generated: //... other tasks executed * 2016-11-05 16:23:26 executing `assets:prepare' * executing "cd /data/apps/myapp/current; rack_env=production bundle exec padrino rake assets:prepare" servers: ["my_server_dns_name"] [my_server_dns_name] executing command ** [out :: my_server_dns_name] => executing rake assets:prepare ... ** [out :: my_server_dns_name] rspec not part of bundle, skip specs. ** [out :: my_server_dns_name] w, [2016-11-05t20:23:28.664995 #14317] warn -- : error creating log directory log/, using standard out logging. ** [out :: my_server_dns_name] [11/05/16 20:23:28 +0000 ip-172-31-16-177 (14317)] info : starting new relic agent in "production" environment. ** [out :: my_server_dns_name] [11/05/16 20:23:28 +0000 ip-172-31-16-177 (14317)] info : prevent agent startup add newrelic_enable=false envi...

java - Replace quotes which are not inside word -

i have long string containing several words. some of these words have apostrophe eg . don't . words have apostrophe outside words example '''movieis great ''' or ''lot of apostrophe ''''' . i want remove apostrophe not part of word. for example in string = don't try ''''remove apostr inside'''' word'. output should don't try remove apostr inside word. i wrote regex .*[^a-z]'[^a-z].* not getting desired output in java code. string s = "don't try ''''remove apostr inside'''' word'"; s = s.replace(".*[^a-z]'[^a-z].*", " "); note .replace() replaces literal strings , not allow regex search argument. you may use regex match apostrophes not enclosed word boundaries: string s = "don't try ''''remove apostr inside'''' word' 'żoł...

mysql - My sql results from rows to column -

this question has answer here: mysql pivot table 8 answers is there way insert values of count(*) these columns. explain. have table +--------+----------+ | url | type | +--------+----------+ | url1 | | +--------+----------+ | url1 | b | +--------+----------+ | url2 | c | +--------+----------+ | url2 | c | +--------+----------+ where values how many times type (a,b,c) appears in data set (this why want count) want have @ final table +--------+------+-----+-----+ | url | | b | c | +--------+------+-----+-----+ | url1 | 3 | 1 | 0 | +--------+------+-----+-----+ | url2 | 2 | 0 | 1 | +--------+------+-----+-----+ until did this select url, type, count(*) table group url,type and i'm getting (random example) |url ...

python - Where to store object information django? -

in django project need access object of user`s character (a model), where should store value of object ? since using in multiple views display content in template. should store in session, retrieve database every time or other alternative? class character(models.model): user = models.onetoonefield(user, on_delete=models.cascade,primary_key=true) gold = models.integerfield(default=gold) points = models.integerfield(default = startpoints) not sure means character , but: if not session-based, permanent information(and believe is) need store in database able fetch when user log in. how store not matter - can dedicated table if need it(in case nice add user fk) or field in user table. then, if have session middleware , authentication middleware, able access user object request object, need is: request.user.character i hope helpful. upd: way store data between requests in db or caching system(if have non-db cache or don't store session in db in faster ...

javascript - Concat sequential 2 elements of an array as an array in new array -

suppose if have array [1,2,3,4,5,6], want new array [[1,2],[3,4],[5,6]]. don't want use loop.i want solve using map-reduce or using best practice not getting how use map-reduce. please help. you use remainder operator % checking. if zero, push last inserted array otherwise result new array. var array = [1, 2, 3, 4, 5, 6], result = array.reduce(function (r, a, i) { % 2 ? r[r.length - 1].push(a) : r.push([a]); return r; }, []); console.log(result); .as-console-wrapper { max-height: 100% !important; top: 0; }

java - The Handler is not working properly in a function in Android -

following code wrote increasing brightness of background color of views 128 255 , vice-versa. unfortunately, handler supposed make wait not functioning properly. kindly me code. there 3x3 matrix having 9 views in it. i'm randomly changing opacity of 1 cell. level : number of cells want change 1 one. here, level : 3 color[9] : 3x3 matrix containing 9 views. public void pattern() { for(int i=0;i<level;i++) { int rand= 0 + (int)(math.random() * 8); computer+=rand; log.d(" :" , ""+i); log.d(" random :" , ""+rand); log.d("pattern incoming " , ""+color[rand].getbackground().getalpha()); color[rand].getbackground().setalpha(128); final int random=rand; handler.postdelayed(new runnable() { @override public void run() { color[random].getbackground().setalpha(128); log.d("inside h...

javascript - Form submitting without refresh not working -

i trying submit form without doing hard refresh page refreshing. tried putting action=“javascript:void(0);" in form tag didn't work. cannot use jquery. work flow causes error: submitting form supposed send information php file. page gets directed page doesn't exist. function toggle_visibility(id){ var e = document.getelementbyid(id); if(e.style.visibility == 'hidden'){ e.style.visibility = 'visible'; } else{ e.style.visibility = 'hidden'; } } function createajaxrequestobject() { var httprequest; if (window.xmlhttprequest) { // mozilla, safari, ... httprequest = new xmlhttprequest(); if (httprequest.overridemimetype) { httprequest.overridemimetype('text/xml'); } } else if (window.activexobject) { // ie try { httprequest...

arrays - Binary mask in Tensorflow -

i mask every other value along particular dimension of tensor don't see way generate such mask. example #masking on 2nd dimension = [[1,2,3,4,5],[6,7,8,9,0] mask = [[1,0,1,0,1],[1,1,1,1,1]] b = * mask #would return [[1,0,3,0,5],[6,0,8,0,0]] is there easy way generate such mask? ideally following: mask = tf.ones_like(input_tensor) mask[:,::2] = 0 mask * input_tensor but slice assigning doesn't seem simple in numpy. you can programmatically create such tensor mask using python. convert tensor. there's no such support in tensorflow api. tf.tile([1,0], num_of_repeats) might fast way create such mask not great either if have odd number of columns. (btw, if end creating boolean mask, use tf.boolean_mask() )