Property '...' has no initializer and is not definitely assigned in the constructor

Question: in my Angular app i have a component:
import { MakeService } from './../../services/make.service';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-vehicle-form',
  templateUrl: './vehicle-form.component.html',
  styleUrls: ['./vehicle-form.component.css']
})
export class VehicleFormComponent implements OnInit {
  makes: any[];
  vehicle = {};

  constructor(private makeService: MakeService) { }

  ngOnInit() {
    this.makeService.getMakes().subscribe(makes => { this.makes = makes
      console.log("MAKES", this.makes);
    });
  }

  onMakeChange(){
    console.log("VEHICLE", this.vehicle);
  }
}

but in the "makes" property I have a mistake.
I dont know what to do with it...
Comment: I am wondering: On newer versions of TypeScript, did anyone figured it out how to specify the object type that will reside inside the array? Instead of using Any[]... ✍
Answer: Just go to tsconfig.json and set
"compilerOptions": {
    "strictPropertyInitialization": false,
    ...
}

to get rid of the compilation error.
Otherwise you need to initialize all your variables which is a little bit annoying
Comment: In this way you will disable the strict checking property initialization for all the project. It's better to add the `!` postfix operator to the variable name, to just ignore this case, or initialize the variable inside the constructor.
Comment: You are suggesting to ignore potential problems that the compiler is telling about, this is not really safe. So downvote.
Comment: StrictPropertyInitialzer is a flag introduced in typescript 2.7. It's up to everybody to choose if you want to enable all these flags and strictly follow all rules or turn off some validation. It makes completely no sense to follow all the rules every time. If your code gets too verbose and downsides and are bigger than advantages you should definetly turn it off. I am not telling that this is the best practice in all cases but its definetly viable option in most cases...
Comment: Just make sure you add that after "strict": true else the transpiler seems to turn it on again (although VS seems to know it's off).
Comment: As I mentioned in my answer you have two options either you disable validation OR initialize all variables. Its up to everybody to choose what will you benefit more from project to project.
Comment: when I set it to false it still gives me the same error, what might be the issue? I'm using VS Code
Comment: Thanks! In `tsconfig.json` .. `compilerOptions` ... I updated the value of strict from true to false ... `"strict": false`     and it fixed the issue.
Comment: For anyone else wondering, this entry has to be added in the "compilerOptions" parts of tsconfig.json
Comment: After adding, I needed to restart vsCode to solve it.
Comment: As suggested by Matteo Guarnerio, it is best to add ! to assert that this particular variable will be initialized for sure rather than using compiler options to disable the check for the entire application
Comment: Good suggestion I prefer this approach compared to marking the variable with `!` or initialising. Especially for subscriptions that take place on OnInit.
Comment: I thought the whole point of TypeScript was to avoid doing this kind of thing. Wouldn't you at least want to assign `undefined` or `null` or something?
Comment: avoid at all costs removing/disabling compiler or lint options if you are deploying for production
Comment: wow ts won't let you work around this garbage with this.field = null in the constructor either.  thanks ts for forcing me to choose bogus initial values for everything, so helpful
Comment: This advice is technically an option, but typically inadvisable, because it reduces the effectiveness of TypeScript and overall code quality could go down as a result.

In my opinion, this approach is akin to using a sledge hammer to put a screw in a wall... yeah, the screw will go in, but you're also going to damage the wall in the process, and the screw probably isn't going to secure anything effectively anyway.
Comment: Most of the time it's better to use hammer that you are used to and put screw gently in to the wall so you don't do any damage than have twenty different tools not knowing to use properly even one of them and in the process damage the wall, the screw and yourself.
Comment: I think this is a design error of typeorm. Even if you disable it with a `!` you can assign a null that value. It is not required in the constructor anymore... The fact that they do not mention it in their documentation tells already the story.
Comment: Leandro, propertyInitialization option was added later in typescript as a compiler check option. Does that mean that before that all the written code was wrong because typescript didnt force you to do this ? Its up to everybody to choose his standarts / rules on his particular project. What works best for you and what you agreed on as a team to follow. If you dont want to turn off this check feel free to do it the other way. What works for you doesnt mean is the best way for all of us. We have a choice.
Comment: Terrible advice, downvote.
Answer: I think you are using the latest version of TypeScript. Please see the section "Strict Class Initialization" in the link.
There are two ways to fix this:
A. If you are using VSCode you need to change the TS version that the editor use.
B. Just initialize the array when you declare it
makes: any[] = [];

or inside the constructor:
constructor(private makeService: MakeService) {
   // Initialization inside the constructor
   this.makes = [];
}

Comment: You must use 'Definite Assignment Assertion' to tell typescript that this variable will have a value at runtime as follows: `makes!: any[];`
Comment: Initializing variables in the constructor is an Angular anti-pattern. Don't do it.
Comment: as the error says you need to initialize the variable to some value makes: any[] = [];
Comment: @KumaresanSd `ctrl+shift+p` and type `typescript` in the dropdown, then select "Select TypeScript Version"
Comment: @MartinSchneider your first source, in context, makes sense. It's saying "you're using the wrong lifecycle hook". Your second source says "no more than", meaning they can also do less. In practice, putting any logic in constructors has a tendency to make code less clean, as one expects all initializations to be done in ngOnInit. Perhaps it would be more correct of me to call it code smell, rather than an anti-pattern. Still, it's not good practice.
Comment: @RaulChiarella Hello!!, If you have strict mode enabled, and you don't give a value declared on initialisation, one way to is to include ! after the variable name. example:
makes: any[]; //doesn't work
makes!: any[]; // should work fine

In the second example you telling the IDE that you are sure this value will be declared before being used.
Comment: HI @Sajeetharan, how to chnage vscode ts version
Comment: @WillAlexander So why Angular Docs say _"the recommended solution is to use a constructor or ngOnInit to set initial values"_ ([src](https://angular.io/errors/NG0100#debugging-the-error)) or _"Constructors should do no more than set the initial local variables to simple values."_ ([src](https://angular.io/guide/lifecycle-hooks#initializing-a-component-or-directive))?
Comment: @HusseinAkar Hello! What do you mean? I am using ngOnInit to populate this array of objects of the `interface` type. So I need to include the `!` after the variable declaration, because of that?
Comment: Where did this MakeService come from?
Comment: I tried this multiple times and using multiple ways and can not get it to work.
Answer: It is because TypeScript 2.7 includes a strict class checking where all the properties should be initialized in the constructor. A workaround is to add
 the ! as a postfix to the variable name:
makes!: any[];

Comment: The "!" syntax exists for those common-ish cases where you can't guarantee that the value will be defined immediately. It's an escape hatch, and shouldn't be relied on, as it can make your code less safe. A default value is usually preferred. Good to know it exists, though
Comment: This is the best solution, since it is directly after the @Input() decorator (in the new angular), when reading any given component, it reads naturally and culls out any dev mistakes.
Comment: @kingdaro is right.  While this can generally be used, it can also lead to code that flat doesn't work.  As an example, in the basic webapp generated by VS2017, change the assignment for the forecasts in fetchdata.components.ts by adding the '!' (public forecasts!: WeatherForecast[];) and it will cause it to completely error out
Comment: incidentally what is the difference from using ! or ? to handle nulls or undefined?
Comment: I needed to define a property that uses an Enum in a service on an app where I can't assume the user's choices, not even a default. It is defined in the first step and not read until the second, so this was very useful escape, good to know it exists, thanks very much.
Comment: This is not recommended when the property is assigned within a subscribe or async callback. There will be a short period of time where it is undefined and the template will throw errors. Use ?:
Answer: We may get the message Property has no initializer and is not definitely assigned in the constructor when adding some configuration in the tsconfig.json file so as to have an Angular project compiled in strict mode:
"compilerOptions": {
  "strict": true,
  "noImplicitAny": true,
  "noImplicitThis": true,
  "alwaysStrict": true,
  "strictNullChecks": true,
  "strictFunctionTypes": true,
  "strictPropertyInitialization": true,

Indeed the compiler then complains that a member variable is not defined before being used.
For an example of a member variable that is not defined at compile time, a member variable having an @Input directive:
@Input() userId: string;

We could silence the compiler by stating the variable may be optional:
@Input() userId?: string;

But then, we would have to deal with the case of the variable not being defined, and clutter the source code with some such statements:
if (this.userId) {
} else {
}

Instead, knowing the value of this member variable would be defined in time, that is, it would be defined before being used, we can tell the compiler not to worry about it not being defined.
The way to tell this to the compiler is to add the ! definite assignment assertion operator, as in:
@Input() userId!: string;

Now, the compiler understands that this variable, although not defined at compile time, shall be defined at run-time, and in time, before it is being used.
It is now up to the application to ensure this variable is defined before being used.
As an an added protection, we can assert the variable is being defined, before we use it.
We can assert the variable is defined, that is, the required input binding was actually provided by the calling context:
private assertInputsProvided(): void {
  if (!this.userId) {
    throw (new Error("The required input [userId] was not provided"));
  }
}

public ngOnInit(): void {
  // Ensure the input bindings are actually provided at run-time
  this.assertInputsProvided();
}

Knowing the variable was defined, the variable can now be used:
ngOnChanges() {
  this.userService.get(this.userId)
    .subscribe(user => {
      this.update(user.confirmedEmail);
    });
}

Note that the ngOnInit method is called after the input bindings attempt, this, even if no actual input was provided to the bindings.
Whereas the ngOnChanges method is called after the input bindings attempt, and only if there was actual input provided to the bindings.
Comment: this is the correct answer when using 'strict' mode
Comment: This should be upvoted as the correct answer, as it solves the problem, rather than just turning of part of the linting.
Comment: A lot of this makes sense to me apart from one thing... What would the assert give you? Would be fine for debugging, but not for using the app. Throwing errors that will not be caught is not a good idea. You should provide some fallback that will make things work no matter what.
Comment: Using "definite assignment assertion" in strict mode just to avoid the condition checks doesn't make great sense. You are undermining the whole logic of having a strict typed system. If avoiding those checks is more important to you, then you probably shouldn't use strict mode.
Answer: Go to your tsconfig.json file and change  the property:
 "noImplicitReturns": false

and then add
 "strictPropertyInitialization": false

under "compilerOptions" property.
Your tsconfig.json file should looks like:

{
      ...
      "compilerOptions": {
            ....
            "noImplicitReturns": false,
            ....
            "strictPropertyInitialization": false
      },
      "angularCompilerOptions": {
         ......
      }
 }

Hope this will help !!

Good Luck
Comment: IMO, it is kinda going backward.
Comment: Firstly, thanks for the solution, it worked. Secondly, can anyone explain what just happened?
Comment: It worked ,  it is necessary when creating directives in angular.
Answer: The error is legitimate and may prevent your app from crashing. You typed makes as an array but it can also be undefined.
You have 2 options (instead of disabling the typescript's reason for existing...):
1. In your case the best is to type makes as possibily undefined.
makes?: any[]
// or
makes: any[] | undefined

So the compiler will inform you whenever you try to access to makes that it could be undefined.
Otherwise, if the // <-- Not ok lines below were executed before getMakes finished or if getMakes failed, your app would crash and a runtime error would be thrown. That's definitely not what you want.
makes[0] // <-- Not ok
makes.map(...) // <-- Not ok

if (makes) makes[0] // <-- Ok
makes?.[0] // <-- Ok
(makes ?? []).map(...) // <-- Ok

2. You can assume that it will never fail and that you will never try to access it before initialization by writing the code below (risky!). So the compiler won't take care about it.
makes!: any[]

More specifically,
Your code's design warrants improvement. Best practices discourage the use of locally defined and mutable variables. A more effective approach involves managing data storage within a service:

To ensure null/undefined safety,
To factorise code (including typing, loading state and errors),
To control unnecessary re-fetch across components.

Here's an illustrative example of the concept I'm proposing. Please note that I have not tested it, and there is room for further improvement.
type Make = any // Type it

class MakeService {

  private readonly source = new BehaviorSubject<Make[] | undefined>(undefined);
  loading = false;

  private readonly getMakes = (): Observable<Make[]> => {
    /* ... your current implementation */
  };

  readonly getMakes2 = () => {
    if (this.source.value) {
      return this.source.asObservable();
    }
    return new Observable(_ => _.next()).pipe(
      tap(_ => {
        this.loading = true;
      }),
      mergeMap(this.getMakes),
      mergeMap(data => {
        this.source.next(data);
        return data;
      }),
      tap(_ => {
        this.loading = false;
      }),
      catchError((err: any) => {
        this.loading = false;
        return throwError(err);
      }),
    );
  };
}

@Component({
  selector: 'app-vehicle-form',
  template: `

Loading...

      {{vehicle.name}}

  `,
  styleUrls: ['./vehicle-form.component.css']
})
export class VehicleFormComponent implements OnInit {
  constructor(public makeService: MakeService) {}

  readonly makes = this.makeService.getMakes2().pipe(
    tap(makes => console.log('MAKES', makes))
  );

  readonly vehicules = this.makes.pipe(
    map(make => make/* some transformation */),
    tap(vehicule => console.log('VEHICLE', vehicule)),
  );

  ngOnInit() {
    this.makes.subscribe(makes => {
      console.log('MAKES', makes);
    });
  }
}

Comment: This seems like the only correct solution. I'm horrified by the other answers.
Comment: I also consider that this error message is useful. So deactivate it in tsconfig.json is not the appropriate solution. And adding '!' can allows the compiler to let go, but it makes the code less sure, unless you're really sure of what is going on. A better solution seems to understand that the property can be undedinfed, and therefore the developer has to write code accordingly. This is the purpose of the answer to me.
Comment: @Rei Miyasaka, this "feature" was added later to typescript does that mean that all code that was written before is wrong ? No it does not. When you have your hello world application feel free to follow all the rules. But once you have huge project (which is a reason for language like typescript to start with) then you should decide how to write the code and all should follow it. I don't see ANYTHING wrong with disabling this particular option in tsconfig.json.
Comment: @MartinČuka Just because everyone was doing it doesn't mean it wasn't wrong or that it wasn't horrifying. TypeScript itself was brought about because JavaScript is kind of horrifying. And the larger the project, the more you should want to be strict with type rules.
Comment: option 2 adding a `!` before `:` is more common.
Answer: there are many solutions

demo code

class Plant {
  name: string;
  // ❌ Property 'name' has no initializer and is not definitely assigned in the constructor.ts(2564)
}

solutions

add 'undefined' type

class Plant {
  name: string | undefined;
}

add definite assignment assertion

class Plant {
  name!: string;
}

declare with init value

class Plant {
  name: string = '';
}

use the constructor with an init value

class Plant {
  name: string;
  constructor() {
    this.name = '';
  }
}

use the constructor and init value by params

class Plant {
  name: string;
  constructor(name: string) {
    this.name = name ?? '';
  }
}

shorthand of the 5

class Plant {
  constructor(public name: string = name ?? '') {
    //
  }
}

tsconfig.json

not recommended

{
  "compilerOptions": {
+   "strictPropertyInitialization": false,
-   "strictPropertyInitialization": true,
  }
}

refs
https://www.typescriptlang.org/docs/handbook/2/classes.html#--strictpropertyinitialization
Answer:
Go to tsconfig.json

add "strictPropertyInitialization": false, in "compilerOptions":
Answer: Update for 2021  :

there is property like "strictPropertyInitialization"

Just go to tsconfig.json and set
"strict": false
to get rid of the compilation error.
Otherwise you need to initialize all your variables which is a little bit annoying.
reason behind this error is :

typescript is a kind of more Secure lang  as compare to javascript.
although this security is enhance by enabling strict feature .So every time when you initialize a variable typescript wants them to assign a value.
Comment: Horrible advice, throws out type safety so that you see fewer errors, rather than surrendering some convenience for safety.
Comment: Apparently, strict option is a combination of several strict type-checking options in TypeScript, including noImplicitAny, strictNullChecks, strictFunctionTypes, strictPropertyInitialization, noImplicitThis, and alwaysStrict. Maybe a bad idea to disable all of that?
Answer: You either need to disable the --strictPropertyInitialization that
Sajeetharan referred to, or do something like this to satisfy the initialization requirement:
makes: any[] = [];

Answer: You can also do the following if you really don't want to initialise it.
makes?: any[];

Answer: A batter approach would be to add the exclamation mark to the end of the variable for which you are sure that it shall not be undefined or null, for instance you are using an ElementRef which needs to be loaded from the template and can't be defined in the constructor, do something like below
class Component {
 ViewChild('idname') variable! : ElementRef;
}

Answer: If you want to initialize an object based on an interface you can initialize it empty with following statement.
myObj: IMyObject = {} as IMyObject;

Comment: Beware that this does not provide type safety. After doing this, typescript will assume that your object is complete while it is actually empty. A safer solution would be to use "myObj: Partial = {};" which tells typescript that every property of the object may be undefined.
Answer: Put a question (?) mark after makes variable.
  makes?: any[];
  vehicle = {};

  constructor(private makeService: MakeService) { }

It should now works.
I'm using angular 12 and it works on my code.
Answer: if you don't want to change your tsconfig.json, you can define your class like this:
class Address{
  street: string = ''
}

or, you may proceed like this as well:
class Address{
  street!: string
}

by adding an exclamation mark "!" after your variable name, Typescript will be sure that this variable is not null or undefined.
Answer: As of TypeScript 2.7.2, you are required to initialise a property in the constructor if it was not assigned to at the point of declaration.
If you are coming from Vue, you can try the following:

Add "strictPropertyInitialization": true to your tsconfig.json
If you are unhappy with disabling it you could also try this makes: any[] | undefined. Doing this requires that you access the properties with null check (?.) operator i.e. this.makes?.length
You could as well try makes!: any[];, this tells TS that the value will be assigned at runtime.
Answer: in tsconfig.json file , inside "compilerOptions" add :
"strictPropertyInitialization": false,

Answer: Get this error at the time of adding Node in my Angular project -

TSError: ? Unable to compile TypeScript:
(path)/base.api.ts:19:13 - error TS2564: Property 'apiRoot
Path' has no initializer and is not definitely assigned in the constructor.
private apiRootPath: string;

Solution -
Added "strictPropertyInitialization": false in 'compilerOptions' of tsconfig.json.
my package.json -
"dependencies": {
    ...
    "@angular/common": "~10.1.3",
    "@types/express": "^4.17.9",
    "express": "^4.17.1",
    ...
}

Ref URL - https://www.ryadel.com/en/ts2564-ts-property-has-no-initializer-typescript-error-fix-visual-studio-2017-vs2017/
Answer: When you upgrade  using firstname.lastname@example.com , its compiler strict the rules follows for array type declare inside the component class constructor.
For fix this issue either change the code where are declared in the code or avoid to compiler  to add property "strictPropertyInitialization": false in the "tsconfig.json" file  and run again npm start .
Angular web and mobile Application Development  you can go to www.jtechweb.in
Answer: a new version of typescript has introduced strick class Initialization, that is means by all of the properties in your class you need to initialize in the constructor body, or by a property initializer. check it in typescript doccumntation
to avoid this you can add (! or  ?) with property
make!: any[] or make? : any[]

otherwise, if  you wish to remove strick class checking permanently in your project
you can set strictPropertyInitialization": false in tsconfig.json file

"compilerOptions": {
....
"noImplicitReturns": false,
....
"strictPropertyInitialization": false
},
Comment: What is the difference between '!' and '?' ?
Comment: @pouyada the `!` is assertive assignment declaration saying that no matter what it is assigned even if typescript can't pick it up. `?` is optional meaning it may or may not be there but your component should be prepared for either case.
Answer: It is because typescript 2.7.2 included a strict class checking where all properties should be declared in constructor. So to work around that, just add an exclamation mark (!) like:
name!:string;

Answer: Can't you just use a Definite Assignment Assertion? (See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html#definite-assignment-assertions)
i.e. declaring the property as makes!: any[]; The ! assures typescript that there definitely will be a value at runtime.
Sorry I haven't tried this in angular but it worked great for me when I was having the exact same problem in React.
Comment: Working with all versions since it is in the official documentation and I tried it. THANKS!!
Answer: Another way to fix in the case when the variable must remain uninitialized (and it is dealt with at the run time) is to add undefined to the type (this is actually suggested by VC Code). Example:
@Input() availableData: HierarchyItem[] | undefined;
@Input() checkableSettings: CheckableSettings | undefined;

Depending on actual usage, this might lead to other issues, so I think the best approach is to initialize the properties whenever possible.
Comment: Writing `@Input() availableData: HierarchyItem[] | undefined;` is the same as writing `@Input() availableData?: HierarchyItem[]` ;)
Comment: Worked for me when initializing the @ViewChild variable.. see for reference: https://stackblitz.com/edit/ngx-flow-example?file=src%2Fapp%2Fapp.component.html
Answer: This has been discussed in Angular Github at https://github.com/angular/angular/issues/24571
I think this recommendation from angular gives good advice:

For angular components, use the following rules in deciding between:
a) adding initializer
b) make the field optional ?
c) leave the !

If the field is annotated with @input - Make the field optional b) or
add an initializer a).
If the input is required for the component user - add an assertion in ngOnInit and apply c).
If the field is annotated @ViewChild, @ContentChild  - Make the field optional b).
If the field is annotated with @ViewChildren or @ContentChildren - Add back '!' - c).
Fields that have an initializer, but it lives in ngOnInit. - Move the initializer to the constructor a).
Fields that have an initializer, but it lives in ngOnInit and cannot be moved because it depends on other @input fields - Add back '!' - c).
Answer: 1) You can apply it like the code below. When you do this, the system will not give an error.
"Definite Assignment Assertion" (!) to tell TypeScript that we know this value
Detail info
@Injectable()
export class Contact {
  public name !:string;
  public address!: Address;
  public digital!: Digital[];
  public phone!: Phone[];
}

