This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.use(function (req, res) { | |
// any get will send 404 | |
if (req.method === "GET") return res.status(404).send("404 Page Not Found"); | |
// any other method will say not allowed | |
return res.status(405).send("Method not allowed"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<body> | |
<h1>Here are all the fruits!</h1> | |
<a href="/fruits/new">add fruit (+)</a> | |
<% fruits.forEach((fruit, index) => { %> | |
<li> | |
<a href="/fruits/<%= index %>"> <%= fruit.name %> </a> | |
</li> | |
<% }); %> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('./index') | |
, TempSchema = new mongoose.Schema({ | |
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']} | |
}); | |
var Temp = mongoose.model('Temp', TempSchema); | |
console.log(Temp.schema.path('salutation').enumValues); | |
var temp = new Temp(); | |
console.log(temp.schema.path('salutation').enumValues); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Django project's configuration lives in settings.py. | |
DATABASES = { | |
'default': { | |
'ENGINE': 'django.db.backends.postgresql', | |
'NAME': 'dbname', | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# All AWS C9 envments | |
https://eu-central-1.console.aws.amazon.com/cloud9/home?region=us-east-1 | |
# Instance management | |
https://console.aws.amazon.com/ec2/home?region=eu-central-1#Instances:sort=instanceId | |
# Create AWS C9 environment | |
https://eu-central-1.console.aws.amazon.com/cloud9/home/create | |
Setting - set tabs to 2 |
Magic words:
psql -U postgres
Some interesting flags (to see all, use -h
or --help
depending on your psql version):
-E
: will describe the underlaying queries of the\
commands (cool for learning!)-l
: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SnakeCase(str) { | |
const regex = /\W+/g; | |
for (char in str) { | |
let newStr = str.toLowerCase().replace(regex, "_"); | |
return newStr; | |
} | |
} | |
console.log(SnakeCase("This*is a Great-Night")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const powerOfTwo = (num) => { | |
let pot = Math.pow(2, Math.ceil(Math.log2(num))) - num; | |
if (pot === 0) { | |
return "true"; | |
} else { | |
return "false"; | |
} | |
}; |
OlderNewer