Skip to content

Instantly share code, notes, and snippets.

View crguezl's full-sized avatar
🌋

Casiano Rodriguez-Leon crguezl

🌋
View GitHub Profile

Mongoose Built-in validation

One of the core concepts of Mongoose is that it enforces a schema on top of a schema-less design such as MongoDB. In doing so, we gain a number of new features, including built-in validation. By default, every schema type has a built-in required validator available. Furthermore, numbers have both min and max validators and strings have enumeration and matching validators.

@crguezl
crguezl / mongooosefindquery.js
Created April 14, 2016 22:13
mongoose query without immediate callback
(function() {
"use strict";
const util = require('util');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/chuchu');
const CardSchema = mongoose.Schema({
"rank" : String,
"suit" : String,
});
@crguezl
crguezl / mongooosefind.js
Created April 14, 2016 20:07
Ejemplo de uso de find y promesas en mongoose
(function() {
"use strict";
const util = require('util');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/chuchu');
const CardSchema = mongoose.Schema({
"rank" : String,
"suit" : String,
});
@crguezl
crguezl / mongoosepromisesexample.js
Created April 14, 2016 18:50
Ejemplo del uso de Promesas en Mongoose
(function() {
"use strict";
const util = require('util');
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/chuchu');
const CardSchema = mongoose.Schema({
"rank" : String,
"suit" : String,
"chuchu": [ {a: String, b: String}]
@crguezl
crguezl / README.md
Created February 11, 2016 14:10
Example of gitbook using gitbook-plugin-quiz

Introduction

Inline math: $$\int_{-\infty}^\infty g(x) dx$$

$$a \times x^2 + b \times x + c = 0$$

Quiz

@crguezl
crguezl / README.md
Created February 11, 2016 14:08
Example of gitbook using gitbook-plugin-quiz

Summary

@crguezl
crguezl / index.html
Last active October 14, 2019 12:55
<!DOCTYPE html>
<html>
<head>
<script src="script.js"></script>
</head>
<body>
<h1> <div id="joke"></div> </h1>
<br/>
@crguezl
crguezl / constructor.js
Last active November 16, 2015 17:15
Constructor de la clase Respuesta para la práctica de SYTW en la que se pide ampliar el Modelo. Ejemplos
function Respuesta(c) {
var f;
if ((typeof c === 'string') || (typeof c === 'number')) {
f = function(respuesta) { return respuesta === c; }
}
else if (c.constructor.name === 'RegExp') {
f = function(respuesta) { return c.exec(respuesta); }
}
else if (c.constructor.name === 'Function') { f = c; }
// else ...
var express = require('express');
var app = express();
app.get('/user/:id', function(req, res, next){
if (req.params.id.match(/^(eva|ana)$/i)) {
res.send('usuario del sistema');
}
else {
next(new Error('usuario desconocido'));
}
@crguezl
crguezl / index.html
Created October 15, 2015 08:08
Example of race condition taken from Concurrency and Parallel Computing in JavaScript by Stephan Herhut on Mar 05, 2014
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Asynchronous Image Loading</title>
</head>
<body>
<div id="holder-div"></div>
<script type="text/javascript">
var image = new Image(100),