2) The second method is to create a constructor and define values here.
export class Contact {
  public name :string;
  public address: Address;
  public digital: Digital[];
  public phone: Phone[];

  constructor( _name :string,
     _address: Address,
     _digital: Digital[],
     _phone: Phone[])
  {
    this.name=_name;
    this.address=_address;
    this.digital=_digital;
    this.phone=_phone;
  }
}

3) The third choice will be to create a get property and assign a value as follows
  export class Contact {
      public name :string="";
      public address: Address=this._address;

      get _address(): Address {
        return new Address();
      }

    }

Answer: In my case it works with different declaration according new typescript strict features:
@ViewChild(MatSort, {static: true}) sort!: MatSort;

If disable typescript new strict feature in tsonfig.json with
"compilerOptions": {
  ///
  ,
  "strictPropertyInitialization":false
}

the old Angular's guide code works well
@ViewChild(MatSort) sort: MatSort;

Here is 4 ways to solve the issue thanks to
Arunkumar Gudelli (2022) https://www.angularjswiki.com/angular/property-has-no-initializer-and-is-not-definitely-assigned-in-the-constructor/
Answer: Add these two line on the tsconfig.json
"noImplicitReturns": true,
"strictPropertyInitialization": false,

and make sure strict is set to true
Answer: JUST go to the tsconfig.ts and add
"strictPropertyInitialization": false, into the compilerOptions Object .

