Skip to content

Instantly share code, notes, and snippets.

View bookercodes's full-sized avatar

Alex Booker bookercodes

View GitHub Profile
var crypto = require("crypto");
module.exports = (function(){
var DELIMITER = ":";
function signToken(token) {
return crypto
.createHmac("sha1", "ZvACQyRwbh5zXTD8ta0W")
.update(token)
.digest("hex");
}
var mongoose = require("mongoose");
var passport = require("passport-local-mongoose");
var user = new mongoose.Schema({
username: { type: String, required: true, unique: true },
email: { type: String, required: true, unique: true },
bio: { type: String, default: "This user has no bio." },
password_reset_code: String,
password_reset_time: Number,
activation_code : String,

Expression-bodied Members

Expression-bodied members are members whose bodies are an expression rather than a statement block. In many common situations, they make code more readable and compact.

The following listing shows a traditional method declaration:

public override string ToString()
{
 return "A textual representation of the object..";
public class Circle
{
public int Radius { get; private set; }
public Point Point { get; private set; }
public double Area => Math.Pow(Radius, 2) * Math.PI;
public double Perimiter => 2 * Math.PI * Radius;
public Circle(Point point, int radius)
1. **Introduction (_You are here._)**
- [Expression-bodied Members]()
- <span title="Coming soon..." style="cursor:not-allowed;">Getter-only Automatic Properties</span>
- <span title="Coming soon..." style="cursor:not-allowed;">Null-conditional Operator</span>
- <span title="Coming soon..." style="cursor:not-allowed;">nameof Operator</span>
- <span title="Coming soon..." style="cursor:not-allowed;">String Interpolation</span>
- <span title="Coming soon..." style="cursor:not-allowed;">Await in Catch and Finally Blocks</span>
- <span title="Coming soon..." style="cursor:not-allowed;">Exception Filters</span>
- <span title="Coming soon..." style="cursor:not-allowed;">Index Initializers</span>
- <span title="Coming soon..." style="cursor:not-allowed;">Extension Add in Collection Initializers</span>
  1. Consistent computer science naming. Map instead of Select. Reduce instead of Aggregate etc.
  2. Does not throw exceptions unless something exceptional happens. Find (which is equivalent to Single) does not throw if no match is found.
  3. People are more likely to search for "unique" than "distinct" etc.
  4. Improves some methods like Range to take a step argument.
public override string ToString()
{
return "I am a member whose body is a statement block";
}
// versus
public override string ToString() => "I am an expression-bodied member.";
public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName => FirstName + " " + LastName;
public static Person operator +(Person person1, Person person2) => person1;
public string this[int i] => "Hi";
{
"dependencies": {
"bluebird": "^2.9.34",
"body-parser": "^1.13.2",
"config": "^1.14.0",
"cors": "^2.7.1",
"express": "^4.13.1",
"moment": "^2.10.6",
"moment-duration-format": "^1.3.0",
"mysql": "^2.7.0",