Skip to content

Instantly share code, notes, and snippets.

View utsukushiihime's full-sized avatar
🎯
Focusing

Crystal McNeil utsukushiihime

🎯
Focusing
View GitHub Profile
@utsukushiihime
utsukushiihime / gist:0860ae991781c230658b70ad4b904150
Created September 9, 2020 16:59
Expressjs 404 Error Handling
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");
});
<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>
@utsukushiihime
utsukushiihime / enum-access.js
Created September 22, 2020 23:29 — forked from bnoguchi/enum-access.js
How to access enumValues in mongoose from a Model or Document
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);

Big-O Notation Exercises

What is the worst-case time complexity for the following algorithms?

#1

function wordOccurrence(word, phrase){
  let result = 0
  const array  = phrase.split(' ')
@utsukushiihime
utsukushiihime / settings.py
Created October 3, 2020 20:27
Django Project Postgres Database Configuration
# A Django project's configuration lives in settings.py.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'dbname',
}
}
@utsukushiihime
utsukushiihime / 0 AWS Cloud9
Last active December 1, 2020 22:12 — forked from yshmarov/0 AWS Cloud9
Ruby on Rails 6: Learn 25+ gems and build a Startup MVP 2020
# 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
@utsukushiihime
utsukushiihime / postgres-cheatsheet.md
Created November 28, 2020 01:16 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

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)
@utsukushiihime
utsukushiihime / .js
Last active December 12, 2020 06:44
toSnakeCase JavaScript
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"));
@utsukushiihime
utsukushiihime / .js
Created December 12, 2020 06:42
powerOfTwo JavaScript
const powerOfTwo = (num) => {
let pot = Math.pow(2, Math.ceil(Math.log2(num))) - num;
if (pot === 0) {
return "true";
} else {
return "false";
}
};