How do I get my user_id from the authorised client

Question: I want to retrieve the id of the user that's currently online. But I CANNOT do it with the following code:
Route::middleware('auth:api')->post('/optionelections', function (Request $request) {
        return $request->user();
    });

The reason is that I keep getting the same unauthorised error from Laravel. I've been trying to fix this error for days and I can't seem to find a solution. So I'm trying to do it in a different way but I don't know how. I'm currently using Passport to store my token and my client_id in local storage.
this is my apply_election.vue
    import {apiDomain} from '../../config'
  export default {
    name: 'applyForElection',
    data () {
      return {
        election: {},
        newOption: {'election_id': ''},
        //this is where the user_id should come
        newOption: {'user_id': ''}

      }
    },
    methods: {
      createOption: function () {
        var itemId = this.$route.params.id
        this.newOption.election_id = itemId
        this.$http.post(apiDomain + 'optionelections', this.newOption)
          .then((response) => {
            this.newOption = {'election_id': itemId}
            alert('you applied!')
            this.$router.push('/electionsnotstarted')
          }).catch(e => {
            console.log(e)
            alert('there was an error')
            this.$router.push('/electionsnotstarted')
          })
      }
    },
    created: function () {
      var itemId = this.$route.params.id
      this.$http.get('http://www.nmdad2-05-elector.local/api/v1/elections/' + itemId)
        .then(function (response) {
          this.election = response.data
        })
    }
  }

And this in my OptionElectionsController.php
public function store(Request $request)
    {

        $optionElection = new OptionElection();
        $optionElection->user_id = $request['user_id'];
        $optionElection->option = "something";
        $optionElection->votes = 0;
        $optionElection->election_id = $request['election_id'];
        $optionElection->accepted = 0;

        if ($optionElection->save()) {

            return response()
                ->json($optionElection);

        }

    }

This is my Auth.js
export default function (Vue) {
  Vue.auth = {
    setToken (token, expiration) {
      localStorage.setItem('token', token)
      localStorage.setItem('expiration', expiration)
    },
    getToken () {
      var token = localStorage.getItem('token')
      var expiration = localStorage.getItem('expiration')

      if (!token || !expiration) {
        return null
      }
      if (Date.now() > parseInt(expiration)) {
        this.destroyToken()
        return null
      } else {
        return token
      }
    },
    destroyToken () {
      localStorage.removeItem('token')
      localStorage.removeItem('expiration')
    },
    isAuthenticated () {
      if (this.getToken()) {
        return true
      } else {
        return false
      }
    }
  }

  Object.defineProperties(Vue.prototype, {
    $auth: {
      get: () => {
        return Vue.auth
      }
    }
  })
}

Answer: You are using the TokenGuard of Laravel, There many way to let the guard recognise the authentication, the best methods:

Send the token in api_token attribute in the request's query.
this.newOption.api_token = token;

Send the token in Authorization header with Bearer prefix.
{
    headers: {
        Authorization: 'Bearer THE_TOKEN'
    }
}


Windows 7 Bootloader installs to wrong drive when installing from secondary hard drive

Question: I have set up an unattended installation of Windows 7, but my setup causes the bootloader to be installed to the wrong drive. Here is the setup:
Drive 0 (OS Drive): This is the drive that the OS gets installed to. This is also the drive I want the bootloader on. All Windows files are installed to this drive, but bootloader is not.
Drive 1 (Installer Drive): This drive contains all the files from the windows 7 dvd, with the sources/install.wim file replaced with my custom version. This is the drive that the system boots to when I go to install windows, and is attached temporarily. This is the drive the bootloader actually gets installed to.
Since the whole idea here is to allow for unattended imaging of the OS, booting temporarily using the installer drive and "repairing" the installation post-install is not an option.
I realize that I could circumvent this problem by deploying the OS over the network using the MDT, but that scenario is less than ideal in some situations, so I need both working.
I need a way to tell the installer to install the bootloader to the hard drive the operating system is being installed to, ignoring the other hard drives attached to the system.
Some google-searched pages which detailing similar problems:
http://www.sevenforums.com/installation-setup/37210-windows-7-boot-manager-wrong-drive.html
http://social.technet.microsoft.com/Forums/en-US/w7itproinstall/thread/7eb4e0af-21f2-472f-89ba-a879cece5ef3/
Answer: Rather then starting a unattended install from the 2nd drive, you may need to do this:

Have WinPE boot from the 2nd drive
it autostarts a script
it runs diskpart to set the active volume to drive 0
it runs imagex to push the .wim into drive 0
it copies the unattended file to drive 0 for first boot customization


can memcpy for std::aligned_storage?

Question: std::aligned_storage::type is POD type. POD type can memcpy. However, What happens if placement new non-trivially-copyable type to std::aligned_storage? Can it memcpy that std::aligned_storage?
non-trivially-copyable type(non-POD type) can NOT memcpy, Behavior is undefined. If std::aligned_storage memcpy non-trivially-copyable type, is it also undefined behavior?
#include <new>
#include <type_traits>
#include <cstring>
#include <iostream>

struct y { int a; } ;

// non-trivially-copyable
struct t
{
    y a;
    int* p;
    t(){ p = new int{ 300 }; }
    t( t const& ){ a.a += 100; }
    ~t(){ delete p; }
};

int main()
{   // Block 1
    {
        t a; a.a.a = 100;
        t b; b.a.a = 200;
        // std::memcpy(&b,&a,sizeof(t));  // abort...non-trivially-copyable
    }
    // Block 2
    {
        std::aligned_storage_t<sizeof(t),alignof(t)> s;
        {
            t a;
            a.a.a = 100;
            std::memcpy(&s,&a,sizeof(t)); // OK...Coincidence? Behavior is undefined?
        }
        std::cout << static_cast<t*>(static_cast<void*>(&s))->a.a << std::endl; // OK...
    }
    // Block 3
    {
        std::aligned_storage_t<sizeof(t),alignof(t)> s1; new( &s1 ) t;
        std::aligned_storage_t<sizeof(t),alignof(t)> s2; new( &s2 ) t;

        std::memcpy(&s2,&s1,sizeof(t)); // trivially-copyable????
    }
}