if it doesn't solve yet, kindly re-open your Code Editor.

EXAMPLE:
"compilerOptions" : {
  "strictPropertyInitialization": false,
}

Answer: change the
fieldname?: any[];

to this:
fieldname?: any;

Answer: You can declare property in constructor like this:
export class Test {
constructor(myText:string) {
this.myText= myText;
}

myText: string ;
}

Answer: A little late for the party. but the most voted answer includes changing the security level as a whole abandoning type safety, to work around this use the typing mechanism of the typescript itself
@ViewChild(MatPaginator) paginator: MatPaginator | undefined;

ngAfterViewInit() {
  this.dataSource.paginator = this.paginator as MatPaginator;
}

I believe the angular material documentation should be updated, but until then I believe this is the best way to do it
Answer: Follow 2 steps to solve this::

"strictPropertyInitialization": false entry in tsconfig.json
ctrl+c stop your server on Terminal(check for terminal, where it is running) and run it again with the command you use like ng serve
These 2 steps, should solve your issue.. as it solved mine.. cheers.. ;)
Answer: Instead of turning off the strict mode, you can assign a initial value to the variable.
For example:

makes: any[] = [null];

 private year: number = 0;
Answer: You can also add @ts-ignore to silence the compiler only for this case:
//@ts-ignore
makes: any[];

Answer: Comment the //"strict": true line in tsconfig.json file.
Comment: Need strict, also have the same issue. I am trying to include this will work other wise shows error
Answer: Just declare your variable as type any
@Input() headerName: any;

Answer: Next to variables  "?" You can fix it by putting it.
Example:
--------->id?:number
--------->name?:string


How to show a password-containing automated generated image, whose "content" is "copyable"?

Question: I'm responsible for a MediaWiki in my company. That Mediawiki contains information, like passwords. Currently those passwords are stored on the server, hosting the MediaWiki, but when a person surfs to that MediaWiki website, the traffic is not encoded (when I use a simple sniffer, I can read the passwords).
There are different approaches to such an issue:

I can turn the MediaWiki website, who is currently based on HTTP, to HTTPS. This is handled in this previous question, but it means that I need to reconfigure the MediaWiki website.
(This is a product of my imagination) I could use a "special component", who reads the password, turns it into an image and shows the image on screen. That "special component" allows the displayed text to be copied/pasted.
(For your information, a MediaWiki-page's URL looks as follows:
"http://<server-name>/wiki/index.php/<page_title>")
Simply said: turn "text" into  (and make it "copyable").

As for the second question: does such a "turn-text-into-an-image"-component exist and if yes, do I need to do something in order for my MediaWiki to use it?
Comment: This is simply not ***reasonable information technology management practices***. It's asking to store passwords in a tool totally unsuitable for storing credentials - and *using security through obscurity* to *secure* those passwords. It's about as bad as it gets.
Comment: I only bothered to answer to explain this is bad. Because this is how you can reach people. There could be no other answer than "don't do this, this is deeply wrong; do that".
Comment: And yet, don't store passwords in it. I understand your desire to store everything coherently, but passwords are sensitive information which absolutely require a specials treatment. Yes, when you design secure systems, you often split information to parts which have different requirements and store them differently, *this* is how things are done. Various FIPS standards require it, for example, and that's for a reason. So it is important enough to throw everything away. Heck, passing keepass database around is better than storing passwords in mediawiki.
Comment: Thanks for the quick reply, but I prefer not throwing everything away: the MediaWiki is a good way to store information, the passwords being a part of that information, so I prefer to keep working like this.
Comment: I see the point that putting passwords in a MediaWiki platform is bad, so there are some proposals to use "password storing and sharing tools", but can those tools be used for storing normal information too ((formatted) text, images, ...)? I mean, it's the idea to keep as much information together, instead of one tool for the explanations, one for the passwords, one for ...
Comment: Yep, you **must** use one tool for passwords and other sensitive information and another tool for everything not that sensitive. (That is if you have only two kinds of data; in some cases you need to use more systems with gradually stronger guarantees, like third tool which requires at least two people to unlock, for very secure information.) Your idea "to keep information together" is what is wrong here. Some information must not be kept together, no matter how strong the desire is. Or, find a password manager with wiki-like features, I hope it exists, and use it for everything.
Comment: There was a moment when I coined the idea to have a plugin for DokuWiki where we kept all the non-secure information, which will do password storage securely, but managed and searched together with the wiki. Boy, this happened to be *extremely hard* to do properly. I gave up.
Comment: Exactly. Therefore I would opt treating all information as sensitive (which, by the way it is). But then we get into a situation where a colleague needs to connect to a customer's system, clicks on something, answers some questions and the VPN gets set up and the RDP connection is used, both automatically. I bet this goes beyond the "password storing and sharing tools", which you have provided in your answer.
Comment: @NikitaKipriyanov: did you ever hear of ConnectWiseControl? It looks like a tool I might use for this purpose, but if it's as unsecure as a MediaWiki, it's not a good idea :-)
Answer: Simple.
Don't do that. Don't store passwords in a MediaWiki. Don't show them on screen. Don't think that rendering text as images makes it more secure.
There are a multitude of tools which are dedicated to storing and sharing password securely, with proper ACL controls, emergency push button to disable access to the database, secure entry into various forms, and so on. Use them:

Psono
Passwork
Passbolt

And so on, search for yourself.
Comment: You've got quite a bit to catch up on so good on you that you're actually moving in the right direction. It's easy to criticize, it's harder to change things that are rooted deep in people's habits
Comment: Let me explain you the idea behind it all: in my firm people sometimes need to connect to users' systems in order to work remotely on the customers' computers or PLCs. This happens through VPN connections, followed by RDP connections. Until now this is done, putting all information in a MediaWiki and I'm looking for another solution. I started my idea by replacing HTTP by HTTPS, then by transforming the passwords from text to images, but apparently it seems not to be good enough. Whatever solution I find, it must be very easily usable for my colleagues.
Comment: Educate your colleagues (and yourself) on security and how to do things properly. If they are unable to learn, fire them for incompetency. Unfortunately, secure things are often not so convenient and easy to use; that's the price you pay for the security. To manage an AD in our organization, for example, one has to use physical security token to authenticate. No way around. Not very convenient, but secure.
Comment: Pardon my lack of knowledge, but what's an AD?
Comment: Microsoft Active Directory. One can not became a domain admin and administer users, computers, policies, etc. without the token.
Comment: For your information: I'm now doing some first tests with the Remote Desktop Manager from Devolutions.net. I'm already able to open some RDP sessions without VPN, tomorrow I'll do some tests using VPN. If everything is working fine and if the DataSource (containing the sensitive information) is secured well enough, I might replace my MediaWiki by this tool. Thanks a lot for your support.
Comment: I don't know the tool but just looking at the homepage, I do hope you're talking about the Team Edition which includes RBAC and Audit. You absolutely cannot (continue to) manage systems, let alone client ones, without the bare minimum of security and accountability. If a client gets compromised (and more likely given the situation, if all your clients do) because of your company's poor security practices, you'd better have airtight contracts that relieve you of any and all responsibility.
Comment: @Ginnungagap: first I'm trying to make the tool work: it works quite easily with single remote connections and well-known VPN systems are ok. I've managed getting Pulse Secure to work, but now I'm in the middle of a Two-Step authentication. If all those things work, I'll have a look at the Team Edition, for the reasons you mentioned.


How can I show that $v_i\otimes v_j$ is non zero in $V \otimes_\mathbb {F}V$

Question: Let $V$ is a finite dimensional vector space over a field $\mathbb F.$ Let $\rm dim (V)=n>0$ and $\mathcal {B}=\{v_1,\ldots,v_n\}$ be a basis of $V.$ Now we know dimension of  $V \otimes_\mathbb {F}V$ is $n^2$ as $V \otimes_\mathbb {F}V \cong \mathbb {F^{n^2}}.$ Now since the set $\mathcal {A}=\{v_i\otimes v_j:1 \leq i,j\leq n\}$ spans  $V \otimes_\mathbb {F}V$ and the number of elements in $\mathcal {A}$ is $n^2$, $\mathcal {A}$ forms a basis for  $V \otimes_\mathbb {F}V$ as a vector space over $\mathbb F.$ In this way every element in $\mathcal {A}$ is non zero.

Now my question is if I don't want to use the above arguments how can I show that for any $i$ and $j$ the element  $v_i\otimes v_j$ is non zero in  $V \otimes_\mathbb {F}V$. By the construction of tensor product if it can be shown then it will help me.

