Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

If you are using ES5 -

**backgroundImage: "url(" + Background + ")"**

If you are using ES6 -
**backgroundImage: `url(${Background})`**
3 years ago
Solution A

If you have a simple asynchronous method that doesn't need to synchronize back to its context, then you can use Task.WaitAndUnwrapException:
***
var task = MyAsyncMethod();
var result = task.WaitAndUnwrapException();
***
You do not want to use Task.Wait or Task.Result because they wrap exceptions in AggregateException.

This solution is only appropriate if MyAsyncMethod does not synchronize back to its context. In other words, every await in MyAsyncMethod should end with ConfigureAwait(false). This means it can't update any UI elements or access the ASP.NET request context.

Solution B

If MyAsyncMethod does need to synchronize back to its context, then you may be able to use AsyncContext.RunTask to provide a nested context:
***
var result = AsyncContext.RunTask(MyAsyncMethod).Result;
***
3 years ago
.NET 4.0 has a built-in library to do this:
***
using System.Web.Script.Serialization;
JavaScriptSerializer jss = new JavaScriptSerializer();
var d = jss.Deserialize(str);
***
This is the simplest way.
3 years ago
Encode:
string encodedStr = Convert.ToBase64String(Encoding.UTF8.GetBytes("inputStr"));

Decode:
string inputStr = Encoding.UTF8.GetString(Convert.FromBase64String(encodedStr));
3 years ago
The best way to do this in pandas is to use drop:

df = df.drop('column_name', 1)
where 1 is the axis number (0 for rows and 1 for columns.)

To delete the column without having to reassign df you can do:

df.drop('column_name', axis=1, inplace=True)
Finally, to drop by column number instead of by column label, try this to delete, e.g. the 1st, 2nd and 4th columns:

df = df.drop(df.columns[[0, 1, 3]], axis=1) # df.columns is zero-based pd.Index
Also working with "text" syntax for the columns:

df.drop(['column_nameA', 'column_nameB'], axis=1, inplace=True)
3 years ago
df1 = df[['a', 'b']]

Alternatively, if it matters to index them numerically and not by their name (say your code should automatically do this without knowing the names of the first two columns) then you can do this instead:

df1 = df.iloc[:, 0:2]

Additionally, you should familiarize yourself with the idea of a view into a Pandas object vs. a copy of that object. The first of the above methods will return a new copy in memory of the desired sub-object (the desired slices).

Sometimes, however, there are indexing conventions in Pandas that don't do this and instead give you a new variable that just refers to the same chunk of memory as the sub-object or slice in the original object. This will happen with the second way of indexing, so you can modify it with the copy() function to get a regular copy. When this happens, changing what you think is the sliced object can sometimes alter the original object. Always good to be on the lookout for this.

df1 = df.iloc[0, 0:2].copy()

To use iloc, you need to know the column positions (or indices). As the column positions may change, instead of hard-coding indices, you can use iloc along with get_loc function of columns method of dataframe object to obtain column indices.

{df.columns.get_loc(c): c for idx, c in enumerate(df.columns)}
Now you can use this dictionary to access columns through names and using iloc.
3 years ago
#The sorted() function takes a key= parameter
newlist = sorted(list_to_be_sorted, key=lambda k: k['name'])

#Alternatively, you can use operator.itemgetter instead of defining the function yourself

from operator import itemgetter
newlist = sorted(list_to_be_sorted, key=itemgetter('name'))
3 years ago
Angular >= 2
You have to use let to declare the value rather than #.



  • {{item}}



Angular = 1


  • {{item}}

3 years ago
import { Component, ElementRef, OnInit } from '@angular/core';

@Component({
selector:'display',
template:`

My name : {{ myName }}


`
})
class DisplayComponent implements OnInit {
constructor(public element: ElementRef) {
this.element.nativeElement // <- your direct element reference
}
ngOnInit() {
var el = this.element.nativeElement;
console.log(el);
}
updateName(value) {
// ...
}
}
3 years ago