天道酬勤,学无止境

问答

Python: Generating a symmetric array with list comprehension

I am trying to generate a matrix A == [f(i,j) for i,j in range(0,n)]. The matrix is symmetric (f(i,j) == f(j,i)) and the diagonal elements are zero (f(i,i) == 0). Question: Is it possible to produce a list comprehension that generates this matrix but that only calls the function f(i,j) for i < j? Not my question: Generate the symmetric matrix in some other way. Possible solution: Make the call to f through an auxiliary function g that saves the value of f in an additional storage or returns the stored value. Would it be possible to solve avoiding the additional storage? I am not sure if this

2022-01-19 02:41:59   python   arrays   list-comprehension

How to convert a json formatted string into a json array in javascript

I am using the $.post() method to retrieve a json formatted string which looks like this: {elementid:10},{elementid:11},{elementid:12},{elementid:14},{elementid:15} In the success callback function of $.post(), I would like to loop the values of this json formatted string but I can't figure out how to do it. // data returns {elementid:10},{elementid:11},{elementid:12},{elementid:14}, etc. $.post('form.php', {'postvalues' : input_ids}, function(data){ var elements = Array(); elements = [data]; for(var i=0; i<elements.length; i++) { var value = elements[i]['elementid']; alert('value = '+value);

2022-01-19 02:41:54   javascript   jquery

Object Pool Pattern in Java

So I've implemented my own Object Pool Pattern and it works just fine and as expected. Returning my "Teacher" objects from a list and creating them when there aren't any. My question: The object being returned "Teacher" then needs to be casted into one of its sub classes which is specialised e.g. "Biology-Teacher". What is the best way to get this kind of functionality? Edit: Sorry, I didn't think code was needed but here goes. Below is the casting I was talking about. This throws a run-time exception which is my main problem. final Bio-Teacher = (Bio-Teacher) ObjectPool.getTeacher(); This is

2022-01-19 02:41:48   java   algorithm   design-patterns

Remove specific properties from Array objects in Node.js

For example I have this array, if I stringfy it it would be like this: [{"car":"Toyota","ID":"1", "Doors": "4", "price": "20.000"},{"car":"Chevrolet","ID":"2", "Doors": "2", "price": "15.000"}] How can I do for remove from the 2 cars: the doors and price. And only leave in the array "car" and "id"? For example: [{"car":"Toyota","ID":"1"},{"car":"Chevrolet","ID":"2"}] Thank you!

2022-01-19 02:41:34   javascript   arrays   node.js   object

Why is AndroidAsync disconnect time so long?

I'm using the AndroidAsync koush low level network protocol library. I am connecting to a server with WebSocket. I am able to connect, send/receive messages, and disconnect. My disconnect time is very long. Server does not detect the disconnect for on average 59 seconds. In order to reproduce the problem, I connect WebSocket, authorize, and start pinging every 10 seconds. Then I turn on Airplane Mode and my network connection drops. At this time the setClosedCallback method is called. Here is how I am logging this message: private WebSocket mConnection; private WebSocketConnectCallback

2022-01-19 02:41:28   android   websocket   androidasync-koush

UIButton not showing the text in iOS6

I am working with iOS6 and Xcode 4.5, I am getting an UI issue with some UIButton, some of the buttons title are not getting shown in my view. In an older version of iOS everything works as expected. Please see the following image. It's not showing the text "Button" while executing it on simulator

2022-01-19 02:41:19   iphone   objective-c   ios   xcode

Recording Videos in Chunks Using Media Recorder Android

I am implementing an Application that includes the functionality of saving Recorded Video in to Different Video Files based on a certain amount of Time. For Achieving that i have implemented a Custom Camera and used the MediaRecorder.stop() and MediaRecorder.start() in a certain Loop. But this approach is creating a Lag Effect while restarting Media Recorder (Stop and Start). Is it possible to seamlessly Stop and Start Recording using Media Recorder or any Third Party Library ? Any help is Highly Appreciated.

2022-01-19 02:41:06   android   mediarecorder   android-mediarecorder   video-recording

Split every row in df and add value to each element

I have a df that looks like this: user_index movie_index genre_index cast_index 3590 1514 10|12|17|35 46|534 63 563 4|2|1|8 9|27 and was generated from: import pandas as pd ds = pd.DataFrame({'user_index': [3590,63], 'movie_index': [1514,563], 'genre_index':['10|12|17|35', '4|2|1|8'], 'cast_index':['46|534', '9|27']}) I need to split every row by '|' (whereas converting every row to list) and to add to each element some value to get such df (here, '5' is added element-wise in column 'genre_index', '2' is added element-wise in column 'user_index'): user_index movie_index genre_index cast_index

2022-01-19 02:40:55   python   python-3.x   pandas

Mechanism for returning a string from C main() program

I know that C program generally ends with return, where we return the status of the program. However, I want to return a string. The reason is that, I will be calling the C-executable from a shell script and printing the returned string. Is there any mechanism for the same ?

2022-01-19 02:40:41   c

jQuery delay function interrupt

I have a pop-up window in jQuery that fades in, and will fade out in 10 seconds if not dismissed by the user. I have the code: $modalElement.fadeIn(1000).delay(10000).fadeOut(1000); And this works fine for the fade in, delay and fade out - but the 'close' button on the form doesnt work until after the timeout! I need the 'close' button to interupt the delay, so that the user can read the pop up and close it themselves, say, at 5 seconds - and then if they havent closed it themselves, then it will close automatically after the 10 second delay. Any ideas how to do this?

2022-01-19 02:40:35   jquery   delay   interrupt