问:
Best Software Engineering Practice for Student Project Team?
I've been reading about the various forms and aspects of agile development, but all focused on the corporate environment.  I am on a student project team at my university, and I'd like to see if some agile concepts could work in an environment other than 'everyone works full/part time'.

We do have our own project server, with Subversion for version control, and Sharepoint for documents, wiki, and action items.

Some challenges

It's hard enough to arrange a weekly meeting, daily standups are infeasable

We're our own customers for the most part (we're part of a competition, but we can't work closely with the organizers)

Not just programmers, also mechanical/electrical team members

Sharepoint's action items don't have the best interface. Are there any extensions available? Would it make sense to switch to something else (like Trac) at the expense of a unified interface for everything non-svn?

Procrastination. As students, the most natural thing to do is wait to the last minute

We have our own space, but often, it's easier to do work elsewhere, and there's no way to predict if anyone else will be there except by making explicit arrangements

Other classes (still have to pass them, so total commitment to the team is limited)

Perhaps our team could benefit from more than just agile techniques, so all suggestions are welcome.

EDIT Thanks for all the great answers. I'm going to start asking my teammates how they feel about some of these ideas, and see what they buy into.  Should I link them to this question? You can edit your answer or just leave a comment to answer this secondary question.

答:
When I was in college, I took several courses that encouraged the adoption and use of Agile practices. They were mostly a mess and although I learned a lot of from them they generally weren't the things the professor was expecting us to learn. I do agile development professionally now and love it, but here are the things I wish that I had known when I was doing agile in school:

Getting things squared with your schedule is really, really hard, which makes daily standups more important, not less. If you can't sit in the same room (very hard) then use Twitter or Yammer or just email.

A lot of Agile's benefit is simply in getting you into a rhythm. That doesn't just mean weekly meetings; it means set goals, commitment to points, and weekly deliverables. This is tough to pull off in an academic context but should go a way towards helping you with your procrastination problem.

It's tough to get used to pairing; everyone has their own computer and style of development. Try to hook a second keyboard/monitor/mouse up to your existing laptops if possible, or use screen sharing software, and standardize on an IDE. Pairing also really, really helps with procrastination but trying to do it without good tools is an awful lot of trouble.

Don't skimp on unit testing, even if you think of it as a silly, academic, one-off project. I've done projects before that I figured were too small to bother with testing and it's never failed to come back and bite me on the ass.

Sharepoint might be a bit heavyweight. Believe it or not, we still do an awful lot of things on whiteboards or with index cards. You may be your own customer but that doesn't mean you can't have stories (discrete, estimable features, basically) and goals. It's helpful to be able to visualize it: these features are planned, these are in development, these are ready for testing. If you'd like software recommendations I can give you those but I do recommend simple paper for a lot of the planning process.

OwnerDisplayName: Brian Guthrie


来源: stackexchange

问:
NodeJs Error: Port already in use:3000 using socket.io and express
I'm making a node.js application that uses socket.io and express.

The code looks like this-

```<code>const express=require('express');
const app=express();
const http=require('http').Server(app);
app.use(express.static('public'));

const io=require('socket.io')(http,{
  cors:{origin:'*'}
});

http.listen(3000,()=>{
  console.log('listening to port 3000');
});

//when connection made
io.on('connection',(socket)=>{
  console.log('connection made!');
});
</code>```

Here,public is a folder container all the html files for the website.

Now,when I run it locally on my pc,it works fine
But when I deployed it on the glitch.com servers,i get this error:

```<code>Error: listen EADDREINUSE: address already in use :::3000
</code>```

As far as i know,3000 is the only available port in glitch and I cannot use another port.

Also,the questions on stack overflow related to this topic doesn't help me since most of the answers are related to killing the running tasks themselves and I don't have permission to do so on the server.

答:
free your 3000 port:

Linux: fuser -k 3000/tcp

ContentLicense: CC BY-SA 4.0

Body:
I'm making a node.js application that uses socket.io and express.

The code looks like this-

const express=require('express');
const app=express();
const http=require('http').Server(app);
app.use(express.static('public'));

const io=require('socket.io')(http,{
  cors:{origin:'*'}
});

http.listen(3000,()=>{
  console.log('listening to port 3000');
});

//when connection made
io.on('connection',(socket)=>{
  console.log('connection made!');
});

Here,public is a folder container all the html files for the website.

Now,when I run it locally on my pc,it works fine
But when I deployed it on the glitch.com servers,i get this error:

Error: listen EADDREINUSE: address already in use :::3000

As far as i know,3000 is the only available port in glitch and I cannot use another port.

Also,the questions on stack overflow related to this topic doesn't help me since most of the answers are related to killing the running tasks themselves and I don't have permission to do so on the server.


问:
Working with Laravel Project without Vendor Folder
I just downloaded a folder of Laravel Project from a server without vendor folder.
then tried to run composer install command to retrieve the vendor folder.
but an error message was shown in console.

