Skip to content

Instantly share code, notes, and snippets.

Marc-Philippe Huget mphuget

View GitHub Profile
View gist:d76fc980103d11f724e1391e3abf2c9f
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'})
};
View gist:9cff85bbaf6e0b09ed55e8527f2e2e53
// 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)
View view.page.ts
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'],
})
View Code CRUD MongoDB
function getAllTodos(req, res) {
const Todo = require('../../todo/models');
Todo.find({}, function(err, todos) {
if (err) throw err;
res.json(todos);
});
View gist:f0eba5765a1b8516dbceb1ae61a1c79b
// 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")
View gist:e6ae7ee7770727245bc36d07d03eb6bf
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'],
})
View gist:81d18210dfcdfa4136175e30ab900484
<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">
View gist:d51a98bfc3c1641ab301fa3c73c670b9
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'],
})
View gist:61c371d7d7a0dd5a00fa90434a8d370a
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'})
};
View gist:04ef58ddeb9da517c8ae3f9f531e088e
<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>
You can’t perform that action at this time.