Help me. Many Thanks.
Answer: Whatever your definition of tensor is, it should be true that any bilinear function
$$
V\times V\longrightarrow \mathbb{F}
$$
must factor uniquely through
$$
V\times V\longrightarrow V\otimes_\mathbb{F} V\longrightarrow \mathbb{F}
$$
Now take any linear functional $\ell :V\to\mathbb{F}$ such that $\ell(v_i)\neq0 $ and $\ell(v_j)\neq 0$. Define a bilinear function $f:V\times V\to \mathbb{F}$ as
$$
f(u,v) = \ell(u)\ell(v)
$$
Since $f$ is clearly bilinear, $f$ must factor through a homomorphism $g:V\otimes_\mathbb{F} V\to \mathbb{F}$, i.e. $g(u\otimes v) = f(u,v)$.
Since $g(v_i\otimes v_j) = f(v_i,v_j) = \ell(v_i)\ell(v_j)\neq 0$, $v_i\otimes v_j$ is nonzero.
Comment: you were faster :)
Comment: Thank you for writing in details.
Answer: If $(v_i,v_j)$ are non-zero there is a bilinear application $\beta : V \times V \to k$ with $\beta(v_i,v_j) = 1$ and by the universal property of tensor product we get a map $b : V \otimes V \to k $ with $b(v_i \otimes v_j) = 1$ so it cannot be zero.


commutes with a nilpotent matrix and invertible

Question: The exercise is:

Given $V$ a vector space, $\dim V<\infty$ and $T, N\in \mathcal{L}(V)$, where $N$ is nilpotent and $TN=NT$. Prove that: $T$ is invertible iff $T+N$ is invertible. Furthermore, $\det(T)=\det(T+N)$ and $p_T(t)=p_{T+N}(t)$.

I need a hint about how can I start this kind of exercise, which involves a nilpotent matrix.
Comment: Try an example, $$ N = \left( \begin{array}{cc} 0 & 1 \\ 0 & 0 \end{array} \right) $$  along with $$ T = \left( \begin{array}{cc} a & b \\ c & d \end{array} \right). $$ In order to have $TN = NT,$ what are the conditions on $a,b,c,d?$ Then, what happens tothe requested determinants, and, I am guessing, the characteristic polynomials?
Answer: Hint: Note that $N$ and $T$ are simultaneously upper triangularizable.
Answer: For a rather different approach one can directly prove $p_T(t)=p_{T+N}(t)$ which then gives you the equality of determinants and in turn the equivalence of invertibility.  I assume $\dim V = m$ and assume the field has characterisitic zero (or if one wants to contemplate positive characteristic fields, then $\text{char}(\mathbb F)\gt m$)
lemma 1:
by nilpotence, $N^m = \mathbf 0$ and with commutativity this means you can apply the binomial theorem, so $\big(T+N\big)^j= T^j +\Big(\sum_{k=1}^{j-1} \binom{j}{k}T^kN^{j-k}\Big) + N^j$
lemma 2:
$T^k N^r$ for $r\geq 1$ is nilpotent, because
$(T^k N^r)^m =  T^{km} N^{rm}=  T^{km}\mathbf 0 = \mathbf 0$
and recall that since nilpotent matrices are similar to strictly upper triangular matrices, they necessarily have trace zero
main argument:
$\text{trace}\Big(T+N\Big)= \text{trace}\Big(T\Big)+\text{trace}\Big(N\Big)= \text{trace}\Big(T\big) + 0 $
and for $j\in\big\{1,2,...,m\big\}$
$\text{trace}\Big(\big(T+N\big)^j\Big)= \text{trace}\Big(T^j\Big) + \sum_{k=0}^{j-1} \binom{j}{k}\cdot\text{trace}\Big(T^kN^{j-k}\Big)= \text{trace}\Big(T^j\Big) + 0$
Thus by application of Newton's Identities $\Big(T+N\Big)$ and  $\Big(T\Big)$ have the same characteristic polynomial.
Comment: Thanks! I agreed! Can you help me with the other itemize? I proved the first implication: det(T+N)=det(T+T−1TN)=det(T)det(Id+T−1N)≠0, because 1 can not be a eigenvalue of T−1N who is nilpotent. How can i do the other implication?
Comment: the characteristic polynomials agree, so evaluate them at zero and get $(-1)^m \det\Big(T\Big)  = \det\Big(0I - \big(T\big)\Big) =p_T(0) = p_{T+N}(0) = \det\Big(0I - \big(T+N\big)\Big) = (-1)^m \det\Big(T+N\Big)$.  Now multiply each side by $(-1)^m$.
Comment: What are the Newton's identities and how are you using that to conclude that  $\Big(T+N\Big)$ and  $\Big(T\Big)$ have the same characteristic polynomial? Thanks!
Answer: It suffices to prove that $T$ and $T+N$ have the same characteristic polynomial. The other two results follow immediately.
I shall give a proof that does not involve triangulation of $T$, because an attendee of a first course on linear algebra usually has not seen any proof of the existence of algebraic closure of an arbitrary field from any course.
Let $F$ be the underlying field and $x$ be an indeterminate. Denote by $F(x)$ be the field of fractions of $F[x]$. For ease of presentation we assume that $T$ and $N$ are matrices over $F$.
Since $\det(xI-T)$ is a monic polynomial in $x$, it is nonzero. Therefore $xI-T$ is invertible over $F(x)$. Then $(xI-T)^{-1}$ commutes with $N$. Hence $N_1=(xI-T)^{-1}N$ is nilpotent and it can be triangularised over $F(x)$ (we do not need $F(x)$ to be algebraically closed here because $0\in F(x)$). Therefore $\det(I-N_1)=1$ and in turn $\det(xI-T-N)=\det(xI-T)$.
Comment: out of curiosity, can you adapt this technique to solve https://math.stackexchange.com/questions/4849941/reduction-of-matrix-nilpotence/ ?  $\ker N$ being a $T$-invariant subspace yields an identical proof to each but I have a lingering curiosity about porting proofs from here to there
Comment: @user8675309 Done, but I think your invariant subspace argument provides a better explanation. Before reading your answer to the linked question, I wasn't aware that "$N$ is nilpotent and $NA=0$" implies that $N$ and $A$ are simultaneously triangularisable.
Comment: Thanks.  I share your concern of people not knowing about algebraic closure, so I went for simultaneous block triangulation.  It is interesting that we can port a variety of techniques from this problem to that one.


Grouping Content by Date in Views

Question: I'm trying to group content by date in views but instead of utilizing 'Fields' to stylize it, I'm trying to style using 'Content'
Here is an example of what I see right now:

Note Post Title

  This is a test comment 1
  John Doe
  Posted Date October 7, 2013 - 11:15 AM

  This is a test comment 2
  John Appleseed
  Posted Date October 7, 2013 - 11:20 AM

Here is what I'm trying to achieve:

October 7, 2013

   Note Post Title 1
     This is a test comment 1
     John Doe
     11:15 AM

     This is a test comment 2
     John Appleseed
     11:20 AM
Answer: For grouping the content by date field, you may try the following:

Add one extra date field in the fields section. (This field will be used for grouping)
In Format -> settings, select that date  field for grouping
Comment: Ankit, thanks for the reply but I'm attempting to do grouping with using Format -> Show -> Content http://oi40.tinypic.com/5yemv6.jpg
Comment: @ApurvParikh One another way to do from UI is using the `aggregation`, enable the aggregation and than in the fields settings select group together
Comment: I'm not using fields, need a way to do grouping with format -> content
Comment: Why don't you want to use fields?

Grouping Content by Date in Views


Is there a way i can draw a transparent WPF application over the desktop at all times?

Question: Is there a way to make an WPF application persist on top of the desktop when one uses the show desktop shortcut (WINDOWS+D) on windows?
I am trying to make an desktop overlay application with widgets. (Same concept as rainmeter) I currently am using functions in user32.dll to keep the window positioned on top of the desktop.
This works perfectly fine until i use WINDOWS+D
I've tried:

On the window Deactivated event, inserting the window's position above the Desktops position
Parenting the window to the desktop

