Skip to content

Instantly share code, notes, and snippets.

View mphuget's full-sized avatar

Marc-Philippe Huget mphuget

View GitHub Profile
import { Injectable } from '@angular/core';
import { Observable, of, throwError } from 'rxjs';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { catchError, tap, map } from 'rxjs/operators';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
@mphuget
mphuget / gist:9cff85bbaf6e0b09ed55e8527f2e2e53
Created March 5, 2020 09:20
pre function for UserSchema
// Hash the password before we even save it to the database
UserSchema.pre('save', function(next) {
let user = this;
if (!user.isModified('local.password'))
return next();
bcrypt.genSalt(10, function(err, salt) {
if (err)
return next(err);
bcrypt.hash(user.local.password, salt, null, function(err, hash) {
if (err)
import { Component, OnInit } from '@angular/core';
import { LoadingController } from '@ionic/angular';
import { RestService } from '../rest.service';
import { ActivatedRoute, ParamMap } from '@angular/router';
@Component({
selector: 'app-view',
templateUrl: './view.page.html',
styleUrls: ['./view.page.scss'],
})
function getAllTodos(req, res) {
const Todo = require('../../todo/models');
Todo.find({}, function(err, todos) {
if (err) throw err;
res.json(todos);
});
// set the dimensions and margins of the graph
var width = 450
height = 450
margin = 40
// The radius of the pieplot is half the width or half the height (smallest one). I subtract a bit of margin.
var radius = Math.min(width, height) / 2 - margin
// append the svg object to the div called 'my_dataviz'
var svg = d3.select("#graph")
import { Component, OnInit } from '@angular/core';
import { LoadingController } from '@ionic/angular';
import { RestService } from '../rest.service';
import { ActivatedRoute, ParamMap } from '@angular/router';
@Component({
selector: 'app-view',
templateUrl: './view.page.html',
styleUrls: ['./view.page.scss'],
})
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-menu-button></ion-menu-button>
</ion-buttons>
<ion-title>
Todos List
</ion-title>
<ion-buttons slot="end">
<ion-button routerLink="/add" routerDirection="forward">
import { Component } from '@angular/core';
import { LoadingController, NavController } from '@ionic/angular';
import { RestService } from '../rest.service';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
import { Injectable } from '@angular/core';
import { Observable, of, throwError } from 'rxjs';
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
import { catchError, tap, map } from 'rxjs/operators';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
<ion-list>
<ion-item-sliding #item>
<ion-item>
Laundry
</ion-item>
<ion-item-options side="start">
<button ion-button color="light">Done</button>
</ion-item-options>
<ion-item-options side="end">
<button ion-button color="light">Edit</button>