PHP Warning:  PHP Startup: Unable to load dynamic library 'bz2'
(tried: \xampp\php\ext\bz2 (The specified module could not be found),
\xampp\php\ext\php_bz2.dll (The specified module could not be found))
in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'bz2' (tried:
\xampp\php\ext\bz2 (The specified module could not be found),
\xampp\php\ext\php_bz2.dll (The specified module could not be found))
in Unknown on line 0 PHP Warning:  PHP Startup: Unable to load dynamic
library 'curl' (tried: \xampp\php\ext\curl (The specified module could
not be found), \xampp\php\ext\php_curl.dll (The specified module could
not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'curl' (tried:
\xampp\php\ext\curl (The specified module could not be found),
\xampp\php\ext\php_curl.dll (The specified module could not be found))
in Unknown on line 0 PHP Warning:  PHP Startup: Unable to load dynamic
library 'fileinfo' (tried: \xampp\php\ext\fileinfo (The specified
module could not be found), \xampp\php\ext\php_fileinfo.dll (The
specified module could not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'fileinfo'
(tried: \xampp\php\ext\fileinfo (The specified module could not be
found), \xampp\php\ext\php_fileinfo.dll (The specified module could
not be found)) in Unknown on line 0 PHP Warning:  PHP Startup: Unable
to load dynamic library 'gettext' (tried: \xampp\php\ext\gettext (The
specified module could not be found), \xampp\php\ext\php_gettext.dll
(The specified module could not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'gettext' (tried:
\xampp\php\ext\gettext (The specified module could not be found),
\xampp\php\ext\php_gettext.dll (The specified module could not be
found)) in Unknown on line 0 PHP Warning:  PHP Startup: Unable to load
dynamic library 'mbstring' (tried: \xampp\php\ext\mbstring (The
specified module could not be found), \xampp\php\ext\php_mbstring.dll
(The specified module could not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'mbstring'
(tried: \xampp\php\ext\mbstring (The specified module could not be
found), \xampp\php\ext\php_mbstring.dll (The specified module could
not be found)) in Unknown on line 0 PHP Warning:  PHP Startup: Unable
to load dynamic library 'exif' (tried: \xampp\php\ext\exif (The
specified module could not be found), \xampp\php\ext\php_exif.dll (The
specified module could not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'exif' (tried:
\xampp\php\ext\exif (The specified module could not be found),
\xampp\php\ext\php_exif.dll (The specified module could not be found))
in Unknown on line 0 PHP Warning:  PHP Startup: Unable to load dynamic
library 'mysqli' (tried: \xampp\php\ext\mysqli (The specified module
could not be found), \xampp\php\ext\php_mysqli.dll (The specified
module could not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'mysqli' (tried:
\xampp\php\ext\mysqli (The specified module could not be found),
\xampp\php\ext\php_mysqli.dll (The specified module could not be
found)) in Unknown on line 0 PHP Warning:  PHP Startup: Unable to load
dynamic library 'pdo_mysql' (tried: \xampp\php\ext\pdo_mysql (The
specified module could not be found), \xampp\php\ext\php_pdo_mysql.dll
(The specified module could not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'pdo_mysql'
(tried: \xampp\php\ext\pdo_mysql (The specified module could not be
found), \xampp\php\ext\php_pdo_mysql.dll (The specified module could
not be found)) in Unknown on line 0 PHP Warning:  PHP Startup: Unable
to load dynamic library 'pdo_sqlite' (tried: \xampp\php\ext\pdo_sqlite
(The specified module could not be found),
\xampp\php\ext\php_pdo_sqlite.dll (The specified module could not be
found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'pdo_sqlite'
(tried: \xampp\php\ext\pdo_sqlite (The specified module could not be
found), \xampp\php\ext\php_pdo_sqlite.dll (The specified module could
not be found)) in Unknown on line 0 PHP Warning:  PHP Startup: Unable
to load dynamic library 'php_openssl.dll' (tried:
\xampp\php\ext\php_openssl.dll (The specified module could not be
found), \xampp\php\ext\php_php_openssl.dll.dll (The specified module
could not be found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'php_openssl.dll'
(tried: \xampp\php\ext\php_openssl.dll (The specified module could not
be found),  \xampp\php\ext\php_php_openssl.dll.dll (The specified
module could not be found)) in Unknown on line 0 PHP Warning:  PHP
Startup: Unable to load dynamic library 'php_ftp.dll' (tried:
\xampp\php\ext\php_ftp.dll (The specified module could not be found),
\xampp\php\ext\php_php_ftp.dll.dll (The specified module could not be
found)) in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'php_ftp.dll'
(tried: \xampp\php\ext\php_ftp.dll (The specified module could not be
found), \xampp\php\ext\php_php_ftp.dll.dll (The specified module could
not be found)) in Unknown on line 0 PHP Warning:  Cannot open
"\xampp\php\extras\browscap.ini" for reading in Unknown on line 0

Warning: Cannot open "\xampp\php\extras\browscap.ini" for reading in
Unknown on line 0 PHP Fatal error:  Unable to start standard module in
Unknown on line 0

Fatal error: Unable to start standard module in Unknown on line 0

答:
Php extensinos are not installed in your machinge, you can install php extension in linux with apt-get install

For example, if your Php version is 8.1,

```<code>sudo apt-get install php@8.1-bz2

sudo apt-get install php@8.1-mbstring
</code>```

In Windows OS you can enable the Php extensions from .ini file.

Body:
Php extensinos are not installed in your machinge, you can install php extension in linux with apt-get install

For example, if your Php version is 8.1,

sudo apt-get install php@8.1-bz2

sudo apt-get install php@8.1-mbstring

In Windows OS you can enable the Php extensions from .ini file.


问:
Error: Can't load file from uriString when upload audio file Android
I am getting error message Error: Can't load file from uriString when uploading audio and PDF files with Quickblox in React Native Android app. It is working for images and videos. Quickblox documentation confirms it supports all file formats for chat attachment. Could someone please guide me how to get rid of this error?

答:
I have an answer from QuickBlox support team, they recommended to check the archive with a sample code in order to send any files as chat message attachments. Per my check works fine with .pdf, .mp3

This sample is not officially released so I can provide you only with a Google drive link

https://drive.google.com/file/d/1C2Rfop3qbLl693UmHA03O3Fdbdy6dVcq/view?usp=sharing


问:
Cors error with axios using authentication
I am having some trouble with axios once I add authentication.

My api.ts file:

```<code>import axios from "axios"

export default axios.create({
  baseUrl: "https://someUrl"
})
</code>```

In App.ts i am setting authentication header:

```<code>import api from api.ts

function App(){
  api.default.header.common["Authorization"] = `Bearer ${token}`
}
</code>```

And in my apiHooks.ts

```<code>import api from api.ts
import {useQuery} from "react-query"
const GetSomething = () => {
  const {data, isLoading = useQuery("key", () => {
    return api.get("/api")
  });
  return data?.data
};
export default GetSomething;
</code>```

So when I'm using the hook, I get a Cors error ONLY when turning on authentication.
The error is the following:

cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at "url"

答:
CORS has to be enabled on the server where the API is running on. CORS added new HTTP headers that allow servers to describe the set of origins that are permitted to read that information.

To enable CORS in Rails based application following code should be included in cors.rb-

    Rails.application.config.middleware.insert_before 0, Rack::Cors do
      allow do
        origins '*'

        resource '*',
          headers: :any,
          methods: [:get, :post, :put, :patch, :delete, :options, :head],
          expose: ['Access-Token', 'Uid', 'Client']
      end
    end
```

Body:
I am having some trouble with axios once I add authentication.

My api.ts file:

import axios from "axios"

export default axios.create({
  baseUrl: "https://someUrl"
})

In App.ts i am setting authentication header:

import api from api.ts

function App(){
  api.default.header.common["Authorization"] = `Bearer ${token}`
}

And in my apiHooks.ts

import api from api.ts
import {useQuery} from "react-query"
const GetSomething = () => {
  const {data, isLoading = useQuery("key", () => {
    return api.get("/api")
  });
  return data?.data
};
export default GetSomething;

So when I'm using the hook, I get a Cors error ONLY when turning on authentication.
The error is the following:

cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at "url"


问:
Hide some POI in Google Maps
I found a way to hide all business poi in Google Maps. And it works great.

```<code>[
  {
    "featureType": "poi.business",
    "stylers": [
      { "visibility": "off" }
    ]
  }
]
</code>```

But I just want to hide some POI categories like restaurants or bars. How can I do that?
Here I found a list of category types but it doesn't work when I try it like this.

```<code>[
  {
    "featureType": "poi.restaurant",
    "stylers": [
      { "visibility": "off" }
    ]
  }
]
</code>```

答:
Unfortunatly you can't hide poi.buisness by sector. According to the documentation relative to style-features of the style-reference you can choose to hide some poi by type

poi.attraction selects tourist attractions.

poi.business selects businesses.

poi.government selects government buildings.

poi.medical selects emergency services, including hospitals, pharmacies, police, doctors, and others.

poi.park selects parks.

poi.place_of_worship selects places of worship, including churches, temples, mosques, and others.

poi.school selects schools.

poi.sports_complex selects sports complexes.

Title: Hide some POI in Google Maps

Body:
I found a way to hide all business poi in Google Maps. And it works great.

[
  {
    "featureType": "poi.business",
    "stylers": [
      { "visibility": "off" }
    ]
  }
]

But I just want to hide some POI categories like restaurants or bars. How can I do that?
Here I found a list of category types but it doesn't work when I try it like this.

[
  {
    "featureType": "poi.restaurant",
    "stylers": [
      { "visibility": "off" }
    ]
  }
]


问:
How to determine if a property is required?
Given a class something like this:

```<code>public class MyClass : ValidationValues
{
    public string Foo { get; set; }

    [Required(ErrorMessage = "Bar is required.")]
    public string Bar { get; set; }

    // and many more
}

public class ValidationValues
{
    public bool IsValid { get; set; } = true;
    public string InvalidReason { get; set; }
}
</code>```

I need to determine if a property is required while looping over it as a generic list. By looking into the Watch, I've figured out one way, but it feels clunky, and I'm thinking it should be simpler.

For some context, this logic is inside of an Azure Function. So no Views, no MVC, etc. The function is a Blob Storage trigger that picks up a .CSV file with a | delimited list which gets deserialized into a List<MyClass>. We do not want to enforce the Required attributes at deserialization because we want more granular control.

So given a file like this:

```<code>value1 | |
value2 | something

</code>```

What eventually gets sent back to the user is something like this:

```<code>[
    {
        "foo": "value1",
        "bar": "",
        "isValid": false,
        "InvalidReason" : "Bar is required"
    },
    {
        "foo": "value2",
        "bar": "something",
        "isValid": true,
        "InvalidReason" : ""
    }
]

</code>```

Here's what I have now:

```<code>foreach (T item in itemList) // where 'itemList' is a List<T> and in this case T is MyClass
{
    foreach (PropertyInfo property in item.GetType().GetProperties())
    {
        if (property.CustomAttributes.ToList()[0].AttributeType.Name == "RequiredAttribute")
        {
             // validate, log, populate ValidationValues
        }
    }
}

</code>```

This is the part I don't like:

```<code>property.CustomAttributes.ToList()[0].AttributeType.Name == "RequiredAttribute"
</code>```

Sometimes when I figure out a coding challenge, I tell myself, "This is the way". But in this case, I'm pretty sure this isn't the way.

答:
Reflection is slow - or at least, relatively slow. So; the main important thing here is: don't do this per instance; you could either cache it per Type (from GetType(), or you could just use T and never even check .GetType() per instance, depending on your intent. This includes caching the properties that exist for a given type, and which are required. However, the real bonus points are to use meta-programming to emit - either at runtime, or at build-time via a "generator" - a method that *does exactly what you want, without any loops, tests, etc; i.e. in this case it might emit a method that does the equivalent of

```<code>void ValidateMyClass(MyClass obj)
{
    if (string.IsNullOrWhitespace(obj.Bar))
    {
        DoSomething("Bar is required.");
    }
}
</code>```

This can be done in a variety of ways, including the Expression API, the emit API (ILGenerator), emitting C# and using CSharpCodeProvider, or the "generators" API.

Body:
Given a class something like this:

public class MyClass : ValidationValues
{
    public string Foo { get; set; }

    [Required(ErrorMessage = "Bar is required.")]
    public string Bar { get; set; }

    // and many more
}

public class ValidationValues
{
    public bool IsValid { get; set; } = true;
    public string InvalidReason { get; set; }
}

I need to determine if a property is required while looping over it as a generic list. By looking into the Watch, I've figured out one way, but it feels clunky, and I'm thinking it should be simpler.

For some context, this logic is inside of an Azure Function. So no Views, no MVC, etc. The function is a Blob Storage trigger that picks up a .CSV file with a | delimited list which gets deserialized into a List<MyClass>. We do not want to enforce the Required attributes at deserialization because we want more granular control.

So given a file like this:

value1 | |
value2 | something

What eventually gets sent back to the user is something like this:

[
    {
        "foo": "value1",
        "bar": "",
        "isValid": false,
        "InvalidReason" : "Bar is required"
    },
    {
        "foo": "value2",
        "bar": "something",
        "isValid": true,
        "InvalidReason" : ""
    }
]

Here's what I have now:

foreach (T item in itemList) // where 'itemList' is a List<T> and in this case T is MyClass
{
    foreach (PropertyInfo property in item.GetType().GetProperties())
    {
        if (property.CustomAttributes.ToList()[0].AttributeType.Name == "RequiredAttribute")
        {
             // validate, log, populate ValidationValues
        }
    }
}

This is the part I don't like:

property.CustomAttributes.ToList()[0].AttributeType.Name == "RequiredAttribute"

Sometimes when I figure out a coding challenge, I tell myself, "This is the way". But in this case, I'm pretty sure this isn't the way.

Body:
Reflection is slow - or at least, relatively slow. So; the main important thing here is: don't do this per instance; you could either cache it per Type (from GetType(), or you could just use T and never even check .GetType() per instance, depending on your intent. This includes caching the properties that exist for a given type, and which are required. However, the real bonus points are to use meta-programming to emit - either at runtime, or at build-time via a "generator" - a method that *does exactly what you want, without any loops, tests, etc; i.e. in this case it might emit a method that does the equivalent of

void ValidateMyClass(MyClass obj)
{
    if (string.IsNullOrWhitespace(obj.Bar))
    {
        DoSomething("Bar is required.");
    }
}

This can be done in a variety of ways, including the Expression API, the emit API (ILGenerator), emitting C# and using CSharpCodeProvider, or the "generators" API.


问:
css/html- to create a circle with a hole in the bottom
enter image description here

I wanna make circle chart like this.
below is my code.

If I invert up and down in that code, i get the shape you want.
But what I really want is a graph with the yellow graph pointing further to the right. How do I adjust the spacing?
Please help me

```<code><svg width="4.5rem" height="4.5rem" viewBox="0 0 40 40">
  <circle class="pieSegment segment1" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#1a0d1c" stroke-dashoffset="11" stroke-dasharray="74" stroke-width="5"></circle>
  <circle class="pieSegment segment3" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#e9ad61" stroke-dashoffset="14" stroke-dasharray="25 75" stroke-width="5"></circle>
</svg>
</code>```

答:
an idea can be to use pathLength="100" to your circle
that allow you to give a percent in the attribute stroke-dashoffset  with 100% - {percent of circle to fill}

then we can imagine rotate the circle to the correct shape

```<code>#mySvg {
  transform: rotate(-125deg) scaleX(-1);
}
</code>```

to round the border of your line you can use

```<code>  stroke-linecap: round;
</code>```

#mySvg {
  transform: rotate(-125deg) scaleX(-1);
}

#mySvg circle {
  stroke-linecap: round;
  shape-rendering: geometricPrecision;
}
   ```
<pre class="snippet-code-html lang-html prettyprint-override"><code><svg id="mySvg" width="4.5rem" height="4.5rem" viewBox="0 0 40 40">
  <circle class="pieSegment segment1" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#1a0d1c" stroke-dashoffset="20" stroke-dasharray="100" stroke-width="5" pathLength="100"></circle>
  <circle class="pieSegment segment3" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#e9ad61" stroke-dashoffset="80" stroke-dasharray="100" stroke-width="5" pathLength="100"></circle>
</svg></code>```

Body:
enter image description here

I wanna make circle chart like this.
below is my code.

If I invert up and down in that code, i get the shape you want.
But what I really want is a graph with the yellow graph pointing further to the right. How do I adjust the spacing?
Please help me

<svg width="4.5rem" height="4.5rem" viewBox="0 0 40 40">
  <circle class="pieSegment segment1" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#1a0d1c" stroke-dashoffset="11" stroke-dasharray="74" stroke-width="5"></circle>
  <circle class="pieSegment segment3" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#e9ad61" stroke-dashoffset="14" stroke-dasharray="25 75" stroke-width="5"></circle>
</svg>

Body:
an idea can be to use pathLength="100" to your circle
that allow you to give a percent in the attribute stroke-dashoffset  with 100% - {percent of circle to fill}

then we can imagine rotate the circle to the correct shape

#mySvg {
  transform: rotate(-125deg) scaleX(-1);
}

to round the border of your line you can use

  stroke-linecap: round;

#mySvg {
  transform: rotate(-125deg) scaleX(-1);
}

#mySvg circle {
  stroke-linecap: round;
  shape-rendering: geometricPrecision;
}

<svg id="mySvg" width="4.5rem" height="4.5rem" viewBox="0 0 40 40">
  <circle class="pieSegment segment1" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#1a0d1c" stroke-dashoffset="20" stroke-dasharray="100" stroke-width="5" pathLength="100"></circle>
  <circle class="pieSegment segment3" cx="20" cy="20" r="15.915494309189533" fill="transparent" stroke="#e9ad61" stroke-dashoffset="80" stroke-dasharray="100" stroke-width="5" pathLength="100"></circle>
</svg>


问:
Image registration problem : Very bad image registration result
I am trying to perform image registration and my registration output is completely bad .

Following is my code , the images that i posses are models of wounds acquired at different camera angle, links for the acquired images and output image is provided below for your review

```<code>import numpy as np
import cv2
from matplotlib import pyplot as plt

im1 = cv2.imread('/home/Documents/image_registration/1.jpg')          # Image that needs to be registered.
im2 = cv2.imread('/home/Documents/image_registration/3.jpg') # trainImage

img1 = cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY)
img2 = cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY)

# Initiate ORB detector
orb = cv2.ORB_create(5000)  #Registration works with at least 50 points

# find the keypoints and descriptors with orb
kp1, des1 = orb.detectAndCompute(img1, None)  #kp1 --> list of keypoints
kp2, des2 = orb.detectAndCompute(img2, None)

#Brute-Force matcher takes the descriptor of one feature in first set and is
 # create Matcher object

matcher = cv2.DescriptorMatcher_create(cv2.DESCRIPTOR_MATCHER_BRUTEFORCE_HAMMING)

# Match descriptors.
matches = matcher.match(des1, des2, None)  #Creates a list of all matches, just like keypoints

# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)

#Like we used cv2.drawKeypoints() to draw keypoints,
#cv2.drawMatches() helps us to draw the matches.

img3 = cv2.drawMatches(im1,kp1, im2, kp2, matches[:500], None)

#cv2.imshow("Matches image", img3)
#cv2.waitKey(0)

#Now let us use these key points to register two images.
#Can be used for distortion correction or alignment

#Second set to #trainIdx.

points1 = np.zeros((len(matches), 2), dtype=np.float32)  #Prints empty array of size equal to (matches, 2)
points2 = np.zeros((len(matches), 2), dtype=np.float32)

for i, match in enumerate(matches):
   points1[i, :] = kp1[match.queryIdx].pt    #gives index of the descriptor in the list of query descriptors
   points2[i, :] = kp2[match.trainIdx].pt    #gives index of the descriptor in the list of train descriptors

h, mask = cv2.findHomography(points1, points2, cv2.RANSAC)

  # Use homography
height, width, channels = im2.shape
im1Reg = cv2.warpPerspective(im1, h, (width, height))  #Applies a perspective transformation to an image.

print("Estimated homography : \n",  h)

#cv2.imshow("Registered image", im1Reg)
#cv2.waitKey()

cv2.imwrite ( '/home/Documents/image_registration/output.jpg' , im1Reg)
</code>```

image 1

image 3

Output registration

Kindly suggest me the problem with  my approach

答:
in python tuples are immutable and sort function (in python list) is sorting in place and that's why it doesn't exist on tuples.
to sort the tuples you should use the sorted function which returns a new list

in your case -

```<code>sorted(matches, key = lambda x: x.distance)
</code>```

Body:
I am trying to perform image registration and my registration output is completely bad .

Following is my code , the images that i posses are models of wounds acquired at different camera angle, links for the acquired images and output image is provided below for your review

import numpy as np
import cv2
from matplotlib import pyplot as plt

im1 = cv2.imread('/home/Documents/image_registration/1.jpg')          # Image that needs to be registered.
im2 = cv2.imread('/home/Documents/image_registration/3.jpg') # trainImage

img1 = cv2.cvtColor(im1, cv2.COLOR_BGR2GRAY)
img2 = cv2.cvtColor(im2, cv2.COLOR_BGR2GRAY)

# Initiate ORB detector
orb = cv2.ORB_create(5000)  #Registration works with at least 50 points

# find the keypoints and descriptors with orb
kp1, des1 = orb.detectAndCompute(img1, None)  #kp1 --> list of keypoints
kp2, des2 = orb.detectAndCompute(img2, None)

#Brute-Force matcher takes the descriptor of one feature in first set and is
 # create Matcher object

matcher = cv2.DescriptorMatcher_create(cv2.DESCRIPTOR_MATCHER_BRUTEFORCE_HAMMING)

# Match descriptors.
matches = matcher.match(des1, des2, None)  #Creates a list of all matches, just like keypoints

# Sort them in the order of their distance.
matches = sorted(matches, key = lambda x:x.distance)

#Like we used cv2.drawKeypoints() to draw keypoints,
#cv2.drawMatches() helps us to draw the matches.

img3 = cv2.drawMatches(im1,kp1, im2, kp2, matches[:500], None)

#cv2.imshow("Matches image", img3)
#cv2.waitKey(0)

#Now let us use these key points to register two images.
#Can be used for distortion correction or alignment

#Second set to #trainIdx.

points1 = np.zeros((len(matches), 2), dtype=np.float32)  #Prints empty array of size equal to (matches, 2)
points2 = np.zeros((len(matches), 2), dtype=np.float32)

for i, match in enumerate(matches):
   points1[i, :] = kp1[match.queryIdx].pt    #gives index of the descriptor in the list of query descriptors
   points2[i, :] = kp2[match.trainIdx].pt    #gives index of the descriptor in the list of train descriptors

h, mask = cv2.findHomography(points1, points2, cv2.RANSAC)

  # Use homography
height, width, channels = im2.shape
im1Reg = cv2.warpPerspective(im1, h, (width, height))  #Applies a perspective transformation to an image.

print("Estimated homography : \n",  h)

#cv2.imshow("Registered image", im1Reg)
#cv2.waitKey()

cv2.imwrite ( '/home/Documents/image_registration/output.jpg' , im1Reg)

image 1

image 3

Output registration

Kindly suggest me the problem with  my approach

Body:
in python tuples are immutable and sort function (in python list) is sorting in place and that's why it doesn't exist on tuples.
to sort the tuples you should use the sorted function which returns a new list

in your case -

sorted(matches, key = lambda x: x.distance)


问:
JTable wait indicator
I have java applet with JTable. Due to lots of data and poor network bandwidth it takes lots of time to perform any operation like load the table or change it.
I'm thinking about adding sort of activity indicator to let user know that his request is processing.
Before i use JProgressBar, I'd like to know whether there are other options like ajax activity flower.

答: You can use JBusyComponent for this. Just wrap your Table or the Scrollpane in the JBusyComponent. But remember to load the data outside the event dispatch thread. For this you can use the SwingWorker as suggested in the other answer. JBusyComponent already provides a BusySwingWorker for this.</p>

ContentLicense: CC BY-SA 3.0

Title: JTable wait indicator


问:
Image Processing Performance iOS Apps
More of a general interest question relating to iOS. I’m interested in image processing and I’m wondering if anyone has any inkling how these apps (sample images below) manage to perform seemingly very compute intensive actions such as pixel sorting in a very responsive way.

Are they using Core Image filters? Perhaps leveraging Metal?

答: I'm recommending using Metal, more opportunity for optimisations.</p>

Title: Image Processing Performance iOS Apps


问:
What kind of JSON structure is the Alpha Vantage API data, and how to convert it to a pandas dataframe?
I have an Alpha Vantage API demo working in a Google Colab notebook, and am trying to convert that data response to a pandas dataframe.

However, I'm not clear on what the JSON data structure is, which is making it difficult to find the right python code.

This is the demo code that's working:

```<code>import requests
import pandas as pd
import json

# replace the "demo" apikey below with your own key from https://www.alphavantage.co/support/#api-key
url = 'https://www.alphavantage.co/query?function=CRYPTO_INTRADAY&symbol=ETH&market=USD&interval=15min&apikey=demo'
r = requests.get(url)
data = r.json()

print(data)
</code>```

And this is a sample of the data it's returning:

```<code>{'Meta Data': {'1. Information': 'Crypto Intraday (15min) Time Series', '2. Digital Currency Code': 'ETH', '3. Digital Currency Name': 'Ethereum', '4. Market Code': 'USD', '5. Market Name': 'United States Dollar', '6. Last Refreshed': '2022-02-10 04:00:00', '7. Interval': '15min', '8. Output Size': 'Compact', '9. Time Zone': 'UTC'}, 'Time Series Crypto (15min)': {'2022-02-10 04:00:00': {'1. open': '3179.59000', '2. high': '3180.47000', '3. low': '3173.82000', '4. close': '3175.86000', '5. volume': 1031}, '2022-02-10 03:45:00': {'1. open': '3180.39000', '2. high': '3183.52000', '3. low': '3176.24000', '4. close': '3179.60000', '5. volume': 1924}, '2022-02-10 03:30:00': {'1. open': '3185.17000', '2. high': '3188.40000', '3. low': '3179.04000', '4. close': '3180.40000', '5. volume': 2018}, '2022-02-10 03:15:00': {'1. open': '3177.58000', '2. high': '3186.24000', '3. low': '3175.01000', '4. close': '3185.17000', '5. volume': 2376}, '2022-02-10 03:00:00': {'1. open': '3186.58000', '2. high': '3189.99000', '3. low': '3170.87000', '4. close': '3177.58000', '5. volume': 6907}, '2022-02-10 02:45:00': {'1. open': '3221.54000', '2. high': '3224.80000', '3. low': '3184.01000', '4. close': '3186.58000', '5. volume': 8794}, '2022-02-10 02:30:00': {'1. open': '3228.30000', '2. high': '3229.00000', '3. low': '3220.00000', '4. close': '3221.53000', '5. volume': 1552}, '2022-02-10 02:15:00': {'1. open': '3225.79000', '2. high': '3228.58000', '3. low': '3220.86000', '4. close': '3228.29000', '5. volume': 1852}, '2022-02-10 02:00:00': {'1. open': '3224.28000', '2. high': '3229.26000', '3. low': '3215.67000', '4. close': '3225.80000', '5. volume': 2698}, '2022-02-10 01:45:00': {'1. open': '3225.74000', '2. high': '3228.92000', '3. low': '3219.29000', '4. close': '3224.27000', '5. volume': 1529}, '2022-02-10 01:30:00': {'1. open': '3214.24000', '2. high': '3227.95000', '3. low': '3207.18000', '4. close': '3225.73000', '5. volume': 2239}, '2022-02-10 01:15:00': {'1. open': '3225.78000', '2. high': '3227.94000', '3. low': '3213.00000', '4. close': '3214.23000', '5. volume': 1930}, '2022-02-10 01:00:00': {'1. open': '3220.08000', '2. high': '3225.99000', '3. low': '3217.40000', '4. close': '3225.78000', '5. volume': 2333}, '2022-02-10 00:45:00': {'1. open': '3221.87000', '2. high': '3224.36000', '3. low': '3213.58000', '4. close': '3220.09000', '5. volume': 1912}, '2022-02-10 00:30:00': {'1. open': '3224.74000', '2. high': '3229.21000', '3. low': '3220.03000', '4. close': '3221.87000', '5. volume': 2299}, '2022-02-10 00:15:00': {'1. open': '3235.70000', '2. high': '3235.82000', '3. low': '3211.27000', '4. close': '3224.74000', '5. volume': 5900}, '2022-02-10 00:00:00': {'1. open': '3243.60000', '2. high': '3248.98000', '3. low': '3233.08000', '4. close': '3235.71000', '5. volume': 3388}, '2022-02-09 23:45:00': {'1. open': '3234.46000', '2. high': '3244.75000', '3. low': '3232.95000', '4. close': '3243.94000', '5. volume': 3475}, '2022-02-09 23:30:00': {'1. open': '3236.47000', '2. high': '3240.00000', '3. low': '3231.41000', '4. close': '3234.82000', '5. volume': 2475}, '2022-02-09 23:15:00': {'1. open': '3242.38000', '2. high': '3245.76000', '3. low': '3232.13000', '4. close': '3236.62000', '5. volume': 2145}, '2022-02-09 23:00:00': {'1. open': '3251.01000', '2. high': '3251.03000', '3. low': '3239.50000', '4. close': '3242.37000', '5. volume': 2438}, '2022-02-09 22:45:00': {'1. open': '3242.50000', '2. high': '3254.57000', '3. low': '3241.18000', '4. close': '3251.02000', '5. volume': 1700}, '2022-02-09 22:30:00': {'1. open': '3233.52000', '2. high': '3245.39000', '3. low': '3232.34000', '4. close': '3242.50000', '5. volume': 1597}, '2022-02-09 22:15:00': {'1. open': '3237.01000', '2. high': '3245.59000', '3. low': '3230.83000', '4. close': '3233.53000', '5. volume': 2708}, '2022-02-09 22:00:00': {'1. open': '3236.09000', '2. high': '3247.00000', '3. low': '3234.70000', '4. close': '3236.85000', '5. volume': 3090}, '2022-02-09 21:45:00': {'1. open': '3249.00000', '2. high': '3249.99000', '3. low': '3234.64000', '4. close': '3236.08000', '5. volume': 3263}, '2022-02-09 21:30:00': {'1. open': '3253.56000', '2. high': '3256.00000', '3. low': '3247.01000', '4. close': '3249.01000', '5. volume': 2060}, '2022-02-09 21:15:00': {'1. open': '3254.33000', '2. high': '3256.80000', '3. low': '3245.05000', '4. close': '3253.56000', '5. volume': 1957}, '2022-02-09 21:00:00': {'1. open': '3258.74000', '2. high': '3261.22000', '3. low': '3248.37000', '4. close': '3254.34000', '5. volume': 4320}, '2022-02-09 20:45:00': {'1. open': '3259.41000', '2. high': '3263.21000', '3. low': '3250.30000', '4. close': '3258.74000', '5. volume': 4215}, '2022-02-09 20:30:00': {'1. open': '3260.67000', '2. high': '3269.70000', '3. low': '3253.49000', '4. close': '3259.42000', '5. volume': 5505}, '2022-02-09 20:15:00': {'1. open': '3244.45000', '2. high': '3264.97000', '3. low': '3240.60000', '4. close': '3260.67000', '5. volume': 4368}, '2022-02-09 20:00:00': {'1. open': '3246.94000', '2. high': '3260.75000', '3. low': '3244.41000', '4. close': '3244.41000', '5. volume': 4653}, '2022-02-09 19:45:00': {'1. open': '3250.72000', '2. high': '3256.63000', '3. low': '3243.77000', '4. close': '3246.94000', '5. volume': 3484}, '2022-02-09 19:30:00': {'1. open': '3247.01000', '2. high': '3258.00000', '3. low': '3237.17000', '4. close': '3250.72000', '5. volume': 5654}, '2022-02-09 19:15:00': {'1. open': '3226.37000', '2. high': '3254.00000', '3. low': '3220.07000', '4. close': '3247.01000', '5. volume': 10292}, '2022-02-09 19:00:00': {'1. open': '3210.13000', '2. high': '3238.50000', '3. low': '3207.01000', '4. close': '3226.38000', '5. volume': 10794}, '2022-02-09 18:45:00': {'1. open': '3204.34000', '2. high': '3210.99000', '3. low': '3197.89000', '4. close': '3210.13000', '5. volume': 2054}, '2022-02-09 18:30:00': {'1. open': '3193.03000', '2. high': '3205.00000', '3. low': '3187.13000', '4. close': '3204.35000', '5. volume': 2349}, '2022-02-09 18:15:00': {'1. open': '3193.37000', '2. high': '3200.56000', '3. low': '3183.02000', '4. close': '3193.00000', '5. volume': 2203}, '2022-02-09 18:00:00': {'1. open': '3199.76000', '2. high': '3204.07000', '3. low': '3191.63000', '4. close': '3193.76000', '5. volume': 1864}, '2022-02-09 17:45:00': {'1. open': '3203.52000', '2. high': '3207.57000', '3. low': '3192.66000', '4. close': '3199.76000', '5. volume': 2315}, '2022-02-09 17:30:00': {'1. open': '3206.02000', '2. high': '3211.36000', '3. low': '3196.97000', '4. close': '3203.52000', '5. volume': 3534}, '2022-02-09 17:15:00': {'1. open': '3205.73000', '2. high': '3217.69000', '3. low': '3205.73000', '4. close': '3206.01000', '5. volume': 3901}, '2022-02-09 17:00:00': {'1. open': '3202.95000', '2. high': '3208.80000', '3. low': '3198.49000', '4. close': '3205.74000', '5. volume': 3619}, '2022-02-09 16:45:00': {'1. open': '3193.45000', '2. high': '3212.28000', '3. low': '3193.06000', '4. close': '3202.95000', '5. volume': 6311}, '2022-02-09 16:30:00': {'1. open': '3183.83000', '2. high': '3194.75000', '3. low': '3179.19000', '4. close': '3193.46000', '5. volume': 3741}, '2022-02-09 16:15:00': {'1. open': '3172.45000', '2. high': '3189.38000', '3. low': '3169.50000', '4. close': '3183.83000', '5. volume': 2725}, '2022-02-09 16:00:00': {'1. open': '3178.44000', '2. high': '3195.00000', '3. low': '3163.02000', '4. close': '3172.45000', '5. volume': 10011}, '2022-02-09 15:45:00': {'1. open': '3166.00000', '2. high': '3179.80000', '3. low': '3165.78000', '4. close': '3178.45000', '5. volume': 2626}, '2022-02-09 15:30:00': {'1. open': '3177.69000', '2. high': '3184.61000', '3. low': '3152.44000', '4. close': '3166.00000', '5. volume': 7079}, '2022-02-09 15:15:00': {'1. open': '3181.27000', '2. high': '3181.50000', '3. low': '3166.54000', '4. close': '3177.68000', '5. volume': 4888}, '2022-02-09 15:00:00': {'1. open': '3188.49000', '2. high': '3200.91000', '3. low': '3179.47000', '4. close': '3181.27000', '5. volume': 3970}, '2022-02-09 14:45:00': {'1. open': '3202.56000', '2. high': '3209.75000', '3. low': '3188.00000', '4. close': '3188.50000', '5. volume': 5743}, '2022-02-09 14:30:00': {'1. open': '3186.82000', '2. high': '3216.99000', '3. low': '3182.91000', '4. close': '3202.61000', '5. volume': 6893}, '2022-02-09 14:15:00': {'1. open': '3179.02000', '2. high': '3190.91000', '3. low': '3171.48000', '4. close': '3186.83000', '5. volume': 2638}, '2022-02-09 14:00:00': {'1. open': '3180.69000', '2. high': '3186.70000', '3. low': '3161.62000', '4. close': '3179.01000', '5. volume': 5528}, '2022-02-09 13:45:00': {'1. open': '3198.63000', '2. high': '3202.50000', '3. low': '3179.34000', '4. close': '3180.94000', '5. volume': 5184}, '2022-02-09 13:30:00': {'1. open': '3198.74000', '2. high': '3204.45000', '3. low': '3186.76000', '4. close': '3198.64000', '5. volume': 4447}, '2022-02-09 13:15:00': {'1. open': '3200.08000', '2. high': '3206.00000', '3. low': '3191.43000', '4. close': '3198.74000', '5. volume': 7063}, '2022-02-09 13:00:00': {'1. open': '3181.70000', '2. high': '3207.99000', '3. low': '3174.43000', '4. close': '3200.07000', '5. volume': 9626}, '2022-02-09 12:45:00': {'1. open': '3190.59000', '2. high': '3193.53000', '3. low': '3174.70000', '4. close': '3181.49000', '5. volume': 5283}, '2022-02-09 12:30:00': {'1. open': '3154.62000', '2. high': '3192.78000', '3. low': '3151.18000', '4. close': '3190.59000', '5. volume': 11267}, '2022-02-09 12:15:00': {'1. open': '3154.60000', '2. high': '3159.75000', '3. low': '3150.14000', '4. close': '3154.62000', '5. volume': 3160}, '2022-02-09 12:00:00': {'1. open': '3152.89000', '2. high': '3158.83000', '3. low': '3140.00000', '4. close': '3154.61000', '5. volume': 5264}, '2022-02-09 11:45:00': {'1. open': '3139.54000', '2. high': '3158.37000', '3. low': '3139.37000', '4. close': '3152.89000', '5. volume': 5061}, '2022-02-09 11:30:00': {'1. open': '3138.69000', '2. high': '3146.00000', '3. low': '3134.57000', '4. close': '3139.53000', '5. volume': 4378}, '2022-02-09 11:15:00': {'1. open': '3126.04000', '2. high': '3139.87000', '3. low': '3124.39000', '4. close': '3138.70000', '5. volume': 3621}, '2022-02-09 11:00:00': {'1. open': '3136.30000', '2. high': '3142.33000', '3. low': '3119.04000', '4. close': '3126.04000', '5. volume': 3827}, '2022-02-09 10:45:00': {'1. open': '3131.03000', '2. high': '3137.00000', '3. low': '3123.14000', '4. close': '3136.30000', '5. volume': 3638}, '2022-02-09 10:30:00': {'1. open': '3135.25000', '2. high': '3142.97000', '3. low': '3127.20000', '4. close': '3131.02000', '5. volume': 3903}, '2022-02-09 10:15:00': {'1. open': '3123.50000', '2. high': '3143.83000', '3. low': '3118.56000', '4. close': '3135.24000', '5. volume': 6848}, '2022-02-09 10:00:00': {'1. open': '3099.46000', '2. high': '3128.43000', '3. low': '3099.11000', '4. close': '3123.50000', '5. volume': 5342}, '2022-02-09 09:45:00': {'1. open': '3105.92000', '2. high': '3111.37000', '3. low': '3096.00000', '4. close': '3099.21000', '5. volume': 2038}, '2022-02-09 09:30:00': {'1. open': '3109.85000', '2. high': '3115.96000', '3. low': '3091.92000', '4. close': '3105.93000', '5. volume': 3369}, '2022-02-09 09:15:00': {'1. open': '3110.20000', '2. high': '3116.00000', '3. low': '3105.85000', '4. close': '3109.83000', '5. volume': 2234}, '2022-02-09 09:00:00': {'1. open': '3094.09000', '2. high': '3115.00000', '3. low': '3094.09000', '4. close': '3110.21000', '5. volume': 5781}, '2022-02-09 08:45:00': {'1. open': '3081.81000', '2. high': '3099.51000', '3. low': '3081.43000', '4. close': '3094.10000', '5. volume': 2801}, '2022-02-09 08:30:00': {'1. open': '3079.49000', '2. high': '3084.93000', '3. low': '3069.00000', '4. close': '3081.81000', '5. volume': 2372}, '2022-02-09 08:15:00': {'1. open': '3097.48000', '2. high': '3103.96000', '3. low': '3069.61000', '4. close': '3079.48000', '5. volume': 5602}, '2022-02-09 08:00:00': {'1. open': '3105.93000', '2. high': '3113.69000', '3. low': '3094.51000', '4. close': '3097.49000', '5. volume': 2361}, '2022-02-09 07:45:00': {'1. open': '3088.19000', '2. high': '3112.61000', '3. low': '3087.68000', '4. close': '3105.93000', '5. volume': 3146}, '2022-02-09 07:30:00': {'1. open': '3087.07000', '2. high': '3091.80000', '3. low': '3079.69000', '4. close': '3088.16000', '5. volume': 2029}, '2022-02-09 07:15:00': {'1. open': '3101.27000', '2. high': '3101.34000', '3. low': '3085.87000', '4. close': '3087.07000', '5. volume': 2136}, '2022-02-09 07:00:00': {'1. open': '3099.93000', '2. high': '3106.57000', '3. low': '3092.94000', '4. close': '3101.26000', '5. volume': 2478}, '2022-02-09 06:45:00': {'1. open': '3101.43000', '2. high': '3107.29000', '3. low': '3098.00000', '4. close': '3099.93000', '5. volume': 2642}, '2022-02-09 06:30:00': {'1. open': '3091.52000', '2. high': '3105.41000', '3. low': '3089.74000', '4. close': '3101.49000', '5. volume': 2442}, '2022-02-09 06:15:00': {'1. open': '3087.91000', '2. high': '3099.99000', '3. low': '3085.49000', '4. close': '3091.52000', '5. volume': 1486}, '2022-02-09 06:00:00': {'1. open': '3089.75000', '2. high': '3096.00000', '3. low': '3084.43000', '4. close': '3087.90000', '5. volume': 2402}, '2022-02-09 05:45:00': {'1. open': '3100.22000', '2. high': '3106.40000', '3. low': '3087.84000', '4. close': '3089.75000', '5. volume': 3642}, '2022-02-09 05:30:00': {'1. open': '3072.85000', '2. high': '3101.64000', '3. low': '3071.27000', '4. close': '3100.23000', '5. volume': 3586}, '2022-02-09 05:15:00': {'1. open': '3066.72000', '2. high': '3074.87000', '3. low': '3055.00000', '4. close': '3072.85000', '5. volume': 2808}, '2022-02-09 05:00:00': {'1. open': '3080.40000', '2. high': '3084.02000', '3. low': '3057.68000', '4. close': '3066.72000', '5. volume': 4779}, '2022-02-09 04:45:00': {'1. open': '3085.53000', '2. high': '3094.37000', '3. low': '3079.70000', '4. close': '3080.41000', '5. volume': 2142}, '2022-02-09 04:30:00': {'1. open': '3083.75000', '2. high': '3088.77000', '3. low': '3078.20000', '4. close': '3085.53000', '5. volume': 1813}, '2022-02-09 04:15:00': {'1. open': '3089.00000', '2. high': '3091.52000', '3. low': '3081.56000', '4. close': '3083.67000', '5. volume': 1639}, '2022-02-09 04:00:00': {'1. open': '3076.52000', '2. high': '3090.13000', '3. low': '3075.04000', '4. close': '3089.00000', '5. volume': 2153}, '2022-02-09 03:45:00': {'1. open': '3074.50000', '2. high': '3078.82000', '3. low': '3072.34000', '4. close': '3076.52000', '5. volume': 1178}, '2022-02-09 03:30:00': {'1. open': '3079.31000', '2. high': '3084.81000', '3. low': '3073.05000', '4. close': '3074.49000', '5. volume': 1746}, '2022-02-09 03:15:00': {'1. open': '3073.70000', '2. high': '3081.01000', '3. low': '3073.70000', '4. close': '3079.32000', '5. volume': 2243}}}

</code>```

I ran this code to try and put that response into a dataframe:

```<code>df = pd.DataFrame(data["Time Series (15min)"])
df = df.T  # Transpose Dataframe for desired results
</code>```

My understanding is the data response is a JSON dictionary data structure, but that produced this error message:

```<code>---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-ba79690310fb> in <module>()
----> 1 df = pd.DataFrame(data["Time Series (15min)"])
      2 df = df.T  # Transpose Dataframe for desired results

KeyError: 'Time Series (15min)'
</code>```

I don't understand the error message, but am thinking it must be something from pandas and not the AlphaVantage API, though I haven't been able to find any clear information on what I should be using instead of "Time Series (15min)"

Greatly appreciate any input on how to approach this.

Body:
I have an Alpha Vantage API demo working in a Google Colab notebook, and am trying to convert that data response to a pandas dataframe.

However, I'm not clear on what the JSON data structure is, which is making it difficult to find the right python code.

This is the demo code that's working:

import requests
import pandas as pd
import json

# replace the "demo" apikey below with your own key from https://www.alphavantage.co/support/#api-key
url = 'https://www.alphavantage.co/query?function=CRYPTO_INTRADAY&symbol=ETH&market=USD&interval=15min&apikey=demo'
r = requests.get(url)
data = r.json()

print(data)

And this is a sample of the data it's returning:

{'Meta Data': {'1. Information': 'Crypto Intraday (15min) Time Series', '2. Digital Currency Code': 'ETH', '3. Digital Currency Name': 'Ethereum', '4. Market Code': 'USD', '5. Market Name': 'United States Dollar', '6. Last Refreshed': '2022-02-10 04:00:00', '7. Interval': '15min', '8. Output Size': 'Compact', '9. Time Zone': 'UTC'}, 'Time Series Crypto (15min)': {'2022-02-10 04:00:00': {'1. open': '3179.59000', '2. high': '3180.47000', '3. low': '3173.82000', '4. close': '3175.86000', '5. volume': 1031}, '2022-02-10 03:45:00': {'1. open': '3180.39000', '2. high': '3183.52000', '3. low': '3176.24000', '4. close': '3179.60000', '5. volume': 1924}, '2022-02-10 03:30:00': {'1. open': '3185.17000', '2. high': '3188.40000', '3. low': '3179.04000', '4. close': '3180.40000', '5. volume': 2018}, '2022-02-10 03:15:00': {'1. open': '3177.58000', '2. high': '3186.24000', '3. low': '3175.01000', '4. close': '3185.17000', '5. volume': 2376}, '2022-02-10 03:00:00': {'1. open': '3186.58000', '2. high': '3189.99000', '3. low': '3170.87000', '4. close': '3177.58000', '5. volume': 6907}, '2022-02-10 02:45:00': {'1. open': '3221.54000', '2. high': '3224.80000', '3. low': '3184.01000', '4. close': '3186.58000', '5. volume': 8794}, '2022-02-10 02:30:00': {'1. open': '3228.30000', '2. high': '3229.00000', '3. low': '3220.00000', '4. close': '3221.53000', '5. volume': 1552}, '2022-02-10 02:15:00': {'1. open': '3225.79000', '2. high': '3228.58000', '3. low': '3220.86000', '4. close': '3228.29000', '5. volume': 1852}, '2022-02-10 02:00:00': {'1. open': '3224.28000', '2. high': '3229.26000', '3. low': '3215.67000', '4. close': '3225.80000', '5. volume': 2698}, '2022-02-10 01:45:00': {'1. open': '3225.74000', '2. high': '3228.92000', '3. low': '3219.29000', '4. close': '3224.27000', '5. volume': 1529}, '2022-02-10 01:30:00': {'1. open': '3214.24000', '2. high': '3227.95000', '3. low': '3207.18000', '4. close': '3225.73000', '5. volume': 2239}, '2022-02-10 01:15:00': {'1. open': '3225.78000', '2. high': '3227.94000', '3. low': '3213.00000', '4. close': '3214.23000', '5. volume': 1930}, '2022-02-10 01:00:00': {'1. open': '3220.08000', '2. high': '3225.99000', '3. low': '3217.40000', '4. close': '3225.78000', '5. volume': 2333}, '2022-02-10 00:45:00': {'1. open': '3221.87000', '2. high': '3224.36000', '3. low': '3213.58000', '4. close': '3220.09000', '5. volume': 1912}, '2022-02-10 00:30:00': {'1. open': '3224.74000', '2. high': '3229.21000', '3. low': '3220.03000', '4. close': '3221.87000', '5. volume': 2299}, '2022-02-10 00:15:00': {'1. open': '3235.70000', '2. high': '3235.82000', '3. low': '3211.27000', '4. close': '3224.74000', '5. volume': 5900}, '2022-02-10 00:00:00': {'1. open': '3243.60000', '2. high': '3248.98000', '3. low': '3233.08000', '4. close': '3235.71000', '5. volume': 3388}, '2022-02-09 23:45:00': {'1. open': '3234.46000', '2. high': '3244.75000', '3. low': '3232.95000', '4. close': '3243.94000', '5. volume': 3475}, '2022-02-09 23:30:00': {'1. open': '3236.47000', '2. high': '3240.00000', '3. low': '3231.41000', '4. close': '3234.82000', '5. volume': 2475}, '2022-02-09 23:15:00': {'1. open': '3242.38000', '2. high': '3245.76000', '3. low': '3232.13000', '4. close': '3236.62000', '5. volume': 2145}, '2022-02-09 23:00:00': {'1. open': '3251.01000', '2. high': '3251.03000', '3. low': '3239.50000', '4. close': '3242.37000', '5. volume': 2438}, '2022-02-09 22:45:00': {'1. open': '3242.50000', '2. high': '3254.57000', '3. low': '3241.18000', '4. close': '3251.02000', '5. volume': 1700}, '2022-02-09 22:30:00': {'1. open': '3233.52000', '2. high': '3245.39000', '3. low': '3232.34000', '4. close': '3242.50000', '5. volume': 1597}, '2022-02-09 22:15:00': {'1. open': '3237.01000', '2. high': '3245.59000', '3. low': '3230.83000', '4. close': '3233.53000', '5. volume': 2708}, '2022-02-09 22:00:00': {'1. open': '3236.09000', '2. high': '3247.00000', '3. low': '3234.70000', '4. close': '3236.85000', '5. volume': 3090}, '2022-02-09 21:45:00': {'1. open': '3249.00000', '2. high': '3249.99000', '3. low': '3234.64000', '4. close': '3236.08000', '5. volume': 3263}, '2022-02-09 21:30:00': {'1. open': '3253.56000', '2. high': '3256.00000', '3. low': '3247.01000', '4. close': '3249.01000', '5. volume': 2060}, '2022-02-09 21:15:00': {'1. open': '3254.33000', '2. high': '3256.80000', '3. low': '3245.05000', '4. close': '3253.56000', '5. volume': 1957}, '2022-02-09 21:00:00': {'1. open': '3258.74000', '2. high': '3261.22000', '3. low': '3248.37000', '4. close': '3254.34000', '5. volume': 4320}, '2022-02-09 20:45:00': {'1. open': '3259.41000', '2. high': '3263.21000', '3. low': '3250.30000', '4. close': '3258.74000', '5. volume': 4215}, '2022-02-09 20:30:00': {'1. open': '3260.67000', '2. high': '3269.70000', '3. low': '3253.49000', '4. close': '3259.42000', '5. volume': 5505}, '2022-02-09 20:15:00': {'1. open': '3244.45000', '2. high': '3264.97000', '3. low': '3240.60000', '4. close': '3260.67000', '5. volume': 4368}, '2022-02-09 20:00:00': {'1. open': '3246.94000', '2. high': '3260.75000', '3. low': '3244.41000', '4. close': '3244.41000', '5. volume': 4653}, '2022-02-09 19:45:00': {'1. open': '3250.72000', '2. high': '3256.63000', '3. low': '3243.77000', '4. close': '3246.94000', '5. volume': 3484}, '2022-02-09 19:30:00': {'1. open': '3247.01000', '2. high': '3258.00000', '3. low': '3237.17000', '4. close': '3250.72000', '5. volume': 5654}, '2022-02-09 19:15:00': {'1. open': '3226.37000', '2. high': '3254.00000', '3. low': '3220.07000', '4. close': '3247.01000', '5. volume': 10292}, '2022-02-09 19:00:00': {'1. open': '3210.13000', '2. high': '3238.50000', '3. low': '3207.01000', '4. close': '3226.38000', '5. volume': 10794}, '2022-02-09 18:45:00': {'1. open': '3204.34000', '2. high': '3210.99000', '3. low': '3197.89000', '4. close': '3210.13000', '5. volume': 2054}, '2022-02-09 18:30:00': {'1. open': '3193.03000', '2. high': '3205.00000', '3. low': '3187.13000', '4. close': '3204.35000', '5. volume': 2349}, '2022-02-09 18:15:00': {'1. open': '3193.37000', '2. high': '3200.56000', '3. low': '3183.02000', '4. close': '3193.00000', '5. volume': 2203}, '2022-02-09 18:00:00': {'1. open': '3199.76000', '2. high': '3204.07000', '3. low': '3191.63000', '4. close': '3193.76000', '5. volume': 1864}, '2022-02-09 17:45:00': {'1. open': '3203.52000', '2. high': '3207.57000', '3. low': '3192.66000', '4. close': '3199.76000', '5. volume': 2315}, '2022-02-09 17:30:00': {'1. open': '3206.02000', '2. high': '3211.36000', '3. low': '3196.97000', '4. close': '3203.52000', '5. volume': 3534}, '2022-02-09 17:15:00': {'1. open': '3205.73000', '2. high': '3217.69000', '3. low': '3205.73000', '4. close': '3206.01000', '5. volume': 3901}, '2022-02-09 17:00:00': {'1. open': '3202.95000', '2. high': '3208.80000', '3. low': '3198.49000', '4. close': '3205.74000', '5. volume': 3619}, '2022-02-09 16:45:00': {'1. open': '3193.45000', '2. high': '3212.28000', '3. low': '3193.06000', '4. close': '3202.95000', '5. volume': 6311}, '2022-02-09 16:30:00': {'1. open': '3183.83000', '2. high': '3194.75000', '3. low': '3179.19000', '4. close': '3193.46000', '5. volume': 3741}, '2022-02-09 16:15:00': {'1. open': '3172.45000', '2. high': '3189.38000', '3. low': '3169.50000', '4. close': '3183.83000', '5. volume': 2725}, '2022-02-09 16:00:00': {'1. open': '3178.44000', '2. high': '3195.00000', '3. low': '3163.02000', '4. close': '3172.45000', '5. volume': 10011}, '2022-02-09 15:45:00': {'1. open': '3166.00000', '2. high': '3179.80000', '3. low': '3165.78000', '4. close': '3178.45000', '5. volume': 2626}, '2022-02-09 15:30:00': {'1. open': '3177.69000', '2. high': '3184.61000', '3. low': '3152.44000', '4. close': '3166.00000', '5. volume': 7079}, '2022-02-09 15:15:00': {'1. open': '3181.27000', '2. high': '3181.50000', '3. low': '3166.54000', '4. close': '3177.68000', '5. volume': 4888}, '2022-02-09 15:00:00': {'1. open': '3188.49000', '2. high': '3200.91000', '3. low': '3179.47000', '4. close': '3181.27000', '5. volume': 3970}, '2022-02-09 14:45:00': {'1. open': '3202.56000', '2. high': '3209.75000', '3. low': '3188.00000', '4. close': '3188.50000', '5. volume': 5743}, '2022-02-09 14:30:00': {'1. open': '3186.82000', '2. high': '3216.99000', '3. low': '3182.91000', '4. close': '3202.61000', '5. volume': 6893}, '2022-02-09 14:15:00': {'1. open': '3179.02000', '2. high': '3190.91000', '3. low': '3171.48000', '4. close': '3186.83000', '5. volume': 2638}, '2022-02-09 14:00:00': {'1. open': '3180.69000', '2. high': '3186.70000', '3. low': '3161.62000', '4. close': '3179.01000', '5. volume': 5528}, '2022-02-09 13:45:00': {'1. open': '3198.63000', '2. high': '3202.50000', '3. low': '3179.34000', '4. close': '3180.94000', '5. volume': 5184}, '2022-02-09 13:30:00': {'1. open': '3198.74000', '2. high': '3204.45000', '3. low': '3186.76000', '4. close': '3198.64000', '5. volume': 4447}, '2022-02-09 13:15:00': {'1. open': '3200.08000', '2. high': '3206.00000', '3. low': '3191.43000', '4. close': '3198.74000', '5. volume': 7063}, '2022-02-09 13:00:00': {'1. open': '3181.70000', '2. high': '3207.99000', '3. low': '3174.43000', '4. close': '3200.07000', '5. volume': 9626}, '2022-02-09 12:45:00': {'1. open': '3190.59000', '2. high': '3193.53000', '3. low': '3174.70000', '4. close': '3181.49000', '5. volume': 5283}, '2022-02-09 12:30:00': {'1. open': '3154.62000', '2. high': '3192.78000', '3. low': '3151.18000', '4. close': '3190.59000', '5. volume': 11267}, '2022-02-09 12:15:00': {'1. open': '3154.60000', '2. high': '3159.75000', '3. low': '3150.14000', '4. close': '3154.62000', '5. volume': 3160}, '2022-02-09 12:00:00': {'1. open': '3152.89000', '2. high': '3158.83000', '3. low': '3140.00000', '4. close': '3154.61000', '5. volume': 5264}, '2022-02-09 11:45:00': {'1. open': '3139.54000', '2. high': '3158.37000', '3. low': '3139.37000', '4. close': '3152.89000', '5. volume': 5061}, '2022-02-09 11:30:00': {'1. open': '3138.69000', '2. high': '3146.00000', '3. low': '3134.57000', '4. close': '3139.53000', '5. volume': 4378}, '2022-02-09 11:15:00': {'1. open': '3126.04000', '2. high': '3139.87000', '3. low': '3124.39000', '4. close': '3138.70000', '5. volume': 3621}, '2022-02-09 11:00:00': {'1. open': '3136.30000', '2. high': '3142.33000', '3. low': '3119.04000', '4. close': '3126.04000', '5. volume': 3827}, '2022-02-09 10:45:00': {'1. open': '3131.03000', '2. high': '3137.00000', '3. low': '3123.14000', '4. close': '3136.30000', '5. volume': 3638}, '2022-02-09 10:30:00': {'1. open': '3135.25000', '2. high': '3142.97000', '3. low': '3127.20000', '4. close': '3131.02000', '5. volume': 3903}, '2022-02-09 10:15:00': {'1. open': '3123.50000', '2. high': '3143.83000', '3. low': '3118.56000', '4. close': '3135.24000', '5. volume': 6848}, '2022-02-09 10:00:00': {'1. open': '3099.46000', '2. high': '3128.43000', '3. low': '3099.11000', '4. close': '3123.50000', '5. volume': 5342}, '2022-02-09 09:45:00': {'1. open': '3105.92000', '2. high': '3111.37000', '3. low': '3096.00000', '4. close': '3099.21000', '5. volume': 2038}, '2022-02-09 09:30:00': {'1. open': '3109.85000', '2. high': '3115.96000', '3. low': '3091.92000', '4. close': '3105.93000', '5. volume': 3369}, '2022-02-09 09:15:00': {'1. open': '3110.20000', '2. high': '3116.00000', '3. low': '3105.85000', '4. close': '3109.83000', '5. volume': 2234}, '2022-02-09 09:00:00': {'1. open': '3094.09000', '2. high': '3115.00000', '3. low': '3094.09000', '4. close': '3110.21000', '5. volume': 5781}, '2022-02-09 08:45:00': {'1. open': '3081.81000', '2. high': '3099.51000', '3. low': '3081.43000', '4. close': '3094.10000', '5. volume': 2801}, '2022-02-09 08:30:00': {'1. open': '3079.49000', '2. high': '3084.93000', '3. low': '3069.00000', '4. close': '3081.81000', '5. volume': 2372}, '2022-02-09 08:15:00': {'1. open': '3097.48000', '2. high': '3103.96000', '3. low': '3069.61000', '4. close': '3079.48000', '5. volume': 5602}, '2022-02-09 08:00:00': {'1. open': '3105.93000', '2. high': '3113.69000', '3. low': '3094.51000', '4. close': '3097.49000', '5. volume': 2361}, '2022-02-09 07:45:00': {'1. open': '3088.19000', '2. high': '3112.61000', '3. low': '3087.68000', '4. close': '3105.93000', '5. volume': 3146}, '2022-02-09 07:30:00': {'1. open': '3087.07000', '2. high': '3091.80000', '3. low': '3079.69000', '4. close': '3088.16000', '5. volume': 2029}, '2022-02-09 07:15:00': {'1. open': '3101.27000', '2. high': '3101.34000', '3. low': '3085.87000', '4. close': '3087.07000', '5. volume': 2136}, '2022-02-09 07:00:00': {'1. open': '3099.93000', '2. high': '3106.57000', '3. low': '3092.94000', '4. close': '3101.26000', '5. volume': 2478}, '2022-02-09 06:45:00': {'1. open': '3101.43000', '2. high': '3107.29000', '3. low': '3098.00000', '4. close': '3099.93000', '5. volume': 2642}, '2022-02-09 06:30:00': {'1. open': '3091.52000', '2. high': '3105.41000', '3. low': '3089.74000', '4. close': '3101.49000', '5. volume': 2442}, '2022-02-09 06:15:00': {'1. open': '3087.91000', '2. high': '3099.99000', '3. low': '3085.49000', '4. close': '3091.52000', '5. volume': 1486}, '2022-02-09 06:00:00': {'1. open': '3089.75000', '2. high': '3096.00000', '3. low': '3084.43000', '4. close': '3087.90000', '5. volume': 2402}, '2022-02-09 05:45:00': {'1. open': '3100.22000', '2. high': '3106.40000', '3. low': '3087.84000', '4. close': '3089.75000', '5. volume': 3642}, '2022-02-09 05:30:00': {'1. open': '3072.85000', '2. high': '3101.64000', '3. low': '3071.27000', '4. close': '3100.23000', '5. volume': 3586}, '2022-02-09 05:15:00': {'1. open': '3066.72000', '2. high': '3074.87000', '3. low': '3055.00000', '4. close': '3072.85000', '5. volume': 2808}, '2022-02-09 05:00:00': {'1. open': '3080.40000', '2. high': '3084.02000', '3. low': '3057.68000', '4. close': '3066.72000', '5. volume': 4779}, '2022-02-09 04:45:00': {'1. open': '3085.53000', '2. high': '3094.37000', '3. low': '3079.70000', '4. close': '3080.41000', '5. volume': 2142}, '2022-02-09 04:30:00': {'1. open': '3083.75000', '2. high': '3088.77000', '3. low': '3078.20000', '4. close': '3085.53000', '5. volume': 1813}, '2022-02-09 04:15:00': {'1. open': '3089.00000', '2. high': '3091.52000', '3. low': '3081.56000', '4. close': '3083.67000', '5. volume': 1639}, '2022-02-09 04:00:00': {'1. open': '3076.52000', '2. high': '3090.13000', '3. low': '3075.04000', '4. close': '3089.00000', '5. volume': 2153}, '2022-02-09 03:45:00': {'1. open': '3074.50000', '2. high': '3078.82000', '3. low': '3072.34000', '4. close': '3076.52000', '5. volume': 1178}, '2022-02-09 03:30:00': {'1. open': '3079.31000', '2. high': '3084.81000', '3. low': '3073.05000', '4. close': '3074.49000', '5. volume': 1746}, '2022-02-09 03:15:00': {'1. open': '3073.70000', '2. high': '3081.01000', '3. low': '3073.70000', '4. close': '3079.32000', '5. volume': 2243}}}

I ran this code to try and put that response into a dataframe:

df = pd.DataFrame(data["Time Series (15min)"])
df = df.T  # Transpose Dataframe for desired results

My understanding is the data response is a JSON dictionary data structure, but that produced this error message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-ba79690310fb> in <module>()
----> 1 df = pd.DataFrame(data["Time Series (15min)"])
      2 df = df.T  # Transpose Dataframe for desired results

KeyError: 'Time Series (15min)'

I don't understand the error message, but am thinking it must be something from pandas and not the AlphaVantage API, though I haven't been able to find any clear information on what I should be using instead of "Time Series (15min)"

Greatly appreciate any input on how to approach this.

Body:
You don't use the right key: it's not Time Series (15min) but Time Series Crypto (15min):

df = pd.DataFrame(data["Time Series Crypto (15min)"]).T
print(df)

# Output
                        1. open     2. high      3. low    4. close 5. volume
2022-02-10 04:00:00  3179.59000  3180.47000  3173.82000  3175.86000      1031
2022-02-10 03:45:00  3180.39000  3183.52000  3176.24000  3179.60000      1924
2022-02-10 03:30:00  3185.17000  3188.40000  3179.04000  3180.40000      2018
2022-02-10 03:15:00  3177.58000  3186.24000  3175.01000  3185.17000      2376
2022-02-10 03:00:00  3186.58000  3189.99000  3170.87000  3177.58000      6907
...                         ...         ...         ...         ...       ...
2022-02-09 04:15:00  3089.00000  3091.52000  3081.56000  3083.67000      1639
2022-02-09 04:00:00  3076.52000  3090.13000  3075.04000  3089.00000      2153
2022-02-09 03:45:00  3074.50000  3078.82000  3072.34000  3076.52000      1178
2022-02-09 03:30:00  3079.31000  3084.81000  3073.05000  3074.49000      1746
2022-02-09 03:15:00  3073.70000  3081.01000  3073.70000  3079.32000      2243

[100 rows x 5 columns]

Bonus rename columns:

df.columns = df.columns.str.split().str[1].str.capitalize()
print(df)

# Output
                           Open        High         Low       Close Volume
2022-02-10 04:00:00  3179.59000  3180.47000  3173.82000  3175.86000   1031
2022-02-10 03:45:00  3180.39000  3183.52000  3176.24000  3179.60000   1924
2022-02-10 03:30:00  3185.17000  3188.40000  3179.04000  3180.40000   2018
2022-02-10 03:15:00  3177.58000  3186.24000  3175.01000  3185.17000   2376
2022-02-10 03:00:00  3186.58000  3189.99000  3170.87000  3177.58000   6907
...                         ...         ...         ...         ...    ...
2022-02-09 04:15:00  3089.00000  3091.52000  3081.56000  3083.67000   1639
2022-02-09 04:00:00  3076.52000  3090.13000  3075.04000  3089.00000   2153
2022-02-09 03:45:00  3074.50000  3078.82000  3072.34000  3076.52000   1178
2022-02-09 03:30:00  3079.31000  3084.81000  3073.05000  3074.49000   1746
2022-02-09 03:15:00  3073.70000  3081.01000  3073.70000  3079.32000   2243

[100 rows x 5 columns]


问:
Get changes from another branch without affecting current branch at all
Is there a simple way to get changes from another branch without merge or rebase. And keep those changes as untracked (for new files) or not staged for commit (for existing files)?</p>

答:
Checkout the new branch you want to place the changes uncommitted over.

git merge --squash sourcebranch

Works similarly to the accepted answer but is one line.

https://blog.oddbit.com/post/2019-06-17-avoid-rebase-hell-squashing-wi/


问:
how to rewrite 5*3**n/6 as 5/2*3**(n-1) :I want string ok
I want to use sequence

I want string ok

```<code>5*3**n/6 ---> 5/2*3**(n-1)
</code>```

I try

```<code>from sympy import *
var('n')
f=5  *3**n/6
g=5/2*3**(n-1)
print("#",f,simplify(f))
print("#",g,simplify(g))
# 5*3**n/6       5*3**n/6
# 2.5*3**(n - 1) 0.833333333333333*3**n
</code>```

(2022-02-11)

https://docs.sympy.org/latest/tutorial/simplification.html#powsimp

答:
```<code>>>> from sympy import powsimp
>>> powsimp(5*3**n/6)
5*3**(n - 1)/2
</code>```

Body:
I want to use sequence

I want string ok

5*3**n/6 ---> 5/2*3**(n-1)

I try

from sympy import *
var('n')
f=5  *3**n/6
g=5/2*3**(n-1)
print("#",f,simplify(f))
print("#",g,simplify(g))
# 5*3**n/6       5*3**n/6
# 2.5*3**(n - 1) 0.833333333333333*3**n

(2022-02-11)

https://docs.sympy.org/latest/tutorial/simplification.html#powsimp


问:
Problems when freeing a dynamically allocated 2d array in C
I am desperately trying to free a 2d int array and can't manage to do so.
I guess there's something wrong when i intialize the array?
Could you please help me out?

```<code>    int rows = 2;
    int cols = 3;
    int *mfields = (int *) malloc(sizeof(int) * rows * cols);
    int **matrix = (int **) malloc(sizeof(int *) * rows);
    for (int i = 0; i < rows; i++) {
        matrix[i] = mfields + i * cols;
        for(int j=0; j<rows;j++) {
            matrix[i][j] = (i+1)*(j+1);
        }
    }
    for (int i = 0; i < rows; i++) {
        free((matrix[i]));
    }
    free(matrix);
</code>```

Thanks in advance,
Christian

答:
Two chunks of memory are allocated:

```<code>int *mfields = (int *) malloc(sizeof(int) * rows * cols);
int **matrix = (int **) malloc(sizeof(int *) * rows);
</code>```

and therefore two chunks of memory should be freed:

```<code>free(matrix);
free(mfields);
</code>```

Freeing multiple chunks of memory, as this loop does:

```<code>    for (int i = 0; i < rows; i++) {
        free((matrix[i]));
</code>```

is incorrect, as it passes addresses to free that were never returned from malloc.

Generally, it is not good to implement matrices as pointers-to-pointers. This prevents the processor from doing load prediction and impairs performance. If the C implementation(s) that will be used with the code support variable length arrays, then it is preferable to simply allocate one chunk of memory:

```<code>int (*matrix)[cols] = malloc(rows * sizeof *matrix);
</code>```

If variable length array support is not available, then a program should allocate one chunk of memory and use manual calculations to address array elements. While this is may be more work for the programmer, it is better for performance:

```<code>int *matrix = malloc(rows * cols * sizeof *matrix);
for (int i = 0; i < rows; i++)
    for (int j = 0; j < cols; j++)
        matrix[i*cols + j] = (i+1) * (j+1);
</code>```

Body:
I am desperately trying to free a 2d int array and can't manage to do so.
I guess there's something wrong when i intialize the array?
Could you please help me out?

    int rows = 2;
    int cols = 3;
    int *mfields = (int *) malloc(sizeof(int) * rows * cols);
    int **matrix = (int **) malloc(sizeof(int *) * rows);
    for (int i = 0; i < rows; i++) {
        matrix[i] = mfields + i * cols;
        for(int j=0; j<rows;j++) {
            matrix[i][j] = (i+1)*(j+1);
        }
    }
    for (int i = 0; i < rows; i++) {
        free((matrix[i]));
    }
    free(matrix);

Thanks in advance,
Christian

Body:
Two chunks of memory are allocated:

int *mfields = (int *) malloc(sizeof(int) * rows * cols);
int **matrix = (int **) malloc(sizeof(int *) * rows);

and therefore two chunks of memory should be freed:

free(matrix);
free(mfields);

Freeing multiple chunks of memory, as this loop does:

    for (int i = 0; i < rows; i++) {
        free((matrix[i]));

is incorrect, as it passes addresses to free that were never returned from malloc.

Generally, it is not good to implement matrices as pointers-to-pointers. This prevents the processor from doing load prediction and impairs performance. If the C implementation(s) that will be used with the code support variable length arrays, then it is preferable to simply allocate one chunk of memory:

int (*matrix)[cols] = malloc(rows * sizeof *matrix);

If variable length array support is not available, then a program should allocate one chunk of memory and use manual calculations to address array elements. While this is may be more work for the programmer, it is better for performance:

int *matrix = malloc(rows * cols * sizeof *matrix);
for (int i = 0; i < rows; i++)
    for (int j = 0; j < cols; j++)
        matrix[i*cols + j] = (i+1) * (j+1);


问:
Hyper-V is disabled after restart of windows 10
I am trying to work with Visual Studio Mobile App (Xamarin.Forms), so as it is said I have to enable Hyper-V on my Win 10 and then setup Visual Studio.
So I follow this and this guide in order to enable it, but after enabling Hyper-V from Settings and restarting the PC it returns disabled/unchecked.
I tried to execute bcdedit /set hypervisorlaunchtype auto in order to make it launch automatically after restart, but still not the solution. Visual Studio says that Hyper-V is disabled and can't visualize the app. Any ideas will be great. Thanks in advance.

P.S My PC is using Intel processor and in Task Manager -> Performance -> Visualization is Enabled, so not the BIOS setting is the problem.

P.S2 I tried the HAXM, but when installing it says that my PC is not compatible.

答:
Check if "Hyper-V Virtual Machine Management" is on "Automatic" in the services.msc.

Windows key + R

Type services.msc and press OK

Search for "Hyper-V Virtual Machine Management"

Right click and click properties

Select automatic by startup type

Press apply and close

I had the same issue and this was the fix for me.


问:
How to Mix 2 list as Dictionary in Python with custom key value pair

I have 2 List

1. Contains Keys

2. Contains Keys+Values

Now I have to make a Dictionary from it which will filter out the keys and insert all the values before the next key arrives in the list.

Example:

```<code>List 1: ['a','ef','ddw','b','rf','re','rt','c','dc']
List 2: ['a','b','c']

Dictionary that I want to create: {
'a':['ef','ddw'],
'b':['rf','re','rt'],
'c':['dc']
}
</code>```

I am only familiar with python language and want solution for same in python only.

答:
I think this should work:</p>
```<code>result = {}
cur_key = None
for key in list_1:
    if key in list_2:
        result[key] = []
        cur_key = key
    else:
        result[cur_key].append(key)
</code>```

Body:
I have 2 List

1. Contains Keys

2. Contains Keys+Values

Now I have to make a Dictionary from it which will filter out the keys and insert all the values before the next key arrives in the list.

Example:

List 1: ['a','ef','ddw','b','rf','re','rt','c','dc']
List 2: ['a','b','c']

Dictionary that I want to create: {
'a':['ef','ddw'],
'b':['rf','re','rt'],
'c':['dc']
}

I am only familiar with python language and want solution for same in python only.

Body:
I think this should work:

result = {}
cur_key = None
for key in list_1:
    if key in list_2:
        result[key] = []
        cur_key = key
    else:
        result[cur_key].append(key)


问:
Java can combine default implementation from an abstract class and interface in a class. Is there a way to achieve this in C#?
Is there a "smart" way to achieve the same result as in Java when using an interface and abstract class which both implements their own half of a shared interface?

In Java, I'm able to extend an abstract class (AnAbstractClass) and implement an interface (AnotherInterface) which each have a default implementation of their part of an interface (AnInterface), such that I don't have to implement any methods in the class that combines these (See code).

I'm trying to convert Java code to C# while making sure everything is mapped 1-to-1. So I would like to avoid creating new classes as much as possible and that my "Combiner" class doesn't contain any methods.

```<code>public class Test{

    public interface AnInterface
    {
        String methodOne();
        int methodTwo();
    }

    public interface AnotherInterface extends AnInterface
    {
        default int methodTwo()
        {
            return 2;
        }
    }

    public abstract class AnAbstractClass implements AnInterface
    {
        public String methodOne()
        {
            return "1";
        }
    }

    public class Combiner extends AnAbstractClass implements AnotherInterface
    {

    }
}
</code>```

答:
This is accomplishable in C#, but as far as I know there's no smart way to do it as interfaces should in general be kept simple and this would mostly just make the code harder to read and debug.

```<code>public interface IAnInterface
{
    public string MethodOne();
    public int MethodTwo();
}

public interface IAnotherInterface : IAnInterface
{
    public static new int MethodTwo()
    {
        return 2;
    }
}

public abstract class AnAbstractClass : IAnInterface
{
    public string MethodOne()
    {
        return "1";
    }
    public abstract int MethodTwo();
}

public class Combiner : AnAbstractClass, IAnotherInterface
{
    public override int MethodTwo()
    {
        return IAnotherInterface.MethodTwo();
    }
}
</code>```

So I implore you to not do this!

Body:
Is there a "smart" way to achieve the same result as in Java when using an interface and abstract class which both implements their own half of a shared interface?

In Java, I'm able to extend an abstract class (AnAbstractClass) and implement an interface (AnotherInterface) which each have a default implementation of their part of an interface (AnInterface), such that I don't have to implement any methods in the class that combines these (See code).

I'm trying to convert Java code to C# while making sure everything is mapped 1-to-1. So I would like to avoid creating new classes as much as possible and that my "Combiner" class doesn't contain any methods.

public class Test{

    public interface AnInterface
    {
        String methodOne();
        int methodTwo();
    }

    public interface AnotherInterface extends AnInterface
    {
        default int methodTwo()
        {
            return 2;
        }
    }

    public abstract class AnAbstractClass implements AnInterface
    {
        public String methodOne()
        {
            return "1";
        }
    }

    public class Combiner extends AnAbstractClass implements AnotherInterface
    {

    }
}

Body:
This is accomplishable in C#, but as far as I know there's no smart way to do it as interfaces should in general be kept simple and this would mostly just make the code harder to read and debug.

public interface IAnInterface
{
    public string MethodOne();
    public int MethodTwo();
}

public interface IAnotherInterface : IAnInterface
{
    public static new int MethodTwo()
    {
        return 2;
    }
}

public abstract class AnAbstractClass : IAnInterface
{
    public string MethodOne()
    {
        return "1";
    }
    public abstract int MethodTwo();
}

public class Combiner : AnAbstractClass, IAnotherInterface
{
    public override int MethodTwo()
    {
        return IAnotherInterface.MethodTwo();
    }
}

So I implore you to not do this!


问:
How to enable authentication on MongoDB through Docker?
I want to spin-up a docker for mongodb:latest but allow only certain user(s) to access certain db(s) (i.e. enable --auth). No one else should access mongodb whatsoever! How should I do this as part of the docker initiation?

BTW, data directory sits on the host by utilising the following command during initiation: -v /my/own/datadir:/data/db.

答:
It works for me.

Create container with DB name

```<code>docker run -d \
--name mongodb \
-e MONGO_INITDB_DATABASE=trackdb \
-p 27017:27017 \
mongo
</code>```

Go to in container and create user

```<code>docker exec -it mongodb bash
mongo
use trackdb
db.createUser({user: "user", pwd: "secretPassword",roles: [{ role: 'readWrite', db:'trackdb'}]})
exit
exit
</code>```

Stop container:

```<code>docker stop mongodb
</code>```

Check your container ID via:

```<code>docker ps -a
</code>```

Change docker configuration (with your favorite editor)

```<code>sudo nano /var/lib/docker/containers/<YOUR_CONTAINER_ID>/config.v2.json
</code>```

Find 2 places and add second argument:

"Args":["mongod"], --> "Args":["mongod","--auth"],

"Cmd":["mongod"], --> "Cmd":["mongod","--auth"],

Should be enough just restart the docker service, but I did sudo reboot now.

After the reboot you can verify your changes: docker inspect mongodb and find 2nd argument in 2 places.
Start container and check authentication.

Enjoy!

Body:
It works for me.

Create container with DB name

docker run -d \
--name mongodb \
-e MONGO_INITDB_DATABASE=trackdb \
-p 27017:27017 \
mongo

Go to in container and create user

docker exec -it mongodb bash
mongo
use trackdb
db.createUser({user: "user", pwd: "secretPassword",roles: [{ role: 'readWrite', db:'trackdb'}]})
exit
exit

Stop container:

docker stop mongodb

Check your container ID via:

docker ps -a

Change docker configuration (with your favorite editor)

sudo nano /var/lib/docker/containers/<YOUR_CONTAINER_ID>/config.v2.json

Find 2 places and add second argument:

"Args":["mongod"], --> "Args":["mongod","--auth"],

"Cmd":["mongod"], --> "Cmd":["mongod","--auth"],

Should be enough just restart the docker service, but I did sudo reboot now.

After the reboot you can verify your changes: docker inspect mongodb and find 2nd argument in 2 places.
Start container and check authentication.

Enjoy!


问:
implicit declaration of function 'pthread_create'
When I am running my C code in a Raspbian environment I keep receiving this from the terminal. I am trying to create multiple threads to run pwm on two io pins while having a third thread that checks to see if a key 'q' is pressed to quit the program. What does this Warning mean?</p>

答:
You must include pthread.h header at the beginning of the file where you use pthread functions

```<code>#include <pthread.h>
</code>```

Body:
You must include pthread.h header at the beginning of the file where you use pthread functions

#include <pthread.h>


问:
Move button when clicked
How do I move the button from the div with id of two to the div with id of one when I click the button?

  <button onclick="moveMe"></button>

```
<pre class="lang-js prettyprint-override"><code>function moveMe() {
 // ??
}
</code>```

答:
You can use code below to move the element.

There's some changes that I made on your code,

you can use version 1 or version 2

the changes on first version is i add "id" attribute on the element so we don't resort to use the tag only as selector, of course you can also use #two>button to make it more precise

the changes on second version is i add a parameter to your function this time it will handle the current element using "this" keyword when calling the function

function moveMe(){
    // one.appendChild(document.querySelector("button"));
    one.appendChild(move);
}

function moveMeV2(element){
    one.appendChild(element);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div id="one">
  <span>one</span>
</div>

<div id="two">
  <span>two</span>
  <button id="move" onclick="moveMe()">Move Me</button>
  <button onclick="moveMeV2(this)">Move Me V2</button>
</div></code>```

Title: Move button when clicked

Body:
How do I move the button from the div with id of two to the div with id of one when I click the button?

  <button onclick="moveMe"></button>

function moveMe() {
 // ??
}

Body:
You can use code below to move the element.

There's some changes that I made on your code,

you can use version 1 or version 2

the changes on first version is i add "id" attribute on the element so we don't resort to use the tag only as selector, of course you can also use #two>button to make it more precise

the changes on second version is i add a parameter to your function this time it will handle the current element using "this" keyword when calling the function

function moveMe(){
    // one.appendChild(document.querySelector("button"));
    one.appendChild(move);
}

function moveMeV2(element){
    one.appendChild(element);
}

<div id="one">
  <span>one</span>
</div>

<div id="two">
  <span>two</span>
  <button id="move" onclick="moveMe()">Move Me</button>
  <button onclick="moveMeV2(this)">Move Me V2</button>
</div>