Any suggestions would be greatly appreciated!
Comment: What is CTRL+D supposed to do, and what is it doing in your particular case?
Comment: I believe you mean "WINDOWS + D" and not CTRL.
Comment: @theMayer Show desktop, Edited it
Comment: @theMayer oh god, yes you're right my bad!
Answer: One (possibly dirty) way would be to register a hotkey to capture a WIN+D call as suggested in this answer: https://stackoverflow.com/a/824395/12167858
Once you have a way to capture the hotkey you can find out whether or not its trigger-event fires before or after the native WIN+D response (showing the desktop).
I did not test this myself just yet, however, if it does fire after the native response, you're good to go. Otherwise, if such a solution would be acceptable, you could use a Task.Delay() to wait for Windows to finish minimizing all visible windows.
/edit: I forgot the critical part: Once you have ensured that Windows is done doing its things, call the code below (as suggested here: https://stackoverflow.com/a/6837421/12167858) to get the window back to its original state:
if (myWindow.WindowState == WindowState.Minimized)
myWindow.WindowState = WindowState.Normal;

Comment: Hello! Thanks for replying I have managed to get global hotkey capturing working for windows+d. When i execute the code you have provided nothing happens. The window state was and stays `WindowState.Normal` before and after the execution of the windows + d shortcut. It seems that the Z-Index of the desktop gets increased to hide all other windows.


Is it worthwhile to use LASSO for variable selection even if it is cumbersome?

Question: My goal is to understand which variables out of 10 actually explain my dependent variable for a voter/election research.
Now I have put all 10 variables into a multiple regression and have filtered out all that have p value over 0.1. Now I have a model with 3 variables, all p values at 0.014 or far below and r=0.8.
It seems all fine.
Can't I just use this model? Or do I absolutely have to use lasso? Because I have tried to bring lasso to work for hours now. I can't do it (only experienced in excel). It's really frustrating all the errors R throws at me. If I have to use lasso, how can I do this the easiest? Is there any way to do LASSO or something similar with excel?
Comment: "do I absolutely have to use lasso?" no, and I'm sure we're all wondering where on earth you got this idea :) May be worth checking out this Wikipedia page which lists some variable selection methods (only some of which are lasso ;) https://en.wikipedia.org/wiki/Feature_selection)
Comment: In comments the OP clarifies that they are interested in "understand(ing) real world relationships. (...) I think they are layered effects. Like x1 and x2 directly influence Y, but x1 itself is influenced by x4 and x7." The language of "direct influence" suggests that you really want to do is causal inference. If that's the case, feature selection is basically irrelevant and in fact you cannot build the causal graph from the data. Instead, you could use the prior domain knowledge to construct the causal graph and start from there.
Comment: There are many CV threads that might be of interest. For example: [Causal Inference After Feature Selection](https://stats.stackexchange.com/q/502082/237901) and [A more definitive discussion of variable selection](https://stats.stackexchange.com/q/223808/237901).
Comment: What is your sample size?
Comment: @christian My sample size (number of observations) is 110 and as more data is coming in, it will be 250.
Comment: 250 is an OK number for 10 variables. 110 is maybe a bit on the low side, but probably still not low enough that I'd say you have to do any variable selection (see my answer).
Comment: ok thanks! and merry christmas!
Comment: @CrossVal_Asker I have edited your title, if you don't mind.
Answer: Variable selection is not compulsory. The idea that you have to throw away variables is wrong. Actually, unless there are strong reasons to throw away variables, don't do it! Use the full model and use the p-values to guide interpretation rather than throwing away information. An insignificant p-value doesn't mean that a variable should be removed, it only means that the data don't give you clear evidence that the coefficient is nonzero.
The Lasso mitigates some of the issues of doing variable selection by p-values, but as long as you don't feel the need to remove information, there's no need to do it, neither by Lasso.
Good reasons for selecting variables are:

The number of observations is critically low for the number of variables you have.

There are strong dependencies between your variables ($X^TX$ is close to singular) and certain information is represented by several variables

The model is used to predict future observations and you are happy to get rid of some variables because it may be costly to observe them in the future.

Using cross-validation and the like you find that a model with fewer variables predicts better (if this happens, mostly one of 1 and 2 is also in place, but there are some further situations in which the original set of variables contains a lot of noise).

Variable selection is not required for interpretation! Note that even if there is no evidence (high p-value) that a certain variable has a nonzero coefficient, this variable may still improve the predictive power of the model. Removing the variable will set its coefficient to zero - don't forget that the estimator for it's coefficient in the full model is the "best guess" of the coefficient value that you have, significant or not, and therefore also better than zero in the sense of least squares.
By the way, regarding Lasso vs. variable selection by p-values (backward/forward/stepwise selection - never throw away all variables with large p-values in one go anyway): There are well known issues with variable selection by p-values and Lasso is often better, but not always. I've seen a good number of examples in which a model selected by backward or forward selection did better predicting on independent data than the Lasso. If you have enough observations to properly assess prediction quality using cross-validation and the like, you can compare different approaches and pick the best rather than always using Lasso.
Comment: Thanks for your thorough answer and Merry Christmas!
I think I may have phrased the question not precicely enough. Yes my goal is to understand real world relationships. More precisely: I think the independent variables are not just correlated by chance. I think they are layered effects. Like x1 and x2 directly influence Y, but x1 itself is influenced by x4 and x7. I think that's the case because all independend variables are correlated and because of prior theoretic research.  That's why I did the stepwise. Do you know what to Google to get help with that problem?
Comment: @CrossVal_Asker I don't think variable selection will help with your problem. You may rather be interested in causal inference using graphical models.
Answer:
My goal is to understand which variables out of 10 actually explain my dependent variable for a voter/election research.

This is not variable selection!
With variable selection the goal is to reduce the size of a model

Such that it is easier to work with, like less computation intensive or requires less future efforts in sampling.
Such that it is less sensitive to noise. See 'bias variance' tradeoff.

Your goal is to understand a relationship. This can be done by making a plot and observe a straight line (or in the case of more variables the line is a plane and you look at statistics in a table instead of a figure because plotting 10-D is not easy in our 3-D physical world).
The role of the p-values is to filter the effects from the noise (like you would do in the 2-D, plot to tell if there is a straight line relationship, or just noise). The p-values indicate statistical significance. That means that you have observed an effect that is statistically measurable with your experiment. The other effects, with high p-value, might be present but are overshadowed by noise.
So in your case it seems fine to go with p-values. However, be aware of the pitfalls with p-values.
Comment: Many Thanks for your thorough answer :)! So "variable selection" and "understanding real world relationships in the model are two different fields, correct?

If yes, we are coming closer to the heart of the problem:
Yes my goal is to understand relationships. More precisely: I think the independent variables are not just correlated by chance. I think they are layered effects. Like x1 and x2 directly influence Y, but x1 itself is influenced by x4 and x7. That's why I did the stepwise. Do you know what to Google to get help with that problem?
Answer: If its only the Feature Importance Aspect you are looking for , you can use RFE Method (Recursive Feature Elimination) as well.
But Lasso Regression takes care of Model not reaching Overfit or Underfit Situations as well as Feature Importance, by reducing all the Useless Features to Zero.
You can use Lasso Regression using GridSearchCV method, and then plot your Mean Train and Mean Test Errors accordingly, if you have different values of Regularization Parameters available. And for the best values of Errors, you can consider the value for the Regularization Parameter and fit your model with Train Data.
Answer: For any others that might be interested in the answer:
I managed to do the LASSO with an excel plugin into excel 365.
It did show significantly different results in comparison to stepwise.
Also, I found out that I actually want to build a causal model not a variable selection. (different terminology).
So yes LASSO seems to be worth the work.


MySQL - SELECT * plus another field syntax

Question: With MySQL, I seem to be able to do something like this:
SELECT *, name
FROM Customers

But I get a syntax error if I reverse the order:
SELECT name, *
FROM Customers

I have tried giving the name an alias and that doesn't help. I know I could do this with a join on the same table, but I'm hoping that there is a simple syntax that will allow this to work without a self-join. Is this possible with another syntax or am I stuck with only being able to add additional query result fields after instead of before selecting all with an asterisk (*)?
Comment: "All columns" pattern allows to select additional columns/expressions. But it cannot be an addition. *but I'm hoping that there is a simple syntax that will allow this to work without a self-join* Do not use asterisk, list all column names one-by-one.
Answer: In general, it is a good idea to qualify all column references -- even *.
So, this works in either order:
select name, c.*
from Customers c;

Or better yet:
select c.name as new_name, c.*
from Customers c;

Note:  You should probably give name as different alias so there are not duplicate column names.
The one exception is when you are using the USING clause for a JOIN.  Then * makes sense.  When using * with USING, the JOIN key are not repeated in the SELECT columns.
Comment: You can reference the [documentation](https://stackoverflow.com/questions/3022934/how-do-i-get-the-executing-programs-directory-in-c-using-a-plataform-independen): **Use of an unqualified `*` with other items in the select list may produce a parse error. To avoid this problem, use a qualified `tbl_name.*` reference**
Comment: *The one exception is when you are using the `USING` clause for a `JOIN`. Then `*` makes sense.* Can you explain this phrase in details? why so? it looks strange..
Comment: @Akina In `USING` you just list columns that are common to both tables in the join, so it doesn't make sense to qualify them with table prefixes. `USING (x)` is equivalent to `ON tbl1.x = tbl2.x`
Comment: @Barmar You are wrong. Test `SELECT col, t1.col, t2.col FROM t1 LEFT JOIN t2 USING (col);`, or RIGHT JOIN. You'll see that qualified `tablename.name` is critical. The same about asterisk - without qualification you cannot distinguish does this output row has source parts in both tables or in left table only.
Comment: OUTER JOIN is an exception because the column can have different values when there's no match.
Answer: MySQL tends to be more lenient that other relational database engines, but even that isn't something I'd rely on. From docs (emphasis mine):

Use of an unqualified * with other items in the select list may produce a parse error. To avoid this problem, use a qualified tbl_name.* reference

The reliable and portable alternative would be:
SELECT name, Customers.*
FROM Customers


How to upgrade an RDS SQL Server Instance to an SSD

Question: I'm trying to upgrade my RDS SQL Server 2012 instance from magnetic storage to an SSD.  It is an instance class of db.m1.large with bring your own license.

I've tried modifying the storage type, but you can't do that with SQL Server instances.
I've tried restoring a snapshot of my instance to a new SSD instance.  That is not allowed either because it says the storage types are different.
That leaves me with only one option that I can see.  That is to create a new SSD instance, create my database structure on the new server, and then do a data transfer using one of the export/import methods for SQL server.

My question is, are there better ways to do this?  It seems like this is way to difficult for the benefits I get using RDS.
A follow up question is should I just move this to an EC2 instance, and be done with RDS so I don't have this problem again.
Answer: In the documentation for Modifying a DB Instance to Use a Different Storage Type there is the following note:

You cannot modify an existing SQL Server DB instance to change storage type or modify storage allocation.

And as you say, you can't restore a snapshot into another storage type.
I think your best option is your number 3. Export your database, and then import it on your new RDS instance.
Leaving RDS for a self hosted variant in EC2 seems a bit drastic since changing storage type isn't really something you do every day, my guess is that this is your first and last time that you do it. The features that comes out of the box with RDS are simply too overwhelming for changing to a self hosted solution, in my opinion at least.
Answer: I realize this question is 2.5 years old. But here is our process:
As mentioned you cant upgrade SQL Server "in-place" with the automagical AWS interface. BUT...You can restore a Snapshot to a new Instance thats created with the new storage type.
Say your instance is called XYZ...make sure you have a snapshot of XYZ. Delete XYZ. Create a new Instance called XYZ with the new storage type. Restore the snapshot of XYZ to the new instance. Apply security group to new instance. Now you can enable multi-AZ mirroring or whatever.
Questions about cross-storage snapshot restores..this page has the comment:
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RestoreFromSnapshot.html
You can restore a DB instance and use a different storage type than the source DB snapshot. In this case, the restoration process is slower because of the additional work required to migrate the data to the new storage type. In the case of restoring to or from Magnetic (Standard) storage, the migration process is the slowest because Magnetic storage does not have the IOPS capability of Provisioned IOPS or General Purpose (SSD) storage.
Comment: I realize your answer is almost 2 years old ;) but do you create the new instance and then restore to it, or just restore from a snapshot to create a new instance?  I ask because I'm testing the process (and so not deleting the original XYZ) but when just restoring the snapshot to an uncreated instance the Console keeps jumping to the warning about "changing types will take longer" and won't continue.


MyUpdatePanel.Update() in Razor