I thought that it is undefined as well. However, we have work.
Is this for coincidence?
Comment: `memcpy()` takes memory addresses, careless if these are aligned or not.
Comment: Hi. The [guidelines for posting](http://stackoverflow.com/help/how-to-ask) on SO are that the code should appear in the post, and it should be *Minimal* to show the problem.  I have transcribed your code and simplified it a little, hopefully it still shows the same behaviour for you.
Answer: First of all: as discussed on this thread, the C++ standard only defines the behaviour of memcpy for trivially copyable objects.  That thread gives a specific example of how it can break for non-trivially copyable options
So, a narrow interpretation of the Standard would say that the mere act of calling memcpy causes UB.
However, a more common sense interpretation would be that it's OK to copy the bytes, but any attempt to treat the target as actually containing an object of the same type would cause UB. Especially in the case where the program depends on side-effects of the destructor, as yours does.  The rest of my answer is based on this latter interpretation.

Starting with Block 2:
std::aligned_storage_t<sizeof(t),alignof(t)> s;
{
    t a;
    a.a.a = 100;
    std::memcpy(&s,&a,sizeof(t));
}
std::cout << static_cast<t*>(static_cast<void*>(&s))->a.a << std::endl

Since t is not trivially copyable, we have not created a valid t object in s's storage. So the attempt to use s as if it contained a valid t object certainly causes undefined behaviour. When UB occurs any results can follow, including (but not limited to) it appearing to "work as expected".

In Block 1 (if the memcpy is uncommented):
{
    t a; a.a.a = 100;
    t b; b.a.a = 200;
    std::memcpy(&b,&a,sizeof(t));  // abort...non-trivially-copyable
}

Here we have destructor side-effects. The memcpy ends the lifetime of a (because a's storage is re-used). However the code will go on to try and call the destructor on a.
In this case, even if the copy "appears to work", your abort probably comes from the double-free of a.p.
If we changed t to be a non-trivially-copyable type but with no destructor side-effects then this example would be unclear.
There is no such double-free in Block 2 because no destructor is ever invoked for the t stored in s.

Block 3:
This is similar to Block 2: the memcpy does not create an object. It "appears to work" because you never invoke destructors for the objects in the aligned_storage.
In fact, under our common-sense interpretation of memcpy, there is no UB here because you never attempted to use the result of copying the bytes and the target does not have a destructor called on it.  (If you copied your cout line to here, it would cause UB for the same reason as in Block 2).

Related discussion: Even for trivially copyable classes it is still murky
The C++ standard is unclear around the issues of when object lifetime begins for objects in malloc'd space or aligned_storage. There was a submission N3751 recognizing that this needs cleanup but there is still a lot of work to do.
In your Block 2, the lifetime has not begun for s. This is because t has non-trivial initialization.  (This is actually not clearly stated by the C++ standard either). However Block 1's a is an object whose lifetime has begun.
N3751 proposes that (if t were trivially copyable) then the memcpy would in fact begin the lifetime of s.
Comment: Wasn't there a long debate on SO recently over whether just `memcpy`ing the bytes out of a non-trivially-copyable type is UB?
Comment: @T.C. copying *out of*? Surely not. I didn't see any recent thread other than the one linked in my answer though.
Comment: [Fun debate](http://stackoverflow.com/questions/29777492/why-would-the-behavior-of-stdmemcpy-be-undefined-for-objects-that-are-not-triv). I don't think either Block 2 or Block 3 has UB (in both cases, you copy a bunch of bytes out of a `T` into some storage, which is just fine).
Comment: @T.C. sorry, I should clarify that in Block 2 the UB actually comes from the attempt to use `s` afterwards, not the memcpy itself. (And Block 3 actually doesn't have any use, so as you say, no UB yet). Will read that other thread first
Comment: Ah, yes, I missed the use in Block 2 (was looking at your excerpt, not the OP)
Comment: @T.C. have updated now, taking that thread into account.  I'm not sure about the variation on Block 1 where `t` is standard-layout, non-trivially-copyable, and an empty destructor. If we go with the interpretation that `memcpy` itself doesn't cause UB then it's hard to say where the downstream-UB would be in that case. (OTOH if we say it's well-defined then we just copied a non-trivially-copyable object, which isn't supposed to happen!)
Comment: I think this shows that we need more than just N3751 to sort out object lifetime issues

can memcpy for std::aligned_storage?


How to draw decision boundary once we get the value of theta?

Question: I am solving the a exercise given by stanford university , machine learning course by Andrew Ng.
Question is (http://openclassroom.stanford.edu/MainFolder/DocumentPage.php?course=MachineLearning&doc=exercises/ex4/ex4.html) to plot a decision boundary on the given data and then estimate the result of the new data .
I have used the fminunc function to calculate the theta .
I have got three theta value's . But for drawing a line we will need only two theta , then what is the need of the third theta value.
I am unable to plot the decision boundary . please help me out .
Answer: It is said you added an intercept term thus it is normal for theta to have three dimension: two gradients (according X and Y plus the bias term). If theta_1 is the bias term, theta_2 the X gradient and theta_3 the Y gradient, the equation of your line is:
Y = -theta_2 / theta_3 .* X + theta_1
Best regards
Comment: Your y-intercept should be theta_1/theta_3 actually.


UIImage encoded to NSData in ObjectiveC and then decoded in Swift

Question: I have an app that was originally created in objective C (lets call this version 1) and I have now converted my app to Swift 2.0 (version 2). One of the main functions of the app is the ability to send images and text from one device to another. Images and text are stored in a NSMutableDictionary and then encoded to NSData and the sent / stored on the Parse backend server. The design of my app also has the ability to email an image from one device to another.
This is working well for both versions of my app – Objective C and Swift. Great !
My problem is when a user sends NSData from version 1 of my app to a device with version 2 (basically an image encoded in objective C and then decoded in Swift) !! Encoded text decodes fine but not the image (saved as objectForKey("data")). See below example. quizData is an array the holds dictionary (keyValue items) that have been sent from another device. This array works with all items except for objectForKey("data"). This object is the encoded image.
<code> var imageData = NSData()

imageData = quizData.objectAtIndex(currentQuestionNumber).objectForKey("data") as! NSData

  // the following always prints out lots of info to confirm the imageData has the encoded image
  print("imageData.length = \(imageData.length)")
  print("imageData.description = \(imageData.description)")

   // decoding
  photoImageView.image = UIImage(data:imageData)
</code>
ok, so the above works when the image was created on another device using Swift. But if the image created and sent from version 1 (objective c) the photoImageView is blank (no errors) yet the imageData is huge (the printout shows that imageDate does hold the users image).
Surley if an NSdata object has the data for a UIImage it should be able to be decoded in ObjC or Swift ?? No problem sending more code if required
Question amended as follows :
Not sure if this really helps but heres objC code for sending a NSData via email (all app data is saved a pList)
<code>// emailArray to be populated with selected data from plist
NSMutableArray *emailArray = [NSMutableArray arrayWithContentsOfFile:path];

 MFMailComposeViewController *emailPicker = [[MFMailComposeViewController alloc]init];
 emailPicker.mailComposeDelegate =self;

/// NSdata from emailArray
NSData *emailQuizData = [NSKeyedArchiver  archivedDataWithRootObject:emailArray];
[emailPicker addAttachmentData:emailQuizData mimeType:@"application/quizApp" fileName:_quizNameLabel.text];
</code>
Comment: None of your code makes much sense. What does the Objective-C code have to do with the Swift code? The Objective-C is loading some plist file (with unknown contents), archiving the resulting array, and sending the archive as an email attachment. The Swift code only shows an attempt to get `NSData` from some unknown array. Where did `quizData` come from in the Swift code? Your question says there is a problem sending data from one device to another. How is that done. Show relevant code with more context.
Comment: I don't think this has anything to do with swift. Basically your serialization/deserialization logic is different. It might makes more sense to post that code instead of the one you have here.
Comment: Would help if you show us the code that encodes the image data as NSData and puts it into the dictionary (the Obj-C code)
Comment: I would also try with Base64 image encoding decoding.
Comment: just check if the image is actually being sent in the first place. I think you are sending nil for "data" key in the first place. The above code doesn't show where you are sending the data. Please check that.
Comment: In order to help, we would need to see the implementation of NSCoding in whatever object is supposed to be in your `emailArray`. It seems like you may not be encoding the `UIImage` into `NSData` properly in the first place.
Answer: if you use base64 encoding this issue shouldn't arise.
here is the implementation in swift:
<code>import UIKit

func base64StringForImage(image: UIImage) -> String? {
    guard let data = UIImagePNGRepresentation(image) else { return nil }
    return data.base64EncodedStringWithOptions([])
}

func imageFromBase64String(string: String) -> UIImage? {
    guard let data = NSData(base64EncodedString: string, options: []) else { return nil }
    return UIImage(data: data)
}
</code>
here is the implementation in objc:
<code>#import <UIKit/UIKit.h>

NS_INLINE NSString * base64StringForImage_objc(UIImage *image) {
    NSData *imageData = UIImagePNGRepresentation(image);
    return [imageData base64EncodedStringWithOptions:0];
}

NS_INLINE UIImage * imageFromBase64String_objc(NSString *string) {
    NSData *imageData = [[NSData alloc] initWithBase64EncodedString: string options: 0];
    return [[UIImage alloc] initWithData:imageData];
}
</code>


After Module updates got "Warning: require_once() "

Question: I am using Drupal -7 and my website is on cloud(not local host).
This is NOT a multi site and using Omegasubtheme.
I have just updated workbench Moderation module from 1.3 to 1.4 and have also added Workbench Media module(7.x-1.1) to my dev. site.
After running update script, I got bunch of errors on my site. So, I again moved Worbench Moderation Module from 1.4 to 1.3.
Devel Generate and Devel Node Access Modules were enabled in my site and I made those module disabled.
After that, I got these errors so I made them enabled again.
I found this thread but, this is for database.inc for memory allocation error message in database.inc.
Devel Module

Can anyone help me how to get rid of these errors?
Errors which I got on front page:

Warning: require_once() [function.require-once]: Unable to allocate
  memory for pool. in _registry_check_code() (line 3177 of
  /docroot/includes/bootstrap.inc).
      Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in _registry_check_code() (line 3177 of
  /docroot/includes/bootstrap.inc).

Errors on available updates module page:

Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in menu_execute_active_handler() (line 515

of /docroot/includes/menu.inc).
      Warning: require_once() [function.require-once]: Unable to allocate memory for pool. in module_load_include() (line 330 of
  /docroot/includes/module.inc).
Answer: It would be interesting to see if your problems could be related to the "memory limit", which might not be high enough (anymore), especially because of the "... have also added Workbench Media module ...".
Assuming this is NOT a multi site, consider editing your /sites/default/settings.php, and change the line to set the memory limit. If it is a multi site, then edit the settings.php file related to the site where you are experiencing the problem.
That line in settings.php should look similar to this:
ini_set('memory_limit', '100M');

The '100M' in it might be some other number. Whatever the number is, try to increase it with like 50%, or maybe even double it to see what happens after you do so (of course do not forget to save the file after increasing that number).
Another possibility that you may want to verify, is to "perform a clear cache" (it doesn't hurt, and occasionally helps solving various issues).
Curious to hear if that helps somehow ...
Comment: **Memory is: APC to 128M**

Few hours from after clearing Varnish Cache, those errors gets just disappeared when Workbench Module is 1.3.
But, when I updated the module to 1.4 again, then I got SQL server errors as well some other errors.(Will try (https://www.drupal.org/node/1260112))

Notice: Undefined property: stdClass::$is_current in workbench_moderation_node_data() (line 1230 of /mnt/www/html/example.com/docroot/sites/all/modules/workbench_moderation/workbench_moderation.module).

I will update if I will get error free page with workbench moderation module-1.4
Comment: Thanks @Pierre.Vriens. I think problem arise because of memory issue. I was not able to find ini_set('memory_limit', '100M'); in my settings.php file. But, I just disabled some modules to avoid m/m issue and perform clear cache. and errors are gone.


Why does websphere Liberty Profile delete LtpaToken2 cookie

Question: There are two app servers: http://localhost:9080/appA and http://localhost:9081/appB
appA is hosted on Websphere and it is out of my control. It sets JSESSIONID and LtpaToken2 with path "/"
appB is on Liberty Profile which I have full control. I do not use session or single sign on. I have one simple REST server which echo back the user input. There's no cookie returned.
I open appA in the browser, logs in, see the cookies (JSESSIONID and LtpaToken2). Open another tab going to appB, then right away I see LtpaToken2 cookie is gone, JSESSIONID is still there. Going back to appA tab, navigate to another page, the user is kicked out.
What could possibly make LtpaToken2 gone from Liberty Profile?
Comment: Including the verbatim HTTP headers would help
Answer: What errors/messages do you see in the logs?
Assuming that ltpa keys are not exchanged between full profile (WAS) and liberty profile, when the token is presented to liberty and it has to authenticate (when accessing a protected servlet) it will fail and remove the cookie.
One other possibility is if the session that comes into liberty is not valid for some reason, then a logout is executed. Are the sessions shared here or a new session is supposed to be created for each app?
One solution is to have customized ltpa cookie names in both WAS and Liberty so one does not mess with the others cookies.
However, if they need to participate in SSO, then the LTPA keys need to be exchanged.
Comment: You're right. The keys are not exchanged. The two applications aren't related to each other. AppB doesn't have any protected resource. The two don't participate in SSO with each other. I tried to change the cookie name on AppB (I don't have control of AppA) but still not working. AppB works fine, but after accessing AppB, it removes AppA's token in the cookie so that I can no longer access AppA and get forward to the login page.
Comment: Without the logs cannot confirm what might be going on but if your AppB does not need security, one option is to disable the useAuthenticationDataForUnprotectedData property and see if it makes any difference : . Are there other apps in the Liberty server that need protection (i.e security feature needed)?
Comment: `` works! Now accessing appB does not affect accessing appA. I have been through the https://www.ibm.com/support/knowledgecenter/SSD28V_8.5.5/com.ibm.websphere.wlp.doc/autodita/rwlp_metatype_4ic.html but miss that attribute somehow. Thanks!


Why doesn't the program throw an exception despite typing the wrong type?

Question: Why doesn't exception handling work in this code?
It seems to me that I have implemented it well, after entering numbers of real type the application works fine, but when I enter for example random characters the program "terminates" but does not show the captured error message.
In the console I get: finished with non-zero exit value 1
import java.util.Scanner;

public class NewClass {
    public static void main(String[] args) {
        NewClass newClass = new NewClass();
        Scanner scanner = new Scanner(System.in);
        try {
            System.out.println("Enter the first side of the rectangle: ");
            double firstValue = scanner.nextDouble();
            System.out.println("Enter the second side of the rectangle: ");
            double secondValue = scanner.nextDouble();
            double result = newClass.calculateRectangleArea(firstValue, secondValue);
            System.out.println("Area of a rectangle with sides " + firstValue + " " + "and" + secondValue + " " + "are" + result);
        } catch (NumberFormatException exception) {
            System.out.println("Please enter the correct type!");
        }
    }

    public double calculateRectangleArea(double a, double b) {
        return a * b;
    }
}

Comment: You need `scanner.nextLine();` in your catch block to swallow the invalid token that is still held by the Scanner object.
Comment: @user16320675 Sorry, I misspelled. The program terminates and the console displays the message `finished with non-zero exit value 1` but already the colleague below gave the solution :)
Answer: Your scanner.nextDouble() method call throws InputMismatchException when you enter a random character other than a valid double number. But you've caught NumberFormatException in your catch block. If you want to capture the above case you should've caught the InputMismatchException.
catch (InputMismatchException exception) {
    System.out.println("Please enter the correct type!");
}


Logistic Regression with Multiple Independent Variables vs One Independent Variable

Question: Will the estimates and odds ratios change for an independent variable if it is by itself vs if there are other independent variables?  I would think that it would change since thinking of it as an equation $y=x$ (one variable) is different than $y=x+z+q$ (3 variables).
Comment: Yes, it will change because more of the variation in the dependent variable y is now being attributed to x.
Comment: Yes, it would. You can verify yourself with any example.
Comment: It'd most likely be different due to other variables.
Answer: The estimate of the effect of $x$ will certainly change if $z$ or $q$ (or both) have an effect on $y$ net of $x$. It will change even if $z$ and $q$ are orthogonal to $x$ as long as $z$ and $q$ explain any portion of $y$. This happens because adding new variables changes the scale in which the entire model is expressed. The logistic model given by:
(1)$$
\ln\bigg(\frac{1}{1-p_i}\bigg) = \beta_{0} + \beta_{1}x_{1i}
$$
Is expressed in the latent variable formulation as:
(2)$$
y^* =\alpha_{0} + \alpha_{1}x_{1i} + \sigma \varepsilon
$$
The total variance in the model is made of explained (modelled) and unexplained (residual/errors) variance. The logistic model forces the errors to have a fixed variance of 3.29 (and a logistical distribution). Hence, any changes in the amount of explained variance will force the total variance of $y*$ to change, causing its scale to change because the variance of the errors is fixed and cannot change. This affects the size of the coefficients because they now explain change in $y*$ in a different scale. The scaling factor is given by $\sigma$ in (2). The alphas in (2) are related to the betas in (1) by:
(3)$$
\beta_{j} = \frac{\alpha_{j}}{\sigma}\;\;j=1,...,J.
$$
Adding more covariates that explain any portion of $y$ will reduce the amount of unexplained heterogeneity and will consequentially change the other coefficients in the model. You can refer to my answer here or to the following literature:
References

Allison, P. D. (1999). Comparing Logit and Probit Coefficients Across Groups. Sociological Methods & Research, 28(2), 186–208.
Mood, C. (2010). Logistic Regression: Why We Cannot Do What We Think We Can Do, and What We Can Do About It. European Sociological Review, 26(1), 67–82.
Comment: Thanks for your information! Does that mean the more independent variables you include the better your model will be, thus, the better your output would be even if it changes some of the odds ratios a bit?
Comment: Not necessarily. Usually it is better to have more of the relevant variables, but there are cases in which controlling for a variable will lead to biased estimates of other coefficients. One example of these is what is called collider effects in some fields, and is probably a matter for a different question here in this site (if there is not any already).


Cassandra Opscenter historical view

Question: I recently upgraded the underlying machines of my Cassandra cluster (In AWS, from "old" to "current" generation hardware).  I thought I'd be able to see if this had a performance impact in Opscenter.
What I didn't consider is that as I decommissioned each node, it was being removed from the performance graphs!  This is a bummer.  Is there any hidden option to show "all collected data", even from nodes not currently in the cluster?  Is the tracking data even still there, or does it get immediately purged.
My workaround going forward will be writing down key metrics/taking screenshots otherwise.
Answer: The data from decommissioned nodes is still there, but will be removed for various granularities over time just like historical data for live nodes.  Reference: http://www.datastax.com/documentation/opscenter/4.1/opsc/configure/opscChangingPerformanceDataExpiration_t.html
There is not currently a way to view that data from within the UI, but you can use the OpsCenter API directly to fetch the data: http://www.datastax.com/documentation/opscenter/4.1/api/docs/metrics.html#new-get-perf-data
If this is something you need on a regular basis and/or feel like filing a feature request, go ahead and send us a message via the "Feedback" link at the top right of the UI.

Cassandra Opscenter historical view


Displaying articles (objects) in multiple pages

Question: I'm learning Express and Pug and having trouble displaying content on multiple pages.
Using a form I'm creating an article that saves the title + content to a database. Using this code I'm rendering the articles to a "View All Articles" page.
// Display list of all articles.
exports.article_list = function (req, res, next) {
  Article.find({}, "title author")
    .sort({ title: 1 })
    .populate("author")
    .exec(function (err, list_articles) {
      if (err) {
        return next(err);
      }
      //Successful, so render
      res.render("article_list", {
        title: "Article List",
        article_list: list_articles,
      });
    });
};

Inside my article_list pug file I have this code which displays a list of all articles.
extends layout

block content
  h1= title

  ul
    each article in article_list
      li
        a(href=article.url) #{article.title}
        |  by Adam

    else
      li There are no articles.

However, when I add the same code to my index pug file I get the following error:
Cannot read properties of undefined (reading 'length')
Not only do I want the articles to be displayed in the "View All Articles" section but I would like the top 5 or 10 most recent submissions to be displayed on the main page but having trouble doing so.
Comment: One situation where this error message is issued is when Pug is trying to iterate through a list type object that is empty, ie `undefined`. I would check that `article_list` is not empty. Add this line: `- console.log(article_list.length);` above `each article...` with the same indentation.
Answer: Apparently article_list is undefined or not an array.
It is not wrong to set a condition here, so that it does not come to an error in pug:
- console.log(article_list)

if article_list
    ul
        each article in article_list

And also try additional return statements:
exports.article_list = function (req, res, next) {
  return Article.find({}, "title author")
    ...
      return res.render("article_list", {
        ...


Singular value decomposition of a three-dimensional array

Question: The Singular Value Decomposition (SVD) of a matrix is
$$A_{m\times n} = U_{m\times m}\Lambda_{m\times n} V_{n\times n}'$$
where $U$ and $V$ are orthogonal matrices and $\Lambda$ has (i, i) entry $\lambda_i \geq 0$ for $i = 1, 2, \cdots , min(m, n)$ and the other entries are zero. Then the left singular vectors  $U$  for rows of matrix and right singular vectors $V$  for columns of matrix can be plotted on the same graph called bi-plot.
I'm wondering how to do the SVD of a three dimensional array and plot the singular vectors on the same graph like bi-plot.
Thanks
Comment: please do not [cross-post](http://math.stackexchange.com/questions/32702/singular-value-decomposition-svd-of-a-three-dimensional-array).
Comment: Could you explain what the analog of matrix multiplication might be for a "three-dimensional array" (presumably, a rank-three array requiring three independent indexes)?
Answer: There are several notions of decomposition of such a tensor. Last year I asked essentially the same question on the MaplePrimes site, answered it myself by referring to wikipedia, and provided an implementation for one of those notions (the CANDECOMP/PARAFAC decomposition) in a follow-up post (applied to decomposing the $3\times m \times n$ tensor given by the R,G,B entries of an image).
Comment: +1 Cool!  (BTW, the links to the MaplePrimes site are returning a 404.)
Comment: @whuber: there was a temporary outage - I believe the links should work again.
Comment: Thanks.  The site's a little slow but it's working now.  I like the image examples.
Comment: Nice. Any idea about plotting the singular vectors. Thanks
Comment: @MYaseen208: I think you can do the same as with a regular SVD - create points $(d_1^\alpha u_{1i}, d_2^\alpha u_{2i})$, $(d_1^\alpha v_{1i}, d_2^\alpha v_{2i})$, $(d_1^\alpha w_{1i}, d_2^\alpha w_{2i}$ for $i = 1, \dotsc, n$, where $u_1, v_1, w_1$ are the 1st triple of "singular" vectors and $d_1$ the 1st singular value - similar for 2nd. (I had to look biplots up - hadn't seen them before.) By the way - I think you'd potentially get a more powerful (3D) graph if you include the third singular vector as a third coordinate...


I have a problem to solve in powerapps dropdown menu

Question: What's up guys!! I made an application and in this application I register an RFID of cotton bales. It contains a selection menu in which I have as an item a sequence of numbers from 1 to 500 that is the identification of the bale. The problem is: when adding the bale and the RFID, I want that bale number to leave my selection menu, so that the next bale read will be the next number. Any formula idea to solve this problem?
Note: (these RFID reads are going to a list in sharepoint and my selection menu has the formula "sequence(500;1;1)").
I've tried making check buttons to show the sequence number in the selection menu, I've tried making filters with forall and conditions with removeif, but I don't think I'm knowing how to manipulate the syntaxes.
Answer: There's a number of ways to approach this problem:

Store the initial 1-500 numbers in a collection and remove one by one after processing a bale
Filter the sequence to numbers that do not appear in the SharePoint list
Use a flow to pre-populate the SharePoint list with the items numbered 1-500 and only toggle a field when the bale is processed. Use the same filter in the dropdown.

Also, I recommend familiarizing yourself with the different types of properties and formulas that exist in PowerApps. You see there are so-called 'Behaviour' formulas that perform some action and others that return values. The things you've tried seem to be mixing the two, which typically doesn't work. Filtering is non-behaviour, so you can't use ForAll() or RemoveIf() in this context.
Comment: Right!! I started using power apps this Sunday hehehe So I don't really understand what you said. Could you help me to run this? I have a list in sharepoint that contains 3 columns: Date and time, Bale and RFID. In my Powerapps I have a screen that contains a dropdown menu and text input. Could you help me with what to do so that when the user selects bale 1 and its respective RFID, the next time he registers the bale, bale 1 is no longer in this drop-down menu? Note: This "project" is just to understand how powerapps works and I found this problem.
Comment: Ok, so why don't you add a Yes/No column 'Processed' to your SharePoint to track if the bale has already been selected (approach 3)? For your dropdown, use Filter(BalesDataSource,Not(Processed)). When a bale is processed, update it with Patch(BalesDataSource,LookUp(BalesDataSource,Bale=<>),{ Processed: true })
Comment: I understood. I hadn't thought of it that way and I think it will work. But I have 2 doubts: Where do I put this patch formula... and where do I have to put the number is the user who will have to choose from the drop-down menu. How will this verification be done? Do you have another way to contact us so we can exchange an idea?
Comment: I'd rather we kept the conversation here. I'm not sure it's OK with StackOverflow to change channels and it can also be helpful for other users. So, when you finish processing a bale, I guess you click or press some button. Put the Patch formula into the button's OnSelect property. In the formula the number should replace the <<>> part
Comment: I had to go on a trip, so I didn't respond anymore. But I did all the procedure you gave me and it worked exactly as I wanted. Thank you very much, @mmikesy90!!


Do jpeg standard fixed huffman tables really reduce data size?

Question: I 'm implementing jpeg compression for microcontroller. In the huffman coding step I decided to use the standard fixed huffman table. I 've read somewhere that these tables are suitable for general images, but cannot find a statistical number about how much percentage do they reduce data size ? If it's just reduce the number of zero then I can do it with a few line of code.
Comment: It depends on how much your image statistically fits the average image that was used to create the default Huffman table. Most of the compression for Jpeg comes from the DCT and quantization, so unless you have a pathological case (very noisy image) you probably will only use a few percent of compression using standard tables. You will have to test it with representative samples from your own data to find out. Asking "how much exactly" doesn't make sense without knowing exact input data...
Comment: But what is the fixed Huffman table? I cannot find it the link you posted bellow.

Does it work with general images?
Answer: Standard huffman tables simply reduce compression time. If you do not use a pre-built table, your encoder has to scan the DCT data twice. The first pass generates counts to build the huffman table. The second pass encodes the huffman table. A two-pass scan generates the optimal huffman table and reduces data size more than a pre-canned on in most cases (by how much?).
PNG has standard huffman tables. If you use those, (unlike JPEG), you do not have to encode the table in the compressed image, thus saving space their.
Comment: You didn't answer my question. As I read here (http://www.impulseadventure.com/photo/optimized-jpeg.html), JPEG standard use standard table too, not just PNG. If I use those standard table, the process becomes replacing a byte with a bit string (not necessary less than 8 bit). My question is does that process really compress data ? (count out the effect of encode zero run length)
Comment: JPEG does not use standard huffman tables. The standard includes sample huffman tables as an appendix. You have to use a huffman table of some sort encoded in the JPEG stream, be it a sample in the standard or one of your own devising. You do not have to use the sample Huffman tables in the standard. And yes, it generally compresses data. PNG has the option of using standard huffman tables or ones you generate yourself. A PNG decoder must be aware of the standard table. A JPEG decoder does not need to have any knowledge of the tables in the JPEG standard.
Comment: "And yes, it generally compresses data" -> I doubt using a huffman table without analyzing data will compress anything. Do you have any proof, or a source ?
Comment: If you generate your own tables, it clearly compresses non-random data. According to your source, the precanned tables in the JPEG standard are only slightly worse than ideal tables.
Comment: It doesn't answer my question, how much does it compress if I use standard table, _count out the effect of encode zero run length._


How to solve this Pell's equation $x^{2} - 991y^{2} = 1 $

Question: How to solve the following Pell's equation?
$$x^{2} - 991y^{2} = 1 $$
where $(x, y)$ are naturals.
The answer is $$x = 379,516,400,906,811,930,638,014,896,080$$
$$y = 12,055,735,790,331,359,447,442,538,767$$
I can't think of any way apart from brute force. Please help.
Also, what is the general way of solving any Pell's equation?
I read the wiki article on it but couldn't get any general method to solve it.
Comment: Here's a useful [online solver,](http://www.alpertron.com.ar/QUAD.HTM) select "step-by-step" to see the methods used.
Comment: Read [this](http://www.cs.umb.edu/~eb/458/final/KoffiPresentation.pdf).
Comment: x3/y3=218651085477388313475594044993514033413718343388164019627976764578114609092763357330159760/6945680635899069348063079893854789105557565351617874814495165631493551941446359906376433
Comment: https://math.stackexchange.com/questions/171803/how-to-solve-this-pells-equation-x2-991y2-1?newreg=2dc4137e514e4868b8d702f219ac41fe
Answer: If $x^2-991y^2=1$, then we have that
$$
\begin{align}
\left(\frac{1}{y}\right)^2
&=\left(\frac{x}{y}\right)^2-991\\
&=\left(\frac{x}{y}-\sqrt{991}\right)\left(\frac{x}{y}+\sqrt{991}\right)\tag{1}
\end{align}
$$
Since $\frac{x}{y}\stackrel{.}{=}\sqrt{991}\stackrel{.}{=}31.5$, we get that
$$
\left|\frac{x}{y}-\sqrt{991}\right|\stackrel{.}{=}\frac1{63}\frac1{y^2}\tag{2}
$$
As described in Section $5$ of this paper, to get a rational approximation as close as $(2)$, $\dfrac{x}{y}$ must be a convergent of the continued fraction for $\sqrt{991}$. Since the next continuant, c_n, satisfies
$$
\frac1{c_n+2}\frac1{y^2}\lt\left|\frac{x}{y}-\sqrt{991}\right|\le\frac1{c_n}\frac1{y^2}\tag{3}
$$
the next continuant should be within about $1$ of $62$.
The continued fraction for an algebraic number of degree $2$ will eventually repeat. The continued fraction for $\sqrt{991}$ is
$$
(31, [2, 12, 10, 2, 2, 2, 1, 1, 2, 6, 1, 1, 1, 1, 3, 1, 8, 4, 1, 2, 1, 2, 3, 1, 4, 1, 20, 6, 4, 31, 4, 6, 20, 1, 4, 1, 3, 2, 1, 2, 1, 4, 8, 1, 3, 1, 1, 1, 1, 6, 2, 1, 1, 2, 2, 2, 10, 12, 2, 62])
$$
where the sequence in brackets repeats.
The only continuant within $1$ of $62$ is the $62$. Thus, the first positive solution corresponds to the rational approximation to $\sqrt{991}$ with the continued fraction
$$
(31, 2, 12, 10, 2, 2, 2, 1, 1, 2, 6, 1, 1, 1, 1, 3, 1, 8, 4, 1, 2, 1, 2, 3, 1, 4, 1, 20, 6, 4, 31, 4, 6, 20, 1, 4, 1, 3, 2, 1, 2, 1, 4, 8, 1, 3, 1, 1, 1, 1, 6, 2, 1, 1, 2, 2, 2, 10, 12, 2)
$$
which is
$$
\color{#C00000}{\frac{x_1}{y_1}}=\color{#C00000}{\frac{379516400906811930638014896080}{12055735790331359447442538767}}\tag{4}
$$
The next solution comes from the next time the next continuant is $62$; that is, for the rational approximation to $\sqrt{991}$ with the continued fraction
$$
(31, 2, 12, 10, 2, 2, 2, 1, 1, 2, 6, 1, 1, 1, 1, 3, 1, 8, 4, 1, 2, 1, 2, 3, 1, 4, 1, 20, 6, 4, 31, 4, 6, 20, 1, 4, 1, 3, 2, 1, 2, 1, 4, 8, 1, 3, 1, 1, 1, 1, 6, 2, 1, 1, 2, 2, 2, 10, 12, 2, 62, 2, 12, 10, 2, 2, 2, 1, 1, 2, 6, 1, 1, 1, 1, 3, 1, 8, 4, 1, 2, 1, 2, 3, 1, 4, 1, 20, 6, 4, 31, 4, 6, 20, 1, 4, 1, 3, 2, 1, 2, 1, 4, 8, 1, 3, 1, 1, 1, 1, 6, 2, 1, 1, 2, 2, 2, 10, 12, 2)
$$
which is
$$
\color{#C00000}{\frac{x_2}{y_2}}=\color{#C00000}{\frac{288065397114519999215772221121510725946342952839946398732799}{9150698914859994783783151874415159820056535806397752666720}}\tag{5}
$$
We can get all the solutions, starting with $(x_0,y_0)=(1,0)$ and $(4)$, using
$$
\begin{align}
x_n&=759032801813623861276029792160\,x_{n-1}-x_{n-2}\\
y_n&=759032801813623861276029792160\,y_{n-1}-y_{n-2}
\end{align}\tag{6}
$$
Answer: Edit, 6 April 2014: I put some GMP oversize integers in two of my indefinite forms programs in C++, so here is the Lagrange cycle method for doing this. The importance of this is that no decimal accuracy is required at all, and no pattern recognition (cycle detection??), no memory is required at all.

Pell 991

0  form   1 62 -30   delta  -2
1  form   -30 58 5   delta  12
2  form   5 62 -6   delta  -10
3  form   -6 58 25   delta  2
4  form   25 42 -22   delta  -2
5  form   -22 46 21   delta  2
6  form   21 38 -30   delta  -1
7  form   -30 22 29   delta  1
8  form   29 36 -23   delta  -2
9  form   -23 56 9   delta  6
10  form   9 52 -35   delta  -1
11  form   -35 18 26   delta  1
12  form   26 34 -27   delta  -1
13  form   -27 20 33   delta  1
14  form   33 46 -14   delta  -3
15  form   -14 38 45   delta  1
16  form   45 52 -7   delta  -8
17  form   -7 60 13   delta  4
18  form   13 44 -39   delta  -1
19  form   -39 34 18   delta  2
20  form   18 38 -35   delta  -1
21  form   -35 32 21   delta  2
22  form   21 52 -15   delta  -3
23  form   -15 38 42   delta  1
24  form   42 46 -11   delta  -4
25  form   -11 42 50   delta  1
26  form   50 58 -3   delta  -20
27  form   -3 62 10   delta  6
28  form   10 58 -15   delta  -4
29  form   -15 62 2   delta  31
30  form   2 62 -15   delta  -4
31  form   -15 58 10   delta  6
32  form   10 62 -3   delta  -20
33  form   -3 58 50   delta  1
34  form   50 42 -11   delta  -4
35  form   -11 46 42   delta  1
36  form   42 38 -15   delta  -3
37  form   -15 52 21   delta  2
38  form   21 32 -35   delta  -1
39  form   -35 38 18   delta  2
40  form   18 34 -39   delta  -1
41  form   -39 44 13   delta  4
42  form   13 60 -7   delta  -8
43  form   -7 52 45   delta  1
44  form   45 38 -14   delta  -3
45  form   -14 46 33   delta  1
46  form   33 20 -27   delta  -1
47  form   -27 34 26   delta  1
48  form   26 18 -35   delta  -1
49  form   -35 52 9   delta  6
50  form   9 56 -23   delta  -2
51  form   -23 36 29   delta  1
52  form   29 22 -30   delta  -1
53  form   -30 38 21   delta  2
54  form   21 46 -22   delta  -2
55  form   -22 42 25   delta  2
56  form   25 58 -6   delta  -10
57  form   -6 62 5   delta  12
58  form   5 58 -30   delta  -2
59  form   -30 62 1   delta  62
60  form   1 62 -30

 disc   3964
Automorph, written on right of Gram matrix:
5788591406539787767296194303  361672073709940783423276163010
12055735790331359447442538767  753244210407084073508733597857

 Pell automorph
379516400906811930638014896080  11947234168218377212415555918097
12055735790331359447442538767  379516400906811930638014896080

Pell unit
379516400906811930638014896080^2 - 991 * 12055735790331359447442538767^2 = 1

=========================================

991       991

I give a complete description at How to detect when continued fractions period terminates and at the MO question I link to there. You need to be very confident about using two by two matrices.  However, and this is the key point, it is NOT NECESSARY to use high decimal precision. All is integer arithmetic. The only approximation is the integer part of the square root of the discriminant, as in $\left\lfloor \sqrt {3964} \right\rfloor = 62.$ The bad news is that my program is limited to number s below $2^{31},$ so the "answer" at the end was gibberish and I just erased it. Oh, this comes up sometimes...with this method, it is also not necessary to use any cycle detection. The cycle for $991$ begins with the binary form $\langle 1,62,-30 \rangle$ and ends precisely when we, once again, reach $\langle 1,62,-30 \rangle.$ Not before, not after. I have a short example, the triples may repeat the first entry, in this case 9, but you are done when all three entries match:
0  form   9 75 -16   delta  -4
1  form   -16 53 53   delta  1
2  form   53 53 -16   delta  -4
3  form   -16 75 9   delta  8
4  form   9 69 -40   delta  -1
5  form   -40 11 38   delta  1
6  form   38 65 -13   delta  -5
7  form   -13 65 38   delta  1
8  form   38 11 -40   delta  -1
9  form   -40 69 9   delta  8
10  form   9 75 -16

Let me start with an easier one, 91, where I do get an answer, then show 991 after:
jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ ./Pell
Input n for Pell
91

0  form   1 18 -10   delta  -1
1  form   -10 2 9   delta  1
2  form   9 16 -3   delta  -5
3  form   -3 14 14   delta  1
4  form   14 14 -3   delta  -5
5  form   -3 16 9   delta  1
6  form   9 2 -10   delta  -1
7  form   -10 18 1   delta  18
8  form   1 18 -10

 disc   364
Automorph, written on right of Gram matrix:
89  1650
165  3059

 Pell automorph
1574  15015
165  1574

Pell unit
1574^2 - 91 * 165^2 = 1

=========================================
jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$

jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$
jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$ ./indefCycle
Input three coefficients a b c for indef f(x,y)= a x^2 + b x y + c y^2
1 0 -991

  0  form              1           0        -991  delta      0
  1  form           -991           0           1  delta     31
  2  form              1          62         -30

          -1         -31
           0          -1

To Return
          -1          31
           0          -1

0  form   1 62 -30   delta  -2
1  form   -30 58 5   delta  12
2  form   5 62 -6   delta  -10
3  form   -6 58 25   delta  2
4  form   25 42 -22   delta  -2
5  form   -22 46 21   delta  2
6  form   21 38 -30   delta  -1
7  form   -30 22 29   delta  1
8  form   29 36 -23   delta  -2
9  form   -23 56 9   delta  6
10  form   9 52 -35   delta  -1
11  form   -35 18 26   delta  1
12  form   26 34 -27   delta  -1
13  form   -27 20 33   delta  1
14  form   33 46 -14   delta  -3
15  form   -14 38 45   delta  1
16  form   45 52 -7   delta  -8
17  form   -7 60 13   delta  4
18  form   13 44 -39   delta  -1
19  form   -39 34 18   delta  2
20  form   18 38 -35   delta  -1
21  form   -35 32 21   delta  2
22  form   21 52 -15   delta  -3
23  form   -15 38 42   delta  1
24  form   42 46 -11   delta  -4
25  form   -11 42 50   delta  1
26  form   50 58 -3   delta  -20
27  form   -3 62 10   delta  6
28  form   10 58 -15   delta  -4
29  form   -15 62 2   delta  31
30  form   2 62 -15   delta  -4
31  form   -15 58 10   delta  6
32  form   10 62 -3   delta  -20
33  form   -3 58 50   delta  1
34  form   50 42 -11   delta  -4
35  form   -11 46 42   delta  1
36  form   42 38 -15   delta  -3
37  form   -15 52 21   delta  2
38  form   21 32 -35   delta  -1
39  form   -35 38 18   delta  2
40  form   18 34 -39   delta  -1
41  form   -39 44 13   delta  4
42  form   13 60 -7   delta  -8
43  form   -7 52 45   delta  1
44  form   45 38 -14   delta  -3
45  form   -14 46 33   delta  1
46  form   33 20 -27   delta  -1
47  form   -27 34 26   delta  1
48  form   26 18 -35   delta  -1
49  form   -35 52 9   delta  6
50  form   9 56 -23   delta  -2
51  form   -23 36 29   delta  1
52  form   29 22 -30   delta  -1
53  form   -30 38 21   delta  2
54  form   21 46 -22   delta  -2
55  form   -22 42 25   delta  2
56  form   25 58 -6   delta  -10
57  form   -6 62 5   delta  12
58  form   5 58 -30   delta  -2
59  form   -30 62 1   delta  62
60  form   1 62 -30
=========================================
jagy@phobeusjunior:~/old drive/home/jagy/Cplusplus$

Answer: Following the  link, taking  (379,12,  which was calculated by brute force) as the fundamental solution,  we can get the generic solution.
I'm trying to replace the brute force with human intelligence(!) using the followings:
first ,  second and continued fraction of $\sqrt{991}$
Comment: Isn't the [fundamental solution](http://en.wikipedia.org/wiki/Pell%27s_equation#Fundamental_solution_via_continued_fractions) actually a solution? I get $379^2-991\cdot12^2=937$.
Comment: The "pairs supplied in the question" were not pairs, but a couple of large numbers written with comma separators. Those are the same numbers given in $(4)$ in [my answer](http://math.stackexchange.com/a/172496).  Those numbers are the smallest positive solution (all solutions are given in $(6)$).
Comment: It is. While focusing the procedure, I actually missed to observe that none of the pairs supplied in the question satisfies the equation. Programmatically, I observer that  (775587755, 24637357) is probably the minimum solution after the trivial pairs(±1,0). Next pair being (875240822, 27802941)
Answer: Here are the steps to find the solutions for all d = m^2 + 2k. In your question d = 991 which belongs to this category. The following five steps give the first solution and the fundamental solutions.
1) 991 = m^2 + 2k
991 - 31^2 = 2k
So m=31, k=15.
2) We set x = m^2 - m + k = 945
y = m - 1 = 30
945^2 - 991*30^2 = 1125 -> 189 - 991*6^2 = 45 -> 63^2 - 991*2^2 = 5
3) Now we will find the solvent as follows:
x_1 = m^2 + m + 2k = 1022
y_1 = m + 1 = 32
1022^2 - 991*32^2 = 29700 -> 511^2 - 991*16^2 = 7425
x_2 = m^2 - m + 2k = 960
y_2 = m - 1 = 30
960^2 - 991*30^2 = 29700 -> 480^2 - 991*15^2 =7425
From the following multiplication we find the value of the solvent:
(511 + 16*sqrt991)(480 + 15*sqrt991) -> 483120^2 - 991*15345^2 = 7425^2
4) We multiply the solvent by any of the first fundamental solutions to find the      second fundamental solution:
(483120 + 15345*sqrt991)(945 + 30*sqrt991) -> 24586^2 - 991*781^2 = 45
5) From the multiplication (24586 + 781*sqrt991)(945 + 30*sqrt991) we obtain the third fundamental solution.
We can continue this process indefinitely to find more and more fundamental solutions.
Answer: I think it can be solved without using complex operators,and the solution is here: When is $991n^2 +1$ a perfect square?
Answer: All you really have to do is brute force the smallest pair (x, y) and the rest is cake. Once you find it, throw it into a 2×2 matrix with both diagonal entries that are the x coordinate and the Anti-diagonal entries being y and y*991 (doesnt matter). The determinant of this guy is 1. Diagonalize the matrix, take to a power s, where s is n integer, and then multiply it back out. The determinant is still one. Thats how you get all other solutions.
Answer: Solving method from Pell's equation without irrational numbers by Norman Wildberger
in pari/gp:
njw(d)=
{
 L= [1,0;1,1]; R= [1,1;0,1];
 A= [1,0;0,-d]; Q= A; N= 1;
 while(1,
  a= Q[1,1]; b= Q[1,2]; c= Q[2,2];
  t= a+2*b+c;
  if(t<0, Q= R~*Q*R; N= N*R, Q= L~*Q*L; N= N*L);
  if(Q==A, break())
 );
 return(N[,1]~)
};

? njw(991)
%5 = [379516400906811930638014896080, 12055735790331359447442538767]

Also this method online in Geogebra
Answer: $$x^2 - 991y^2 = 1$$ -------(1)
Assuming $y \not= 0$ divide both sides of the equation by $y^2$
i.e. $$(x/y)^2 - 991 = (1/y)^2$$
i.e. $(x/y)^2 - (1/y)^2 = 991$
i.e. $(x/y - 1/y)(x/y + 1/y) = (1)(991)$
i.e. $(x/y - 1/y)(x/y + 1/y) = (496 - 495)(496 + 495)$
i.e. $x/y = 496$ and $1/y = 495$
i.e. $x = (496/495)$ and $y = 1/495$
The equation represents a hyperbola of the form $$x^2/a^2 - y^2/b^2 = 1$$
i.e. the equation is $$x^2/(1^2) - y^2/(\sqrt {1/991})^2 = 1$$
foci of this hyperbola are the co ordinates $(\pm c, 0)$
Here $c = \sqrt{a^2 + b^2}$
The asymptotes are $y = \pm (b/a)x$
i.e. The asymptotes are $y = \pm (1/\sqrt{991})x$
There exists a $CONJUGATE$  $HYPERBOLA$ of the form $\frac{x^2}{a^2} - \frac{y^2}{b^2} = -1$, for the $HYPERBOLA$ $\frac{x^2}{a^2} - \frac{y^2}{b^2} = 1$
Here the equation of the $conjugate$  $hyperbola$ is $x^2 - 991(y^2) = -1$
$$x^2 - 991y^2 = -1$$ -------(2)
Now solve equations (1) and (2) for $x$ and $y$
i.e. $(2)(x^2) - (2)(991)(y^2) = 0$
i.e. $(x^2) - (991)(y^2) = 0$
i.e. $(x^2) = (991)(y^2)$
i.e. $\frac{x^2}{y^2} = 991$
i.e. $\left(\frac{x^2}{y^2} - (\sqrt{991})^2\right) = 0$
i.e. $\left(\frac{x}{y} - \sqrt{991}\right)\left(\frac{x}{y} + \sqrt{991}\right) = 0$
i.e. $(\frac{x}{y} = \pm\sqrt{991})$
i.e. $\frac{y}{x} = \pm\frac{1}{\sqrt{991}}$ , the equations of the asymptotes to the hyperbola
Comment: Try putting $$ s at the start and end of your mathematics
Answer: had forgotten this one. I've got better programs now, including one that does Pell....
jagy@phobeusjunior:~/Desktop/Cplusplus$ ./Pell  991
Sun Jul 17 12:56:55 PDT 2022

0  form   1 62 -30   delta  -2
1  form   -30 58 5   delta  12
2  form   5 62 -6   delta  -10
3  form   -6 58 25   delta  2
4  form   25 42 -22   delta  -2
5  form   -22 46 21   delta  2
6  form   21 38 -30   delta  -1
7  form   -30 22 29   delta  1
8  form   29 36 -23   delta  -2
9  form   -23 56 9   delta  6
10  form   9 52 -35   delta  -1
11  form   -35 18 26   delta  1
12  form   26 34 -27   delta  -1
13  form   -27 20 33   delta  1
14  form   33 46 -14   delta  -3
15  form   -14 38 45   delta  1
16  form   45 52 -7   delta  -8
17  form   -7 60 13   delta  4
18  form   13 44 -39   delta  -1
19  form   -39 34 18   delta  2
20  form   18 38 -35   delta  -1
21  form   -35 32 21   delta  2
22  form   21 52 -15   delta  -3
23  form   -15 38 42   delta  1
24  form   42 46 -11   delta  -4
25  form   -11 42 50   delta  1
26  form   50 58 -3   delta  -20
27  form   -3 62 10   delta  6
28  form   10 58 -15   delta  -4
29  form   -15 62 2   delta  31
30  form   2 62 -15   delta  -4
31  form   -15 58 10   delta  6
32  form   10 62 -3   delta  -20
33  form   -3 58 50   delta  1
34  form   50 42 -11   delta  -4
35  form   -11 46 42   delta  1
36  form   42 38 -15   delta  -3
37  form   -15 52 21   delta  2
38  form   21 32 -35   delta  -1
39  form   -35 38 18   delta  2
40  form   18 34 -39   delta  -1
41  form   -39 44 13   delta  4
42  form   13 60 -7   delta  -8
43  form   -7 52 45   delta  1
44  form   45 38 -14   delta  -3
45  form   -14 46 33   delta  1
46  form   33 20 -27   delta  -1
47  form   -27 34 26   delta  1
48  form   26 18 -35   delta  -1
49  form   -35 52 9   delta  6
50  form   9 56 -23   delta  -2
51  form   -23 36 29   delta  1
52  form   29 22 -30   delta  -1
53  form   -30 38 21   delta  2
54  form   21 46 -22   delta  -2
55  form   -22 42 25   delta  2
56  form   25 58 -6   delta  -10
57  form   -6 62 5   delta  12
58  form   5 58 -30   delta  -2
59  form   -30 62 1   delta  62
60  form   1 62 -30

 disc 3964
Automorph, written on right of Gram matrix:
5788591406539787767296194303  361672073709940783423276163010
12055735790331359447442538767  753244210407084073508733597857

 Pell automorph
379516400906811930638014896080  11947234168218377212415555918097
12055735790331359447442538767  379516400906811930638014896080

Pell unit
379516400906811930638014896080^2 - 991 * 12055735790331359447442538767^2 = 1

=========================================

  2
616049024759241^2 - 991 * 19569442212887^2 = 2

=========================================
  2 Automorph, written on right of Gram matrix:
-9396316159744  -293541633193305
-19569442212887  -611350866679369

991       991

Sun Jul 17 12:56:55 PDT 2022

one I learned from Lubin
$$  \sqrt { 991} = 31 +     \frac{  \sqrt {991} - 31 }{ 1 }  $$
$$    \frac{ 1 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{30 } = 2 +  \frac{    \sqrt {991} - 29 }{30 } $$
$$    \frac{ 30 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{5 } = 12 +  \frac{    \sqrt {991} - 31 }{5 } $$
$$    \frac{ 5 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{6 } = 10 +  \frac{    \sqrt {991} - 29 }{6 } $$
$$    \frac{ 6 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{25 } = 2 +  \frac{    \sqrt {991} - 21 }{25 } $$
$$    \frac{ 25 }{   \sqrt {991} - 21 }  =  \frac{    \sqrt {991} + 21 }{22 } = 2 +  \frac{    \sqrt {991} - 23 }{22 } $$
$$    \frac{ 22 }{   \sqrt {991} - 23 }  =  \frac{    \sqrt {991} + 23 }{21 } = 2 +  \frac{    \sqrt {991} - 19 }{21 } $$
$$    \frac{ 21 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{30 } = 1 +  \frac{    \sqrt {991} - 11 }{30 } $$
$$    \frac{ 30 }{   \sqrt {991} - 11 }  =  \frac{    \sqrt {991} + 11 }{29 } = 1 +  \frac{    \sqrt {991} - 18 }{29 } $$
$$    \frac{ 29 }{   \sqrt {991} - 18 }  =  \frac{    \sqrt {991} + 18 }{23 } = 2 +  \frac{    \sqrt {991} - 28 }{23 } $$
$$    \frac{ 23 }{   \sqrt {991} - 28 }  =  \frac{    \sqrt {991} + 28 }{9 } = 6 +  \frac{    \sqrt {991} - 26 }{9 } $$
$$    \frac{ 9 }{   \sqrt {991} - 26 }  =  \frac{    \sqrt {991} + 26 }{35 } = 1 +  \frac{    \sqrt {991} - 9 }{35 } $$
$$    \frac{ 35 }{   \sqrt {991} - 9 }  =  \frac{    \sqrt {991} + 9 }{26 } = 1 +  \frac{    \sqrt {991} - 17 }{26 } $$
$$    \frac{ 26 }{   \sqrt {991} - 17 }  =  \frac{    \sqrt {991} + 17 }{27 } = 1 +  \frac{    \sqrt {991} - 10 }{27 } $$
$$    \frac{ 27 }{   \sqrt {991} - 10 }  =  \frac{    \sqrt {991} + 10 }{33 } = 1 +  \frac{    \sqrt {991} - 23 }{33 } $$
$$    \frac{ 33 }{   \sqrt {991} - 23 }  =  \frac{    \sqrt {991} + 23 }{14 } = 3 +  \frac{    \sqrt {991} - 19 }{14 } $$
$$    \frac{ 14 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{45 } = 1 +  \frac{    \sqrt {991} - 26 }{45 } $$
$$    \frac{ 45 }{   \sqrt {991} - 26 }  =  \frac{    \sqrt {991} + 26 }{7 } = 8 +  \frac{    \sqrt {991} - 30 }{7 } $$
$$    \frac{ 7 }{   \sqrt {991} - 30 }  =  \frac{    \sqrt {991} + 30 }{13 } = 4 +  \frac{    \sqrt {991} - 22 }{13 } $$
$$    \frac{ 13 }{   \sqrt {991} - 22 }  =  \frac{    \sqrt {991} + 22 }{39 } = 1 +  \frac{    \sqrt {991} - 17 }{39 } $$
$$    \frac{ 39 }{   \sqrt {991} - 17 }  =  \frac{    \sqrt {991} + 17 }{18 } = 2 +  \frac{    \sqrt {991} - 19 }{18 } $$
$$    \frac{ 18 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{35 } = 1 +  \frac{    \sqrt {991} - 16 }{35 } $$
$$    \frac{ 35 }{   \sqrt {991} - 16 }  =  \frac{    \sqrt {991} + 16 }{21 } = 2 +  \frac{    \sqrt {991} - 26 }{21 } $$
$$    \frac{ 21 }{   \sqrt {991} - 26 }  =  \frac{    \sqrt {991} + 26 }{15 } = 3 +  \frac{    \sqrt {991} - 19 }{15 } $$
$$    \frac{ 15 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{42 } = 1 +  \frac{    \sqrt {991} - 23 }{42 } $$
$$    \frac{ 42 }{   \sqrt {991} - 23 }  =  \frac{    \sqrt {991} + 23 }{11 } = 4 +  \frac{    \sqrt {991} - 21 }{11 } $$
$$    \frac{ 11 }{   \sqrt {991} - 21 }  =  \frac{    \sqrt {991} + 21 }{50 } = 1 +  \frac{    \sqrt {991} - 29 }{50 } $$
$$    \frac{ 50 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{3 } = 20 +  \frac{    \sqrt {991} - 31 }{3 } $$
$$    \frac{ 3 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{10 } = 6 +  \frac{    \sqrt {991} - 29 }{10 } $$
$$    \frac{ 10 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{15 } = 4 +  \frac{    \sqrt {991} - 31 }{15 } $$
$$    \frac{ 15 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{2 } = 31 +  \frac{    \sqrt {991} - 31 }{2 } $$
$$    \frac{ 2 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{15 } = 4 +  \frac{    \sqrt {991} - 29 }{15 } $$
$$    \frac{ 15 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{10 } = 6 +  \frac{    \sqrt {991} - 31 }{10 } $$
$$    \frac{ 10 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{3 } = 20 +  \frac{    \sqrt {991} - 29 }{3 } $$
$$    \frac{ 3 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{50 } = 1 +  \frac{    \sqrt {991} - 21 }{50 } $$
$$    \frac{ 50 }{   \sqrt {991} - 21 }  =  \frac{    \sqrt {991} + 21 }{11 } = 4 +  \frac{    \sqrt {991} - 23 }{11 } $$
$$    \frac{ 11 }{   \sqrt {991} - 23 }  =  \frac{    \sqrt {991} + 23 }{42 } = 1 +  \frac{    \sqrt {991} - 19 }{42 } $$
$$    \frac{ 42 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{15 } = 3 +  \frac{    \sqrt {991} - 26 }{15 } $$
$$    \frac{ 15 }{   \sqrt {991} - 26 }  =  \frac{    \sqrt {991} + 26 }{21 } = 2 +  \frac{    \sqrt {991} - 16 }{21 } $$
$$    \frac{ 21 }{   \sqrt {991} - 16 }  =  \frac{    \sqrt {991} + 16 }{35 } = 1 +  \frac{    \sqrt {991} - 19 }{35 } $$
$$    \frac{ 35 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{18 } = 2 +  \frac{    \sqrt {991} - 17 }{18 } $$
$$    \frac{ 18 }{   \sqrt {991} - 17 }  =  \frac{    \sqrt {991} + 17 }{39 } = 1 +  \frac{    \sqrt {991} - 22 }{39 } $$
$$    \frac{ 39 }{   \sqrt {991} - 22 }  =  \frac{    \sqrt {991} + 22 }{13 } = 4 +  \frac{    \sqrt {991} - 30 }{13 } $$
$$    \frac{ 13 }{   \sqrt {991} - 30 }  =  \frac{    \sqrt {991} + 30 }{7 } = 8 +  \frac{    \sqrt {991} - 26 }{7 } $$
$$    \frac{ 7 }{   \sqrt {991} - 26 }  =  \frac{    \sqrt {991} + 26 }{45 } = 1 +  \frac{    \sqrt {991} - 19 }{45 } $$
$$    \frac{ 45 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{14 } = 3 +  \frac{    \sqrt {991} - 23 }{14 } $$
$$    \frac{ 14 }{   \sqrt {991} - 23 }  =  \frac{    \sqrt {991} + 23 }{33 } = 1 +  \frac{    \sqrt {991} - 10 }{33 } $$
$$    \frac{ 33 }{   \sqrt {991} - 10 }  =  \frac{    \sqrt {991} + 10 }{27 } = 1 +  \frac{    \sqrt {991} - 17 }{27 } $$
$$    \frac{ 27 }{   \sqrt {991} - 17 }  =  \frac{    \sqrt {991} + 17 }{26 } = 1 +  \frac{    \sqrt {991} - 9 }{26 } $$
$$    \frac{ 26 }{   \sqrt {991} - 9 }  =  \frac{    \sqrt {991} + 9 }{35 } = 1 +  \frac{    \sqrt {991} - 26 }{35 } $$
$$    \frac{ 35 }{   \sqrt {991} - 26 }  =  \frac{    \sqrt {991} + 26 }{9 } = 6 +  \frac{    \sqrt {991} - 28 }{9 } $$
$$    \frac{ 9 }{   \sqrt {991} - 28 }  =  \frac{    \sqrt {991} + 28 }{23 } = 2 +  \frac{    \sqrt {991} - 18 }{23 } $$
$$    \frac{ 23 }{   \sqrt {991} - 18 }  =  \frac{    \sqrt {991} + 18 }{29 } = 1 +  \frac{    \sqrt {991} - 11 }{29 } $$
$$    \frac{ 29 }{   \sqrt {991} - 11 }  =  \frac{    \sqrt {991} + 11 }{30 } = 1 +  \frac{    \sqrt {991} - 19 }{30 } $$
$$    \frac{ 30 }{   \sqrt {991} - 19 }  =  \frac{    \sqrt {991} + 19 }{21 } = 2 +  \frac{    \sqrt {991} - 23 }{21 } $$
$$    \frac{ 21 }{   \sqrt {991} - 23 }  =  \frac{    \sqrt {991} + 23 }{22 } = 2 +  \frac{    \sqrt {991} - 21 }{22 } $$
$$    \frac{ 22 }{   \sqrt {991} - 21 }  =  \frac{    \sqrt {991} + 21 }{25 } = 2 +  \frac{    \sqrt {991} - 29 }{25 } $$
$$    \frac{ 25 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{6 } = 10 +  \frac{    \sqrt {991} - 31 }{6 } $$
$$    \frac{ 6 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{5 } = 12 +  \frac{    \sqrt {991} - 29 }{5 } $$
$$    \frac{ 5 }{   \sqrt {991} - 29 }  =  \frac{    \sqrt {991} + 29 }{30 } = 2 +  \frac{    \sqrt {991} - 31 }{30 } $$
$$    \frac{ 30 }{   \sqrt {991} - 31 }  =  \frac{    \sqrt {991} + 31 }{1 } = 62 +  \frac{    \sqrt {991} - 31 }{1 } $$
Simple continued fraction tableau:
$$
 \begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}
 & & 31 & & 2 & & 12 & & 10 & & 2 & & 2 & & 2 & & 1 & & 1 & & 2 & & 6 & & 1 & & 1 & & 1 & & 1 & & 3 & & 1 & & 8 & & 4 & & 1 & & 2 & & 1 & & 2 & & 3 & & 1 & & 4 & & 1 & & 20 & & 6 & & 4 & & 31 & & 4 & & 6 & & 20 & & 1 & & 4 & & 1 & & 3 & & 2 & & 1 & & 2 & & 1 & & 4 & & 8 & & 1 & & 3 & & 1 & & 1 & & 1 & & 1 & & 6 & & 2 & & 1 & & 1 & & 2 & & 2 & & 2 & & 10 & & 12 & & 2 & & 62 & \\
 \\
  \frac{ 0 }{ 1 }   &   \frac{ 1 }{ 0 }   & &   \frac{ 31 }{ 1 }   & &   \frac{ 63 }{ 2 }   & &   \frac{ 787 }{ 25 }   & &   \frac{ 7933 }{ 252 }   & &   \frac{ 16653 }{ 529 }   & &   \frac{ 41239 }{ 1310 }   & &   \frac{ 99131 }{ 3149 }   & &   \frac{ 140370 }{ 4459 }   & &   \frac{ 239501 }{ 7608 }   & &   \frac{ 619372 }{ 19675 }   & &   \frac{ 3955733 }{ 125658 }   & &   \frac{ 4575105 }{ 145333 }   & &   \frac{ 8530838 }{ 270991 }   & &   \frac{ 13105943 }{ 416324 }   & &   \frac{ 21636781 }{ 687315 }   & &   \frac{ 78016286 }{ 2478269 }   & &   \frac{ 99653067 }{ 3165584 }   & &   \frac{ 875240822 }{ 27802941 }   & &   \frac{ 3600616355 }{ 114377348 }   & &   \frac{ 4475857177 }{ 142180289 }   & &   \frac{ 12552330709 }{ 398737926 }   & &   \frac{ 17028187886 }{ 540918215 }   & &   \frac{ 46608706481 }{ 1480574356 }   & &   \frac{ 156854307329 }{ 4982641283 }   & &   \frac{ 203463013810 }{ 6463215639 }   & &   \frac{ 970706362569 }{ 30835503839 }   & &   \frac{ 1174169376379 }{ 37298719478 }   & &   \frac{ 24454093890149 }{ 776809893399 }   & &   \frac{ 147898732717273 }{ 4698158079872 }   & &   \frac{ 616049024759241 }{ 19569442212887 }   & &   \frac{ 19245418500253744 }{ 611350866679369 }   & &   \frac{ 77597723025774217 }{ 2464972908930363 }   & &   \frac{ 484831756654899046 }{ 15401188320261547 }   & &   \frac{ 9774232856123755137 }{ 310488739314161303 }   & &   \frac{ 10259064612778654183 }{ 325889927634422850 }   & &   \frac{ 50810491307238371869 }{ 1614048449851852703 }   & &   \frac{ 61069555920017026052 }{ 1939938377486275553 }   & &   \frac{ 234019159067289450025 }{ 7433863582310679362 }   & &   \frac{ 529107874054595926102 }{ 16807665542107634277 }   & &   \frac{ 763127033121885376127 }{ 24241529124418313639 }   & &   \frac{ 2055361940298366678356 }{ 65290723790944261555 }   & &   \frac{ 2818488973420252054483 }{ 89532252915362575194 }   & &   \frac{ 13329317833979374896288 }{ 423419735452394562331 }   & &   \frac{ 109453031645255251224787 }{ 3476890136534519073842 }   & &   \frac{ 122782349479234626121075 }{ 3900309871986913636173 }   & &   \frac{ 477800080082959129588012 }{ 15177819752495259982361 }   & &   \frac{ 600582429562193755709087 }{ 19078129624482173618534 }   & &   \frac{ 1078382509645152885297099 }{ 34255949376977433600895 }   & &   \frac{ 1678964939207346641006186 }{ 53334079001459607219429 }   & &   \frac{ 2757347448852499526303285 }{ 87590028378437040820324 }   & &   \frac{ 18223049632322343798825896 }{ 578874249272081852141373 }   & &   \frac{ 39203446713497187123955077 }{ 1245338526922600745103070 }   & &   \frac{ 57426496345819530922780973 }{ 1824212776194682597244443 }   & &   \frac{ 96629943059316718046736050 }{ 3069551303117283342347513 }   & &   \frac{ 250686382464452967016253073 }{ 7963315382429249281939469 }   & &   \frac{ 598002707988222652079242196 }{ 18996182067975781906226451 }   & &   \frac{ 1446691798440898271174737465 }{ 45955679518380813094392371 }   & &   \frac{ 15064920692397205363826616846 }{ 478552977251783912850150161 }   & &   \frac{ 182225740107207362637094139617 }{ 5788591406539787767296194303 }   & &   \frac{ 379516400906811930638014896080 }{ 12055735790331359447442538767 }    \\
  \\
 & 1 & & -30 & & 5 & & -6 & & 25 & & -22 & & 21 & & -30 & & 29 & & -23 & & 9 & & -35 & & 26 & & -27 & & 33 & & -14 & & 45 & & -7 & & 13 & & -39 & & 18 & & -35 & & 21 & & -15 & & 42 & & -11 & & 50 & & -3 & & 10 & & -15 & & 2 & & -15 & & 10 & & -3 & & 50 & & -11 & & 42 & & -15 & & 21 & & -35 & & 18 & & -39 & & 13 & & -7 & & 45 & & -14 & & 33 & & -27 & & 26 & & -35 & & 9 & & -23 & & 29 & & -30 & & 21 & & -22 & & 25 & & -6 & & 5 & & -30 & & 1
 \end{array}
 $$
$$
 \begin{array}{cccc}
  \frac{ 1 }{ 0 }   & 1^2 - 991 \cdot 0^2 = 1 &     \mbox{digit}  &  31  \\
  \frac{ 31 }{ 1 }   & 31^2 - 991 \cdot 1^2 = -30 &     \mbox{digit}  &  2  \\
  \frac{ 63 }{ 2 }   & 63^2 - 991 \cdot 2^2 = 5 &     \mbox{digit}  &  12  \\
  \frac{ 787 }{ 25 }   & 787^2 - 991 \cdot 25^2 = -6 &     \mbox{digit}  &  10  \\
  \frac{ 7933 }{ 252 }   & 7933^2 - 991 \cdot 252^2 = 25 &     \mbox{digit}  &  2  \\
  \frac{ 16653 }{ 529 }   & 16653^2 - 991 \cdot 529^2 = -22 &     \mbox{digit}  &  2  \\
  \frac{ 41239 }{ 1310 }   & 41239^2 - 991 \cdot 1310^2 = 21 &     \mbox{digit}  &  2  \\
  \frac{ 99131 }{ 3149 }   & 99131^2 - 991 \cdot 3149^2 = -30 &     \mbox{digit}  &  1  \\
  \frac{ 140370 }{ 4459 }   & 140370^2 - 991 \cdot 4459^2 = 29 &     \mbox{digit}  &  1  \\
  \frac{ 239501 }{ 7608 }   & 239501^2 - 991 \cdot 7608^2 = -23 &     \mbox{digit}  &  2  \\
  \frac{ 619372 }{ 19675 }   & 619372^2 - 991 \cdot 19675^2 = 9 &     \mbox{digit}  &  6  \\
  \frac{ 3955733 }{ 125658 }   & 3955733^2 - 991 \cdot 125658^2 = -35 &     \mbox{digit}  &  1  \\
  \frac{ 4575105 }{ 145333 }   & 4575105^2 - 991 \cdot 145333^2 = 26 &     \mbox{digit}  &  1  \\
  \frac{ 8530838 }{ 270991 }   & 8530838^2 - 991 \cdot 270991^2 = -27 &     \mbox{digit}  &  1  \\
  \frac{ 13105943 }{ 416324 }   & 13105943^2 - 991 \cdot 416324^2 = 33 &     \mbox{digit}  &  1  \\
  \frac{ 21636781 }{ 687315 }   & 21636781^2 - 991 \cdot 687315^2 = -14 &     \mbox{digit}  &  3  \\
  \frac{ 78016286 }{ 2478269 }   & 78016286^2 - 991 \cdot 2478269^2 = 45 &     \mbox{digit}  &  1  \\
  \frac{ 99653067 }{ 3165584 }   & 99653067^2 - 991 \cdot 3165584^2 = -7 &     \mbox{digit}  &  8  \\
  \frac{ 875240822 }{ 27802941 }   & 875240822^2 - 991 \cdot 27802941^2 = 13 &     \mbox{digit}  &  4  \\
  \frac{ 3600616355 }{ 114377348 }   & 3600616355^2 - 991 \cdot 114377348^2 = -39 &     \mbox{digit}  &  1  \\
  \frac{ 4475857177 }{ 142180289 }   & 4475857177^2 - 991 \cdot 142180289^2 = 18 &     \mbox{digit}  &  2  \\
  \frac{ 12552330709 }{ 398737926 }   & 12552330709^2 - 991 \cdot 398737926^2 = -35 &     \mbox{digit}  &  1  \\
  \frac{ 17028187886 }{ 540918215 }   & 17028187886^2 - 991 \cdot 540918215^2 = 21 &     \mbox{digit}  &  2  \\
  \frac{ 46608706481 }{ 1480574356 }   & 46608706481^2 - 991 \cdot 1480574356^2 = -15 &     \mbox{digit}  &  3  \\
  \frac{ 156854307329 }{ 4982641283 }   & 156854307329^2 - 991 \cdot 4982641283^2 = 42 &     \mbox{digit}  &  1  \\
  \frac{ 203463013810 }{ 6463215639 }   & 203463013810^2 - 991 \cdot 6463215639^2 = -11 &     \mbox{digit}  &  4  \\
  \frac{ 970706362569 }{ 30835503839 }   & 970706362569^2 - 991 \cdot 30835503839^2 = 50 &     \mbox{digit}  &  1  \\
  \frac{ 1174169376379 }{ 37298719478 }   & 1174169376379^2 - 991 \cdot 37298719478^2 = -3 &     \mbox{digit}  &  20  \\
  \frac{ 24454093890149 }{ 776809893399 }   & 24454093890149^2 - 991 \cdot 776809893399^2 = 10 &     \mbox{digit}  &  6  \\
  \frac{ 147898732717273 }{ 4698158079872 }   & 147898732717273^2 - 991 \cdot 4698158079872^2 = -15 &     \mbox{digit}  &  4  \\
  \frac{ 616049024759241 }{ 19569442212887 }   & 616049024759241^2 - 991 \cdot 19569442212887^2 = 2 &     \mbox{digit}  &  31  \\
  \frac{ 19245418500253744 }{ 611350866679369 }   & 19245418500253744^2 - 991 \cdot 611350866679369^2 = -15 &     \mbox{digit}  &  4  \\
  \frac{ 77597723025774217 }{ 2464972908930363 }   & 77597723025774217^2 - 991 \cdot 2464972908930363^2 = 10 &     \mbox{digit}  &  6  \\
  \frac{ 484831756654899046 }{ 15401188320261547 }   & 484831756654899046^2 - 991 \cdot 15401188320261547^2 = -3 &     \mbox{digit}  &  20  \\
  \frac{ 9774232856123755137 }{ 310488739314161303 }   & 9774232856123755137^2 - 991 \cdot 310488739314161303^2 = 50 &     \mbox{digit}  &  1  \\
  \frac{ 10259064612778654183 }{ 325889927634422850 }   & 10259064612778654183^2 - 991 \cdot 325889927634422850^2 = -11 &     \mbox{digit}  &  4  \\
  \frac{ 50810491307238371869 }{ 1614048449851852703 }   & 50810491307238371869^2 - 991 \cdot 1614048449851852703^2 = 42 &     \mbox{digit}  &  1  \\
  \frac{ 61069555920017026052 }{ 1939938377486275553 }   & 61069555920017026052^2 - 991 \cdot 1939938377486275553^2 = -15 &     \mbox{digit}  &  3  \\
  \frac{ 234019159067289450025 }{ 7433863582310679362 }   & 234019159067289450025^2 - 991 \cdot 7433863582310679362^2 = 21 &     \mbox{digit}  &  2  \\
  \frac{ 529107874054595926102 }{ 16807665542107634277 }   & 529107874054595926102^2 - 991 \cdot 16807665542107634277^2 = -35 &     \mbox{digit}  &  1  \\
  \frac{ 763127033121885376127 }{ 24241529124418313639 }   & 763127033121885376127^2 - 991 \cdot 24241529124418313639^2 = 18 &     \mbox{digit}  &  2  \\
  \frac{ 2055361940298366678356 }{ 65290723790944261555 }   & 2055361940298366678356^2 - 991 \cdot 65290723790944261555^2 = -39 &     \mbox{digit}  &  1  \\
  \frac{ 2818488973420252054483 }{ 89532252915362575194 }   & 2818488973420252054483^2 - 991 \cdot 89532252915362575194^2 = 13 &     \mbox{digit}  &  4  \\
  \frac{ 13329317833979374896288 }{ 423419735452394562331 }   & 13329317833979374896288^2 - 991 \cdot 423419735452394562331^2 = -7 &     \mbox{digit}  &  8  \\
  \frac{ 109453031645255251224787 }{ 3476890136534519073842 }   & 109453031645255251224787^2 - 991 \cdot 3476890136534519073842^2 = 45 &     \mbox{digit}  &  1  \\
  \frac{ 122782349479234626121075 }{ 3900309871986913636173 }   & 122782349479234626121075^2 - 991 \cdot 3900309871986913636173^2 = -14 &     \mbox{digit}  &  3  \\
  \frac{ 477800080082959129588012 }{ 15177819752495259982361 }   & 477800080082959129588012^2 - 991 \cdot 15177819752495259982361^2 = 33 &     \mbox{digit}  &  1  \\
  \frac{ 600582429562193755709087 }{ 19078129624482173618534 }   & 600582429562193755709087^2 - 991 \cdot 19078129624482173618534^2 = -27 &     \mbox{digit}  &  1  \\
  \frac{ 1078382509645152885297099 }{ 34255949376977433600895 }   & 1078382509645152885297099^2 - 991 \cdot 34255949376977433600895^2 = 26 &     \mbox{digit}  &  1  \\
  \frac{ 1678964939207346641006186 }{ 53334079001459607219429 }   & 1678964939207346641006186^2 - 991 \cdot 53334079001459607219429^2 = -35 &     \mbox{digit}  &  1  \\
  \frac{ 2757347448852499526303285 }{ 87590028378437040820324 }   & 2757347448852499526303285^2 - 991 \cdot 87590028378437040820324^2 = 9 &     \mbox{digit}  &  6  \\
  \frac{ 18223049632322343798825896 }{ 578874249272081852141373 }   & 18223049632322343798825896^2 - 991 \cdot 578874249272081852141373^2 = -23 &     \mbox{digit}  &  2  \\
  \frac{ 39203446713497187123955077 }{ 1245338526922600745103070 }   & 39203446713497187123955077^2 - 991 \cdot 1245338526922600745103070^2 = 29 &     \mbox{digit}  &  1  \\
  \frac{ 57426496345819530922780973 }{ 1824212776194682597244443 }   & 57426496345819530922780973^2 - 991 \cdot 1824212776194682597244443^2 = -30 &     \mbox{digit}  &  1  \\
  \frac{ 96629943059316718046736050 }{ 3069551303117283342347513 }   & 96629943059316718046736050^2 - 991 \cdot 3069551303117283342347513^2 = 21 &     \mbox{digit}  &  2  \\
  \frac{ 250686382464452967016253073 }{ 7963315382429249281939469 }   & 250686382464452967016253073^2 - 991 \cdot 7963315382429249281939469^2 = -22 &     \mbox{digit}  &  2  \\
  \frac{ 598002707988222652079242196 }{ 18996182067975781906226451 }   & 598002707988222652079242196^2 - 991 \cdot 18996182067975781906226451^2 = 25 &     \mbox{digit}  &  2  \\
  \frac{ 1446691798440898271174737465 }{ 45955679518380813094392371 }   & 1446691798440898271174737465^2 - 991 \cdot 45955679518380813094392371^2 = -6 &     \mbox{digit}  &  10  \\
  \frac{ 15064920692397205363826616846 }{ 478552977251783912850150161 }   & 15064920692397205363826616846^2 - 991 \cdot 478552977251783912850150161^2 = 5 &     \mbox{digit}  &  12  \\
  \frac{ 182225740107207362637094139617 }{ 5788591406539787767296194303 }   & 182225740107207362637094139617^2 - 991 \cdot 5788591406539787767296194303^2 = -30 &     \mbox{digit}  &  2  \\
  \frac{ 379516400906811930638014896080 }{ 12055735790331359447442538767 }   & 379516400906811930638014896080^2 - 991 \cdot 12055735790331359447442538767^2 = 1 &     \mbox{digit}  &  62  \\
 \end{array}
 $$
379516400906811930638014896080 mod  991 = 1
-39,  -35,  -30,  -27,  -23,  -22,  -15,  -14,  -11,  -7,
-6,  -3,  1,  2,  5,  9,  10,  13,  18,  21,
25,  26,  29,  33,  42,  45,  50,


how to make Autobahn WAMP Python server & Javascript client work together?

Question: I have a Python Autobahn WAMP server (v. 0.8.8, app code at http://pastebin.com/DfQvaJYF) working fine with a Python client. Using latest Twisted 13.2. for both server and client.
However, the browser javascript client (autobahn js from CDN, app code at http://pastebin.com/1GGaRP5e) similarly taken from Autobahn JS examples subscribes to a topic, but does not receive any messages. There are no errors whatsoever anywhere. Same happens when running the client using Node.js.
Checking the server log, I can see that nothing is indeed transmitted - there are no TX WAMP EVENTs ever, after the js web or the Node.js client connects and subscribes.
The WAMP server is running on port 8080, and the JS web client page is served from port 8111. Both on the same host.
Comment: Try connecting a 2nd client (which also subscribes). The publisher session by default does not receive the event itself.
Comment: Ah, you're publishing from loop in server. So above comment does not apply. Another thing: on Python side, you seam to be using the implicit default realm "realm1", whereas with JS you use "tutorialpubsub" ... try making the latter "realm1".
Comment: Thanks. After answering myself below, I checked the autobahn code and it seems to me autobahn sets the default realm to None, not "realm1" as you suggest. Or did I misunderstand your meaning?
Answer: Found the issue. Thank you @oberstet for commenting (see above). While just setting the client realm to suggested default realm1 did not work, that lead me towards the solution.
The short and simple answer is that the Python WAMP server should always explicitly set the realm. This applies at least when the server implements a component that subclasses wamp.ApplicationSession (many or all the examples at the autobahn website).
In other words, in the server there has to be an onConnect function that joins a realm. Without it,

a similarly constructed Python client (that does not join a realm), will work
no (Python or Javascript) client that sets a realm will work

Some speculation beyond the solution: If one can build a Javascript client that works without setting a realm (example I used requires explicit realm), perhaps such a client would work as well. Perhaps the Python WAMP server code is buggy in its setting of default realm. Or maybe it's just that the default has been changed. I don't know.


Song for Guy chorus synth sound

Question: I'm currently trying to reproduce the sounds of Elton John's Song for Guy as a learning project, and I'm stuck with the wind-like sound that accompanies each chorus (and the third and following repetitions of the initial song motif at the end, before EJ starts to sing).
I have a quite convincing bass, and the strings that accompanies the second part of the chorus to its conclusion are good too, but I can't understand what that sound is. I've tried some white noise with a low-pass filter (with a slight resonance) where an envelope changes the cut-off frequency of the filter along with the chorus' parts and it sounds like it when the frequency is high and the sounds morphs into a kind of hiss. However, when the frequency is lower, this isn't it, and by long. It sounds like some king of chord, but without tonality, only resonance, if you get my clumsy meaning. But what chord, anyway, as it seems to be always in tone with each part of the chorus (or it's the filter doing that)?
How on earth is that sound made?
PS: In addition, I found that my accompaniment lacks depth. As a relative newbie, I added more reverb, but that's not enough, obviously. Is there resources on the web on how to construct studio "wall of sound like" depth? And how one teaches oneself to recreate sounds (I've watched hours of sound design videos, but I'm often stuck when trying to learn how to make a sound from a song that is not exactly what I found in some tutorial)?
Comment: Your second question needs to be asked separately.
Comment: Try a phaser....
Comment: @Tim: did that, already, and got similar results. It's probably the base sound that I don't get, not the filter?
Comment: Have you used keyboard scaling on the filter cutoff? Do you have a synth that is similar enough to the original synth?
Comment: @ToddWilcox: no, I haven't used keyboard scaling yet, as I was too far from a sound that came near the original sound to add what I considered cake icing at that point. Same for the synth. I planned to continue playing with Serum until I got an acceptable sound, then move to something more similar to the original.
Answer: High resonance [Q], hi-pass filter sweep.
Likely playing one or more notes of the chord structure as it changes - this will be a significant part of the sound, switching up the inversions & spread of the notes as this section increases in sonic impact. What the sound is underneath would be quite hard to tell, but obviously one with a lot of high frequency in it, perhaps a saw-tooth base. There may be some noise mixed into it, but I'm not really hearing any.
I'd guess the sweep was done manually rather than as part of the patch, as the speed changes over time [& is a bit lumpy in places] - one hand for the notes, the other for the filter knob.
The record's release date of 1978 would be perfect for it to have been played on the then newly-released Prophet 5, the first mainstream polyphonic synth.
You can get software imitations of the Prophet these days - notably that by Arturia
Other potential candidates from the time may have been the Yamaha CS-80 or [imo less likely] the Oberheim Poly or the PolyMoog
Comment: I was curious about what synth was used in the original recording.
Comment: Yeah… I've thrown another couple of possibles into the answer, but other than the CS-80 I really don't think there was much else at the time that would give that kind of sound. The CS was a fun little [or actually huge] oddball, much favoured by Stevie Wonder. My money is on the Prophet, though I couldn't say for sure. I didn't have one until 1980/1 & I wasn't thinking about how other people made sounds before that, other than the notables, Kraftwerk, Human League etc who weren't using polys at that time, only Gary Numan with his famous PolyMoog had really dented that field for me at the time.
Answer: If you mean the parts like the one starting around...

 ...I think you want a synth pad.
This seems like a nice tutorial just to get the concept of pads:

But, you can find plugins for pads that are preset with that kind of "sweeping" sound, you don't necessarily need to create your own. Some pads put most of the sweep in the initial sustain then hold one tone, others continuously sweep. You might need to try out several before finding one you like.

Song for Guy chorus synth sound


Solve the improper integral: $\int_1^{\infty}\frac{33e^{-\sqrt{x}}}{\sqrt{x}}$

Question: I'm completely stuck on this one. I only know that it converges thanks to Wolfram, but I don't know how to evaluate it.
$$\int_1^{\infty}\frac{33e^{-\sqrt{x}}}{\sqrt{x}}$$
Thank you for the help.
Comment: Did you mean $\int_1^\infty e^{-\sqrt{x}}/\sqrt{x}\,dx$?
Comment: Let $u={\sqrt x}$.
Answer: Hint. If you make the change of variable
$$
u=\sqrt{x},\quad du=\frac{dx}{2\sqrt{x}},
$$ then
$$
\int_1^{\infty}\frac{33e^{-\sqrt{x}}}{\sqrt{x}}\:dx=66\int_1^{\infty}e^{-u}\:du.
$$
Comment: I didn't see that. Thanks!
Comment: @DanielWaleniak You are welcome.


How to sample live and loop with live musicians without a laptop?

Question: I'm a musician in a live band that plays folkadelic music.  Folkadelic music is played by bands like Kila or Shooglenifty. Instrument mix is acoustic guitar, electric guitar, fiddle, bass, drum kit and horns.
I want to add live sampling and looping to our performance.
The workflow I'm thinking of is that the looping musician (the looper, let's call it)  has feeds from each of the musicians. While the band is playing the looper samples one of the other musicians' performance and then triggers that sample or samples live.  I could loop the samples automatically in a sequencer or manually by repeatedly triggering the sample(s) by finger drumming on trigger pads.
The band doesn't play to click so for this to work, the looper's instrument has to make it quick to sample, trim and quantize the sample and then change tempo on the fly using some sort of tap tempo function or by manually triggering the sequence.
Note that I'm not talking about just playing loops at the same tempo as the live music. I've got that, thanks. I'm really looking at something like creating and playing hip-hop beats in a live situation from live samples. That requires being able to trim live samples down to phrases or notes with ease. It also requires being able to finger drum trigger pads.
Oh and I don't want to use a laptop. I've found dedicated hardware to be much more reliable and robust.
Is it possible to do something like this with an Akai MPC Live, Electribe 2 or something like that?  Does anyone have experience with this?
Comment: You can crop samples with a few, but in reality, the problem you describe is generally not fixed by cropping or trimming samples, but by running the looper she same tempo as the music
Comment: @DoktorMayhem I'm familar with changing tempos of loopers to match live music, (search "user:10635 [looping]"). I'm really looking at something like developing hiphop beats in a live situation from live samples. That requires being able to trim samples down to phrases or notes with ease.  I'll edit my question to make it clearer.
Comment: There are various loopers on the market and they all do what you need. Mostly triggered from foot switch.
Comment: @DoktorMayhem I'm familar with most of the simple loopers. They don't allow trimming the samples.
Comment: Ah - I think I get what you mean. Some do allow cropping, but it's difficult. Normally you'd grab the sample at the length you want, and then let the looper autotrim past the loop length. A laptop is usually the way to go - most of the bands we play with use laptops on stage (and in our experience the only ones that have given issues are macbooks :-/)  -
Answer: I've looked at the Electribe 2 sampler and the Akai MPC Live standalone online.  Unfortunately, I only own the Electribe 2 so the Akai info is from online.
It appears that the Akai MPC Live would be the best choice for this sort of performing.
As you can see from this video, with practice sample capture and editing is quick on the Akai using its multitouch screen and waveform display.

This is a lot harder on the Electribe 2.  With the Electribe, you have adjust the start and endpoints by twiddling a knob and the only display of the sample is a single numeric value in fractions of a second.
I'm not sure if the Akai can change playback tempo in realtime with onboard controls, because I don't have the device in front of me, but it does accept external MIDI syncing from an external MIDI controller, so I can use the Electribe 2 or some other controller to change the playback speed.
Answer: I think you could look also at Casio the designer of the mighty SK-5 and FZ-1, the models like XW-G1 (discontinued) or MZ-X500 https://www.casiomusicgear.com/products/mz-x-series/mz-x500 could sample live block and have them sequenced as drum patterns with either a step sequencer (XW-G1) or a 16-track MIDI sequencer (MZ-X500)
Comment: Big and heavy though.


Exim SMTP Smarthost Setup

Question: I used these settings to set up exim to use gmail as a smarthost, which worked. However, I don't seem to be able to use these settings against other smtp servers, such as Yahoo or Fastmail (both with port 465 instead of 587). Both of these fail with the message defer (-18): Remote host smtp.example.com [x.x.x.x] closed connection in response to initial connection. Is there anything wrong with these settings? What could be going wrong?
my_route:
  driver = manualroute
  domains = ! +local_domains
  transport = my_relay
  route_list = * smtp.mail.yahoo.com

my_relay:
  driver = smtp
  port = 465
  hosts_require_auth = $host_address
  hosts_require_tls = $host_address

my_login:
  driver = plaintext
  public_name = LOGIN
  hide client_send = : email@example.com : my_password

Comment: Could you add output of the "# exim -d+all firstname.lastname@example.com < /dev/null" to your question?
Comment: It's working now. I'm not sure exactly what was going on, but I think at least part of my problem was misunderstanding what `(-53): retry time not reached for any host` meant.
Comment: Additionally I had the Fastmail password wrong as I thought I could use an [Alternate Login](http://www.emaildiscussions.com/showthread.php?p=560242#post560242), and it's possible that Yahoo have blocked me as they sent me an email asking me to change my password due to suspicious activity. Having said all that I didn't get any meaningful error messages.
Answer: Had same challenge and solved it by changing smtp port from 465 (SSL/TLS) to 587 (STARTTLS).

Exim SMTP Smarthost Setup


Learning eastern european music style on harmonica?

Question: I am a beginner harmonica player. I bought recently a C harmonica and subscribed to two online learning courses. After a few weeks, I noticed I would prefer to learn some Eastern European/gypsy melodies instead of those blues/campfire songs which they teach in my courses. Can somebody recommend an online course for that purpose? On which harp do people play Eastern European music? A minor harp?
I still will continue my subscribed courses. I noticed in one course the teacher uses an A harmonica. I play on a C harmonica. Does that matter?
Comment: I'm not able to play the harmonica but I'm pretty sure you need a __harmonic minor__ harmonica (so not natural minor) to play in gypsy style
Comment: Playing by yourself, it doesn't really matter what key your harmonica is in. Playing with others, if the song's in C, use a C harp, or for cross harp playing, use an F.
Comment: @skymedium could you post some examples of eastern european or gypsy harmonica playing?  I'm not an expert in this area of harmonica music, but if you post some videos or recordings, I will be able to tell you what type of harmonica it is, and in what key they're playing it.
Comment: it would be possible to play gypsy melodies on a 10 hole harmonica in cross harp (the flat 2 is available in that position, and there are some useful bends to play some of the necessary melodic inflections, just like fiddle and clarinet players in that style do).  However, while I know that you *could* play gypsy/eastern European harmonica like that, I don't know if that's what those players actually do (because I've never heard a harmonica played like that)
Comment: @Some_Guy There is an example. Found out he is playing an A minor harmonica.
Comment: @skymedium do you have some video or audio you could share of this example?  I'm very curious
Comment: @Some_Guy Completely forgot to add the link: https://www.youtube.com/watch?v=ZOYxmf4-7Sg He also offers a teaching lesson on that tune: https://www.youtube.com/watch?v=02qZcYC0hEM Another lesson I found: https://www.youtube.com/watch?v=lEHEYYrQlLY
Answer: The harmonica keys should correspond to the key of the music, regardless of the genre in which you are playing... The "C", "A", "D", "F", and "G" keys are a good place to start for beginners. Here is a little chart:

This article gives a beginner's look at the harmonica positions, if you haven't already reached that in your lessons... A summarized description of the first 3 positions:

1st position starts on the 1 blow, 4 blow and is the same key as the
  harmonica
2nd position starts on 2 draw, 6 blow and is a fifth up from the key
  of the harmonica
3rd position starts on 1 draw, 4 draw and is one tone up from the key
  of the harmonica

As you play more with others and grow your abilities, you will likely also want to look into the various harmonica types.
Many harmonica players have lots and lots of harmonicas in various keys and of various types:

From there, playing in a specific genre will be based on the style you implement. Listen to a lot of eastern European music and practice in that style.


remainder of polynomial division

Question:
The polynomial $P$ gives a remainder of $5x-7$ when divided by $x^2 -1$. Find the remainder when $P$ is divided by $x-1$.

I know we can use Bezout's theorem. Thus for $x-1$ the remainder will be $-2$. I am just not sure if this is the correct answer.
Answer: Yes, the remainder will be $-2$. We know that:
\begin{align*}
P(x) &= Q_1(x)(x^2 - 1) + (5x - 7) \\
P(x) &= Q_2(x)(x - 1) + r
\end{align*}
where $Q_1(x)$ and $Q_2(x)$ are some polynomials and $r$ is a constant. By setting $x = 1$, we know from the first equation that $P(1) = -2$. Doing likewise for the second equation yields $r = -2$.
Answer: Hint $\ {\rm mod}\,\ x\!-\!1\!:\,\ \color{#c00}{x\equiv 1}\,\Rightarrow\, (\color{#c00}x^2\!-\!1)q(\color{#c00}x) + r(\color{#c00}x) \,\equiv\, (\color{#c00}1^2\!-\!1)q(\color{#c00}1) + r(\color{#c00}1)\,\equiv\, r(\color{#c00}1)\,$ by $\:\equiv$ Rules.
Remark $\ $ Generally note that $\ P\equiv r\pmod{\!fg}\,\Rightarrow\,P\equiv r\pmod{\! f},\ $ by $\,f\mid fg\mid P-r,\ $ i.e. congruences descend to divisors of the modulus. Above is special case $\,f,g = x\!-\!1,x\!+\!1,\,$ which yields $\ P\equiv r(x)\pmod{\!x^2\!-\!1}\,\Rightarrow\, P\equiv r(x) \pmod{\!x\!-\!1}.\,$ But $\ r(\color{#c00}x)\equiv r(\color{#c00}1)\pmod{x\!-\!1}.$
Answer: $$P(x) =  (x^2-1)q(x) + (5x-7)$$
By remainder theorem, $P(1)$ is the remainder when $P(x)$ is dvided by $x-1$; so you may simply evaluate $P(1)$

remainder of polynomial division