Angular2 canActivate() calling async function

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

MySQL syntax for Join Update

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

How to check if a String contains only ASCII?

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

Redirect to named url pattern directly from urls.py in django?

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