Question: I am trying to convert my existing ASP.NET application to MVC 3 Razor. I use a lot of updatepanels, and I do conditional updates at the code behind using MyUpdatePanel.Update().
I am not finding this functionality with MVC 3. I can see a lot of blogposts talking about jQuery and how to use it to achieve the same, but I want to render other partialviews from my action conditionally. Is it possible to achieve it?
Comment: There is no code-behind in ASP.NET MVC. I can recommend the [ASP.NET MVC tutorials](http://www.asp.net/mvc), especially the introduction, to help you convert your web site.
Answer: The way you'd work with Ajax in ASP.NET MVC is completely different from the ASP.NET way (i.e., Ajax toolkit with server-side controls such as UpdatePanel).
ASP.NET MVC is more basic and therefore more work. You handle Ajax calls on the client side using a library such as jQuery, and on the server side you implement a controller with Ajax methods.
Have a look at http://sweettam.blogspot.com/2011/06/aspnet-mvc-3-ajax-part-i.html.

MyUpdatePanel.Update() in Razor


Finding interactions using randomForest

Question: I am trying to use randomForest in R to find interaction terms to add to a model.  My plan was to fit trees with maxnodes=4 (two deep stubs), then compute how often var A is a child of var B and its improved accuracy to measure the importance of the A*B interaction.  Essentially this is leveraging randomForest for the sampling.
To make this work I also wanted mtry=# variables, so all variables would have a chance at being the child of the root variable.
This strategy failed in my data because all trees after the first few were identical. I did decrease cp, but that did not help.  I removed mtry=#vars, and still got all 95% of  trees the same (the last 95%, the first few are different).
When maxnodes=32, I got a good set of trees, but that's not what I needed for determining interactions.  I need to do this because I can't deploy a randomForest in production.
Any ideas why this wouldn't work?  I am coding this myself now using rpart on 2 variable models iterating over the potential good pairs.
Comment: What class are your variables? For example, if these are factor (categorical) variables, is there any reason why you wouldn't simply concatenate the two variable into a new variable and add your new variable to the decision tree input? If they're numeric you could add/multiply/whatever to create a new variable, then add that as input. . .  adding extraneous info to a random forest should be ok.
Comment: @SoccerGeek If you feel Ryan Bressier post below answered your question, please mark it as 'accepted' by clicking the green check mark. If not, please add a comment to clarify. Thanks in advance.
Answer: You may actually want a really low value of mTry. Setting this equal to a high value or #vars means that you are evaluating every variable as a potential splitter at each node and will result in more deterministic behavior like you are seeing because the best splitter will always be chosen. This phenomena is known as "masking" with regards to importance scores. A lower value of mTry will randomize things more and increase the diversity of the trees. Another way to increase the randomness would be to decrease the number of samples bagged for each tree.
(Note: some implementations use an algorithm that insists on examining at least one non constant variable per node even if they have to examine more then mtry features.  This usually increases accuracy but makes them less sensitive to choice of mTry and can result in more deterministic trees. I'm considering making it optional in my implementation.)
Some work on variable importance including this paper "Understanding variable importances in forests of randomized trees" has suggested that more randomization is good going so fat as to use Extra-Trees. As the splits and splitter become more randomized you would need to incorporate impurity decrease in such an analysis.
The first few trees being the only unique ones sounds like a bug unless the trees are somehow sorted. It is quite possible that there are only a few different trees but the growth of each tree should be independent.
I've done a bit of this sort of analysis and found it useful and interesting in highly dimensional datasets. I'm not sure I would call the results interactions as the two variables could conceivably be entirely independent except in how they relate to the target variable. I'm no sure if there is a terminology widely used in the literature but I think of the downstream variable as having increased local importance on that side of the split (and likely decreased importance on the other).
We also often run random forests to predict every variable in the data set and use importance scores to pick up on non linear relationships between variables not related to a specific target.
Comment: the link to the paper is broken. can you update the link or give the title to the paper? thanks
Comment: Done. The title is "Understanding variable importances
in forests of randomized trees" incase the edit doesn't show up right away.
Answer: Just for clarity, setting mtry=nvar means that you're Bagging trees, and no longer using Random Forests.
Also, both Bagging and RF should be used with very deep trees (in the original version, fully grown unpruned trees), so requesting 4 terminal nodes does not really make sense.

To make this work I also wanted mtry=# variables, so all variables would have a chance at being the child of the root variable.

If you want to give all variables a chance to play a role in tree structure, you want to set a rather low value of mtry. Otherwise, from the way the CART algorithm works, the splits of all trees will be made on the exact same variables (this is even more true if your trees are shallow). In Bagging trees, the extreme case where mtry=nvar, a major issue is that all trees resemble each other so much that their predictions are very correlated. This is for this very reason that Breiman introduced Random Forests.

Finding interactions using randomForest


How to deal with data having huge disparity in number in each class

Question: I have data in which the number of negative cases in response is approximately 98% of the total sample size (total # records are approximately 1 million, Response is binary). The positive cases are roughly 2%. What are the limitations of applying 'glm' and 'cart'  on such data? What option do I have in such cases?
On test data I did get a very good AUC ~0.92. How much faith should I have in this model considering such a disparity in the number of cases in the positive and negative categories?
Comment: what was the sample size of positive cases?
Comment: Are you and [learner](http://stats.stackexchange.com/users/31017/learner) the same person?
Comment: So, please, consider [merging your two accounts](http://stats.stackexchange.com/help/merging-accounts) /cc @mbq.
Comment: Actually I posted my comment when I was in my office where i use my office email. Right now i used my personal computer at home which by default used my personal mail. But thanks for suggestion. I would consider merging these accounts
Answer: Is this a binary response variable?
One limitation of models with very small (or large) rates is the amount of data needed to get accurate and stable estimates of variance and sample errors. As a rule of thumb you would want both Np = 5 and N(1-p) = 5 (or higher), so with an estimated p of 0.02 you need N of 250.  So in order to get accurate sample errors etc you want a minimum 250 observations.
Comment: thanks, yes it does. Does it matter if the response is continuous
Comment: This is not correct, David. Precision of the estimator does not depend on variability in the dependant variable, only the independent variable.
Answer: For logistic regression there's no problem with imbalanced samples per se, though if the absolute number in either response class is small for separate covariate patterns the maximum-likelihood estimators of odds ratios can be rather too biased for comfort, and some prefer to used penalized-likelihood methods as discussed here. For larger models computational constraints might necessitate down-sampling the most common class, which reduces the precision of all estimates somewhat but otherwise only affects the intercept (an estimate of which for the original population can be recovered —see here). In your case a minority class numbering 20k shouldn't give cause for concern unless you're trying to estimate odds ratios for some very rare predictor categories.
For classification trees there's what seems to be a good answer here.


updating cURL on Heroku

Question: I am trying to figure out how to update the version of cURL on Heroku, but am very new to Heroku and entire buildpack system.  Does anyone know how I could update just the cURL utility?
Thanks
Answer: You can see which packages are installed on Heroku's Ubuntu Packages on Cedar and Cedar-14 page. It looks like Cedar has curl 7.19.7-1ubuntu1.11 and cedar-14 has 7.35.0-1ubuntu2.5.
If your app is running cedar and you want the 7.35.0 on cedar-14, run heroku stack:set cedar-14 to upgrade. If you want a version > 7.35.0, you could try deploying the curl binary in a /bin folder within your repository and accessing that directly.

updating cURL on Heroku


How do I put a reset button on my view's exposed filters?

Question: This a really basic question, but it stumped me for a moment and there was little I could find on the net that answered this most basic need.
By default when you expose filters in a view, the only button that shows is 'Apply'.  I have seen reset buttons elsewhere on the site and on example sites but I don't know how to make it appear on my view.
How do I put a 'Reset' button on my view to reset the exposed filters?
Answer:
In your view configuration go to Advanced -> EXPOSED FORM -> Exposed form style: Basic | settings.

Check 'Include reset button' and save.


Como filtrar linhas em que as colunas cumprem condições consecutivamente no Python?

Question: Estou a tentar filtrar linhas em que as colunas cumpram condições consecutivamente.
Isto é, se a linha tiver colunas com as condições de após um L/I, a coluna seguinte tenha um A/S, então que retorne o valor de 1 na nova coluna(caso não se verifique, retorne 0)
Input:
       RFA RFB RFC RFD
    0   S   S   S   S
    1   A   I   A   A
    2   A   A   L   A
    4   S   S   L   A

Output:
       RFA RFB RFC RFD  promo
    0   S   S   S   S     0
    1   A   I   A   A     1
    2   A   A   L   A     1
    4   S   S   L   A     1

Script:
      def promo_behaviour(x):
          for i in range(0,95411):
             for j in data_rfa_r.columns:
                 if (x[j][i] == 'L' or x[j][i] == 'I') and (x[j][i+1] == 'A' or x[j][i+1] == 'S'):
                    return 1
                 else:
                    return 0
      data_rfa_r['promo'] = data_rfa_r.apply(promo_behaviour)

Escrevi esta função mas sem sucesso (95411 são o número de observações/linhas).
Esqueci de referir que no contexto do problema, a coluna de index 0 é a mais recente! Ou seja, deve ser lido da direita para a esquerda.
EDIT:
Output:

       RFA promo2 RFB promo1 RFC RFD
    0   S    0    S     0     S   S
    1   A    1    I     0     A   A
    2   A    0    A     1     L   A
    4   S    0    S     0     L   A

Comment: Boa tarde! Na base de dados real não! mas são mais de 25 variaveis( --> 25 colunas)...
Answer: Você pode utilizar o isin, criando uma lista de possíveis combinações.
vl = ['LA','IA','LS','IS']
dados['promo'] = (dados.shift(axis = 1) + dados).isin(vl).any(axis = 1).astype(int)

dados.shift 'move' o data frame
isin verifica a ocorrência dentro da lista
any verifica se existe ocorrência de True nas linhas
astype(int) retorna 0 ou 1 no lugar de True ou False
Answer: Solução em uma linha:
df['promo']=pd.Series([bool(re.search(r'(L|I)(?=[AS])',k)) for k in df.sum(axis=1)])

Minha ideia foi transformar as colunas em uma única coluna com a concatenação das outras colunas. Nessa nova coluna, apliquei o teste lógico usando regex. Usei positive lookbehind para verificar se existe um A ou S depois que vi um I ou L. Código inteiro:
import pandas as pd
import numpy as np
import re

df=pd.read_csv("stack.txt",sep=",")

df['promo']=pd.Series([bool(re.search(r'(L|I)(?=[AS])',k)) for k in df.sum(axis=1)]).map({True:1, False:0})

print(df)

Retorna:
  RFA RFB RFC RFD  promo
0   S   S   S   S      0
1   A   I   A   A      1
2   A   A   L   A      1
3   S   S   L   A      1

Comment: Após resolver denominar os null por outra letra...funcionou certinho com um tempo muito melhor! Já agora, por acaso sabe se dá para colocar a coluna promo quando se verifica  condição? Isto é, na promoção que fez ir o L para o A...vou colocar um edit!
Comment: Apesar de achar que não vai funcionar no meu caso particular por causa de  missing values(null), acho que estaria completamente correcto!
Comment: bom, acho que basta substituir o NULL por qualquer string que não seja A,S,L ou I, não?
Comment: Numa outra situação seria, mas neste caso os null values são importantes pois na verdade não são null values(são simplesmente momentos em que o cliente ainda não era socio para ter acesso à promoção) Mas substituindo deve funcionar com certeza! Vou experimentar e caso funcione, colocarei como correcta também! Muito Obrigado!
Comment: Ok. Evite o nested for loop pq é um algoritmo O(n^2) e, portanto, extremamente ineficiente.
Comment: Seguirei o seu conselho! Apesar da amostra serem só 100k mas mesmo assim, compensa sempre!
Comment: Talvez seja o caso de abrir outra pergunta
Comment: Ok! Era só para evitar abrir outro tópico!


TypeError: unhashable type: 'list' in python nltk

Question: I have this code:
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
from nltk.stem import PorterStemmer
import re

fo = open('cran.all.1400', 'r+')
contents = fo.read()
docs = re.split(r'\.I[\s][\d]*')

stop_words = set(stopwords.words('english'))

tokens = []
for each in docs:
    tokens.append(word_tokenize(eac))

s_words = [w for w in tokens if not w in stop_words]
print(s_words)

When I try to run it, I get this error:

how can I solve this?
Comment: Please, don't post text (code and error messages) as images. It makes it difficult to help you
Comment: The elements of `tokens`, which you are calling `each` are apparently lists and since `stop_words` is a set, they must be (but lists are not) hashable.
Answer: It appears that your variable each is a list, and you try to look if the latter belongs to a set. The in operator needs that each is hashable in order to search for it in the set.
Answer: Not sure if it's related, but I'm thinking you mean [w for w in tokens if w not in stop_words]
tokens.append(word_tokenize(each)) <-- that is likely giving you a 2d array.  So each is a list.  Perhaps you're expecting this to be a 1 dimensional list, in which case you could use tokens.concat(word_tokenize(each))


ReactJS: show modal with loading message during superagent ajax request

Question: I'm having trouble showing a modal dialog with loading message during ajax request(with superagent).
I have a reactjs app that has a single input field, a button, and a modal region. I want it to work like so...

A user inserts a keyword into the input field and clicks on the button.
Once the button has been clicked, an ajax call is made to scrape information from a certain website using the keyword.
During the ajax call, a modal dialog that shows a loading message appears.
Once the the ajax call is over, the modal dialog is closed and a list of information that has been scraped will be listed under the input field.

I can't seem to get 3. to work.
Here's what I have:
I tried putting in a method that changes the props of the modal component before and after the ajax call that didn't work.
Any help is appreciated!
app.js
import React from 'react'
import ReactDOM from 'react-dom'
import PageBody from './pageBody'

ReactDOM.render(
     <PageBody />
    ,document.getElementById('root')
)

pageBody.js
import React, {Component} from 'react'
import Search from './Search'
import Modal from './modal'

export default class PageBody extends Component{
    constructor (props){
        super(props)
        this.state = {
             is_crawling: false
        }
    }

    crawlState (is_crawling) {
        this.setState({is_crawling: is_crawling})
    }

    render () {
        const show_modal = this.state.is_crawling
        this.crawlState = this.crawlState.bind(this)

        return (

                <Search crawlState={this.crawlState}/>
                <Modal show_modal={show_modal}/>

        )
    }
}

search.js
import React, {Component} from 'react'
import request from 'superagent'

export default class Search extends Component{
    constructor (props) {
        super(props)
        this.state = {
            keyword: ''
            ,result: []
        }
    }

    // method used to make ajax request
    crawl (){
        const keyword = this.state.keyword
        this.props.crawlState(true) // set crawlstate as true to show modal
        request // actual ajax request (superagent)
            .get('/crawl')
            .query({keyword: keyword})
            .end((err, res) => {
                if (err) console.log('superagent failed')
                const r = res.body.result
                this.setState({result: r})
            })
        this.props.crawlState(false) // set crawlstate as false to hide modal
    }

    onChangeHandler (e) {
        this.setState({keyword: e.target.value})
    }

    render () {
        const onChangeHandler = e => this.onChangeHandler(e)
        const crawl = this.crawl()
        const keyword = this.state.keyword
        const arr = this.state.result.map((e, idx) => {
            return
{e}

        })

        return (

                <input type="text" onChange={onChangeHandler} value={keyword} />
                <button onClick={crawl}>CRAWL</button>
                {arr}

        )
    }
}

modal.js
import React, {Component} from 'react'

export default class Modal extends Component{
    constructor (props) {
        super(props)
        this.state = {
            show: false
        }
    }

    componentWillReceiveProps(nextProps){
        const show_modal = nextProps.show_modal
        this.setState({show: show_modal})
    }

    render () {
       if (this.state.show){
            return

        } else {
            return null
        }
    }
}

Answer: In pageBody.js component,you should bind crawlState() function inside the constructor not inside the render or you can use arrow function like crawlState = () => {}
In search.js component, use this.crawl on onClick function rather than making new const variable.
You should bind crawl function to use this inside the function and you have called this.props crawlState() in the same level without any conditions which means you have called setState() twice at the same time which you shouldn't do, so you should call this.props crawlState(false) inside end after the request completion.
pageBody.js
import React, {Component} from 'react'
import Search from './Search'
import Modal from './modal'

export default class PageBody extends Component{
  constructor (props){
    super(props)
    this.state = {
      is_crawling: false
    }
    this.crawlState = this.crawlState.bind(this)

  }

  crawlState (is_crawling) {
    this.setState({is_crawling: is_crawling})
  }

  render () {
    const show_modal = this.state.is_crawling;

    return (

          <Search crawlState={this.crawlState}/>
          <Modal show_modal={show_modal}/>

    )
  }
}

search.js
import React, {Component} from 'react'
import request from 'superagent'

export default class Search extends Component{
  constructor (props) {
    super(props)
    this.state = {
      keyword: ''
      ,result: []
    }
  }

  // method used to make ajax request
  crawl = () => {
    const keyword = this.state.keyword
    this.props.crawlState(true) // set crawlstate as true to show modal
    request // actual ajax request (superagent)
        .get('/crawl')
        .query({keyword: keyword})
        .end((err, res) => {
          if (err) console.log('superagent failed')
          const r = res.body.result
          this.setState({result: r})
          this.props.crawlState(false) // set crawlstate as false to hide modal
        })
  }

  onChangeHandler (e) {
    this.setState({keyword: e.target.value})
  }

  render () {
    const onChangeHandler = e => this.onChangeHandler(e)
    const keyword = this.state.keyword
    const arr = this.state.result.map((e, idx) => {
      return
{e}

    })

    return (

          <input type="text" onChange={onChangeHandler} value={keyword} />
          <button onClick={this.crawl}>CRAWL</button>
          {arr}

    )
  }
}

Hope this will help you.
Comment: thank you, it worked!

also, just to understand what I did wrong here...
inside the crawl method in search.js...
the crawlState was first set to true and then the ajax call fired, but because it's async crawlState runs immediately after setting it to false again. so to set the crawlState after the ajax ends, I have to put it inside the .end... I hope I got that right
Comment: yeah that's right plus according to react you shouldn't `setState` twice within the same function, you should use it using any sort of conditional statement.


Ler dados com input e escrever as linhas lidas em um arquivo

Question: Eu estou tentando criar um programa que quando eu der uma entrada ele vai criando uma lista dentro de um arquivo, mas quando eu tento fazer isso ele adiciona minhas entradas em uma linha única e não uma embaixo da outra.
Deve haver um comando para isso, como posso fazer para arrumar isso?
arquivo = open('contas', 'w')
def adicionar():
    while True:
        a = input('\nO que quer adicionar?: ')
        arquivo.write(a)
        if a == '':
            break
adicionar()
arquivo.close

Answer: Basta você adicionar a quebra de linha na string, ao passá-la para o método write:
with open('contas', 'w') as arquivo:
    while True:
        a = input('\nO que quer adicionar?: ')
        arquivo.write(a + "\n") # <-- aqui
        if not a:
            break

O "\n" corresponde à quebra de linha. Repare também que usei with, que já fecha o arquivo automaticamente ao final da execução, mesmo que ocorra algum erro.
Também removi a função adicionar, que me parece desnecessária aqui. Da forma que foi feita, ela só pode ser chamada depois que o arquivo estiver aberto, e mesmo assim a variável só poderá se chamar arquivo - enfim, se quer uma função, ou ela deveria receber o arquivo como parâmetro, e deveria verificar se ele está aberto, ou então a função deveria receber o nome do arquivo como parâmetro e fazer tudo dentro dela (abrir, escrever, fechar). Mas para um programa pequeno como esse, que só vai fazer isso, acho um exagero criar esta função.
Repare também no final: if not a verifica se a string é vazia. Esta é uma outra forma de verificar, já que uma string vazia é considerada um valor falso (falsy value) - leia mais sobre isso aqui e aqui.

Outro detalhe é que este código sempre adiciona a quebra de linha no final, para todas as linhas - inclusive para a string vazia. Ou seja, o arquivo terá duas linhas em branco no final (uma relativa à última string não-vazia digitada, e outra relativa à string vazia).
Se quiser evitar isso, basta verificar se a string é vazia antes de escrever:
with open('contas', 'w') as arquivo:
    while True:
        a = input('\nO que quer adicionar?: ')
        if not a: # se a linha for vazia, sai e não escreve ela no arquivo
            break
        arquivo.write(a + "\n")

Agora o arquivo só vai ter uma linha vazia no final, referente à última string não-vazia digitada. Mas se quiser eliminar esta linha também, então o jeito é ir guardando tudo em uma lista e juntar tudo no final:
lista = []
while True:
    a = input('\nO que quer adicionar?: ')
    if not a:  # se a linha for vazia, sai e não adiciona na lista
        break
    lista.append(a)

with open('contas', 'w') as arquivo:
    arquivo.write("\n".join(lista))

Agora eu crio uma lista e vou adicionando apenas as strings não-vazias nela. No final, junto tudo com o método join, usando a quebra de linha como o "juntador" (o que vai ficar entre cada elemento da lista). Assim, a última string não-vazia não terá a quebra de linha adicionada depois dela.

Outra opção é, em vez de arquivo.write, usar a função print, passando o arquivo como parâmetro (já que o print, por default, adiciona a quebra de linha no final):
with open('contas', 'w') as arquivo:
    while True:
        a = input('\nO que quer adicionar?: ')
        print(a, file=arquivo)
        if not a:
            break

Answer: Tente isto:
arquivo = open('contas', 'w')
def adicionar():
    while True:
        print("O que quer adicionar?: ")
        a="\n".join(iter(input,""))
        arquivo.write(a)
        if a == '':
            break
adicionar()
arquivo.close

Recomendo a leitura:

Iteradores em Python
Python String join()(Em inglês)


do not assign default values when creating model from dict in pydantic

Question: I have a pydantic model with optional fields that have default values. I use this model to generate  a JSON schema for another tool, so it can know the default values to apply if it chooses to assign a field.
class MyModel(BaseModel):
    my_field: Optional[str] = None
    my_other_field: Optional[str] = "aaaaaaaaaaab"

my_dict = {"my_field": "value"}
my_model = MyModel(**my_dict)

# prints: {"my_field": "value", "my_other_field": "aaaaaaaaaaab"}
print(my_model)

So in this case, I want my_model to have just my_field assigned, and not my_other_field to not be assigned. my_other_field may or may not be in the dictionary, so if it's not present, I don't want it to be in the resulting model object.
I can not find a way to customize construction of the model from a dict and have it ignore assigning a default.
So essentially, I want the defaults to be present when I call MyModel.schema(), but not when I construct the model from a dict. Is this possible?
Note that my model is hierarchical and has nested models, but isn't shown above.
Comment: I think it's a bad idea? All code that try to use `my_other_field` will have to wary about a possible `AttributeError`.
Comment: What do you mean, you don't want it to be assigned? Then what _should_ the value of that field be? The field has to have **some** value. It can be `None` or some other sentinel value, but it cannot just "not be there". Either you have a field or you don't. There is no such thing as a field without a value.
Comment: Also, you want the schema to show a default value, but that default value to **never be used**. Isn't that super confusing?
Answer: Don't confuse the type of the attribute with the type of the argument that can be passed to initialize it. my_field has type Optional[str] because the default value is None. my_other_field should have type str because the default value is, in fact, another str value.
Optional[foo] is just a synonym for Union[foo, None]. It doesn't mean that you can optionally provide a value to initialize the field; that's indicated by assigning a value to the name.
The possibilities are
class Foo(BaseModel):
    f1: str   # Must provide a string when instantiating Foo
    f2: Optional[str]  # Must provide a string or None when instantiating Foo
    f3: str = "bar"  # Can provide a string, or "bar" will be used
    f4: Optional[str] = "bar"  # Can provide a string or None, or "bar" will be used
    f5: Optional[str] = None  # Can provide a string or none, or None will be used

Comment: Thanks. I understand the typing. I'm trying to figure out if I can serialize to the model object but skip populating the defaults.
Comment: @StealthRabbi You mean **de**serialize to the model. And not populating the default values **that you defined yourself** makes zero sense.


Compile error after upgrade Gradle version to 3.0.0

Question: Here is the error log.

More than one file was found with OS independent path 'android/databinding/DataBindingComponent.java'
Comment: more details and code pls
Comment: @NirajSanghani what code you need to look into?
Comment: kotlin or java?
Comment: it's built with java
Comment: ok check my answer
Comment: what android studio version are u using?
Answer: It seems that your databindings are creating some issues
Use as below if you are using the newer version
implementation 'com.android.databinding:library:1.3.1'
implementation 'com.android.databinding:adapters:1.3.1'

or for older
 compile 'com.android.databinding:library:1.3.1'
    compile 'com.android.databinding:adapters:1.3.1'

Also, make sure you added the new repo in root gradle.build
repositories {
    maven {
        url 'https://maven.google.com'
    }
}

You may also use with newer Gradle wrapper:
repositories {
        maven {
            google()
        }
    }

If you have used data binding in repo, then make sure you have added:
android {
    ....
    dataBinding {
        enabled = true
    }
}

This is the best way to do it.
In your root level gradle.build use below
buildscript {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

and in your gradle-wrapper.properties file change the wrapper version as below
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

Also in your app level build.gradle make sure you are using 26 version as below
android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.xxxx"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Comment: dataBinding {
        enabled = true
    } this line did a magic :)
Comment: I haven't used databinding :(
Comment: in any case make sure u did put in all changes i mentioned if ur using 3.0
Comment: which one is for data binding fix?


What do I need to be able to delete a user's workspace?

Question: I need to delete the workspace of a user that has some files checked out.
My account is a member of Administration Console users, TFS_APPTIER_SERVICE_WPG and the Application Tier's Team Foundation Administrators group.
The Team Foundation Administrators group has all privileges except "Make requests on behalf of others":
Administer Warehouse
Create Team Project Collection
Delete Team Project Collection
Edit Instance-level information

Make requests on behalf of others
Trigger events
Use full Web Access features
View instance-level information

I can access the Team Foundation Server Administration Console, but the File menu only has "Exit".
I understand that I can also do this from the tf utility, but I can't find it or perhaps I don't have this utility installed (Where can I look for it?).
Answer: You need Team Explorer to be installed to get access to the te.exe utility.
Install it on your local computer and not the TFS server. It is a client utility.
Answer: You can do that with the tf.exe from the command line.
The options you need are

tf workspace allows you to see which workspaces exist for a certain
user
tf undo allows you to remove the locks tf delete ca delete
tf delete can delete workspaces

using tf undo can be a lot of work but there are tools like Team Foundation Server Sidekicks that save time.
A good overview can be found at http://fci-h.blogspot.de/2011/01/how-to-force-undo-checkout-tfs.html


Solution of Schrodinger equation for free particle - How to eliminate mass variable

Question: Probably missing something very obvious, sorry if this is a stupid question.
I have to show the function
$\psi\left(x, y\right) =
\frac{1}{\sqrt{2\pi\mathrm{i}t}}
\int_{-\infty}^{\infty}\mathrm{e}^{\mathrm{i}\left(x - y\right)^{\, 2}/4t}\,
\psi_{0}\left(y\right)\,\mathrm{d}y$ is a solution of the Schrodinger equation for a free particle, i.e. is a solution of $i\hbar \frac{\partial \psi(x,t)}{\partial t} = \frac{-\hbar^2}{2m} \frac{\partial^2 \psi(x,t)}{\partial x^2}$.
Working through I get that $i\hbar \frac{\partial \psi(x,t)}{\partial t} = -\hbar \frac{\partial^2 \psi(x,t)}{\partial x^2}$. That is, I can't get a $1/2m$ term no matter what I do, and my lecture notes don't contain any relations of $\hbar$ and $m$ so I'm not sure how to finish the proof.
I read in another question on free particles we can "let $\hbar^2/2m = 1$ without loss of generality but I can't find a source on this claim.
Any help or hints appreciated, thanks.
Comment: PS To write $\hbar$ write \hbar in between $$.
Comment: Thanks, wasn't sure of the notation.
Answer: That function certainly can't solve that equation, since the parameters $\hbar$ and $m$ don't occur in it.
It's quite usual to set various constants or combinations thereof to $1$ in physics to simplify expressions. You can either do this simply by choosing units such that the constant expression takes the value $1$, or you can explicitly rescale time and space. See natural units.
Note that in the present case the choice $\frac{\hbar^2}{2m}=1$ that you mention would be unhelpful, as it would leave a factor of $\hbar$ on the left-hand side – what you need is $\frac\hbar{2m}=1$.
Comment: @D.P Yes, quite reasonable; I think they simply set all (real-valued) constants to $1$ to simplify things. I wouldn't call it an "assumption", more like a choice of units or a simplification. It doesn't change the character of the solutions.
Comment: I thought as much, I forgot to mention that $\psi_0 : \mathbb{R} \to \mathbb{C}$ is a smooth function with compact support, however I don't see how this would change the solution either. Would the assumption $\overline{h}/2m = 1$ be reasonable in your opinion (I'm a mathematician, not a physicist so I'm not used to this kind of work)? If not I can't see how the professor expects us to solve this.
Comment: I see, thanks for the clarification.


Explicit Representations of Meromorphic Functions as Quotients of Entire Functions

Question: Any meromorphic function can be expressed as a quotient of two entire functions. However many times meromorphic functions are not given as a quotient. Is there a general algorithm or method, given a meromorphic function (i.e. you know all the poles and their orders), to express it as a quotient of entire functions?
How does one even do it for the Weierstrass $\mathfrak{p}$ function?
Answer: Use the method given in the proof of the Weierstrass Factorization theorem to construct a function $g$ with zeros at the poles of your function $f$. Then your desired quotient is $\displaystyle \frac{fg}{g}$.
Comment: I guess this is probably the best you're going to get in general. The expression of the entire functions as infinite products doesn't much help with understanding what they should mean though...


Changing Uilabel text style Objective-C

Question: I search on google about how to change style of text in UILabel but I got nothing. My text is long and when I wrote a long text it displays " When will you ... for me? " but I want it displays " When will you go to market ... ".
How can I do? Thank you for your kind.
Answer: you can do this in two ways
option -1
programmatically
Objective-C
label.lineBreakMode = NSLineBreakByTruncatingTail;

Swift
label.lineBreakMode =.byTruncatingTail

other types are
  // NSParagraphStyle
typedef NS_ENUM(NSInteger, NSLineBreakMode) {       /* What to do with long lines */
NSLineBreakByWordWrapping = 0,      /* Wrap at word boundaries, default */
NSLineBreakByCharWrapping,      /* Wrap at character boundaries */
NSLineBreakByClipping,      /* Simply clip */
NSLineBreakByTruncatingHead,    /* Truncate at head of line: "...wxyz" */
NSLineBreakByTruncatingTail,    /* Truncate at tail of line: "abcd..." */
NSLineBreakByTruncatingMiddle   /* Truncate middle of line:  "ab...yz" */
}

option -2
using storyboard attribute inspector
Answer: You should set lineBreakMode property to your label to NSLineBreakByTruncatingTail. It will take care of that.
Comment: Thank you very much. It's work with `setLineBreakMode:NSLineBreakByTruncatingTail ` . ;)
Answer: If your label in storyboard go to the property of label > Line Breaks choose Truncate Tail. If your adding it programmatically then add bellow code
yourLabel.lineBreakMode = NSLineBreakByTruncatingTail;

Changing Uilabel text style Objective-C


What kind of baritone is this voice & is it learned or naturally acquired?

Question: I understand that there are different types of baritones. I am aware of a few such as the Dramatic Baritone, Dramatic Bass Baritone, Lyric Low Baritone, Verdi Baritone.
One of my favourite pop operatic baritones is Carlos Marin, best known for being the baritone of Il Divo. He has this wonderfully rich voice that I can't quite describe, but it sounds very 'full' and 'rich', if that makes sense hopefully.
Here are some of my favourite clips of him.
Tonight @ 1:09 - 1:27
Adagio @ 3:20 - 3:34
Without You @ 2:45 - 3:24
What kind of baritone would he be categorised under? Do all baritones have this 'rich' tone to their voice? Is this something that comes naturally, or is it learned? I myself am a baritone and I can sometimes acquire that same (or similar) style of 'fullness' in the voice, but it does take a fair bit of effort. Is this normal?
Answer: Most vocal coloring is natural. It can be developed but mainly it is what you're born with. That is why you can recognize who is singing, by their voice. As singers age their voice changes, usually getting darker. What you have here is best known as a dramatic baritone.