Accessing a value in a tuple that is in a list
With a list comprehension. [x[1] for x in L]
With a list comprehension. [x[1] for x in L]
canActivate needs to return an Observable that completes: @Injectable() export class AuthGuard implements CanActivate { constructor(private auth: AngularFireAuth, private router: Router) {} canActivate(route:ActivatedRouteSnapshot, state:RouterStateSnapshot):Observable<boolean>|boolean { return this.auth.map((auth) => { if (auth) { console.log(‘authenticated’); return true; } console.log(‘not authenticated’); this.router.navigateByUrl(‘/login’); return false; }).first(); // this might not be necessary – ensure `first` is imported if you … Read more
No difference. int? is just shorthand for Nullable<int>, which itself is shorthand for Nullable<Int32>. Compiled code will be exactly the same whichever one you choose to use.
MySQL supports a multi-table UPDATE syntax, which would look approximately like this: UPDATE Reservations r JOIN Train t ON (r.Train = t.TrainID) SET t.Capacity = t.Capacity + r.NoSeats WHERE r.ReservationID = ?; You can update the Train table and delete from the Reservations table in the same transaction. As long as you do the update … Read more
The final keyword does not appear in the class file for local variables and parameters, thus it cannot impact the runtime performance. It’s only use is to clarify the coders intent that the variable not be changed (which many consider dubious reason for its usage), and dealing with anonymous inner classes. There is a lot … Read more
DateTime.TryParse This I believe is faster and it means you dont have to use ugly try/catches 🙂 e.g DateTime temp; if(DateTime.TryParse(startDateTextBox.Text, out temp)) { // Yay 🙂 } else { // Aww.. 🙁 }
From Guava 19.0 onward, you may use: boolean isAscii = CharMatcher.ascii().matchesAllOf(someString); This uses the matchesAllOf(someString) method which relies on the factory method ascii() rather than the now deprecated ASCII singleton. Here ASCII includes all ASCII characters including the non-printable characters lower than 0x20 (space) such as tabs, line-feed / return but also BEL with code … Read more
If you are on Django 1.4 or 1.5, you can do this: from django.core.urlresolvers import reverse_lazy from django.views.generic import RedirectView urlpatterns = patterns(”, url(r’^some-page/$’, RedirectView.as_view(url=reverse_lazy(‘my_named_pattern’), permanent=False)), … If you are on Django 1.6 or above, you can do this: from django.views.generic import RedirectView urlpatterns = patterns(”, url(r’^some-page/$’, RedirectView.as_view(pattern_name=”my_named_pattern”, permanent=False)), … In Django 1.9, the default … Read more
That library seems to allow validation for single elements. Just associate a click event to your button and try the following: $(“#myform”).validate().element(“#i1”); Examples here: https://jqueryvalidation.org/Validator.element
Following [] is supported in PHP >= 5.4: [‘name’ => ‘test’, ‘id’ => ‘theID’] This is a short syntax only and in PHP < 5.4 it won’t work.