Skip to content

Instantly share code, notes, and snippets.

View vbguard's full-sized avatar
:octocat:
I'm coding

Viktor Bulvarenko vbguard

:octocat:
I'm coding
View GitHub Profile
defined_indexes = Model.index_specifications.map { |s| s.fields.map(&:to_s) };
existing_indexes = Model.collection.indexes.map { |i| i['key'].keys };
missing_indexes = defined_indexes - existing_indexes
# => []
extra_indexes = existing_indexes - defined_indexes - [['_id']]
# => []
#################################################################################
@vbguard
vbguard / macos+ntfs
Created October 4, 2019 21:47 — forked from exAspArk/macos+ntfs.sh
Mount writable NTFS disk with osxfuse + ntfs-3g
sudo mkdir /Volumes/NTFS
diskutil list
sudo /usr/local/bin/ntfs-3g /dev/disk2s1 /Volumes/NTFS -olocal -oallow_other
rsync -v --progress ~/Downloads/something /Volumes/NTFS/
sudo umount /Volumes/NTFS
@vbguard
vbguard / self-signed-ssl-mongo.sh
Created October 4, 2019 21:45 — forked from exAspArk/self-signed-ssl-mongo.sh
Self-signed SSL Certificate with OpenSSL on MacOS | MongoDB
openssl genrsa -out CAroot.key 2048
openssl req -new -key CAroot.key -out CAroot.csr # CN should be different from the certificates below
openssl req -x509 -days 1825 -key CAroot.key -in CAroot.csr -out CAroot.crt
cat CAroot.crt CAroot.key > CAroot.pem
openssl genrsa -out mongod.key 2048
openssl req -new -key mongod.key -out mongod.csr
openssl x509 -req -days 1825 -in mongod.csr -CA CAroot.pem -CAkey CAroot.key -CAcreateserial -out mongod.crt
cat mongod.crt mongod.key > mongod.pem
sequelize
// .sync({ force: true })
.sync()
.then(result => {
console.log(result);
app.listen(3000);
})
.catch(err => {
console.log(err);
});
Product.belongsTo(User, { constraints: true, onDelete: 'CASCADE' });
User.hasMany(Product);
const Sequelize = require('sequelize');
const sequelize = require('../util/database');
const User = sequelize.define('user', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
allowNull: false,
primaryKey: true
const Sequelize = require('sequelize');
const sequelize = new Sequelize('node-complete', 'root', 'nodecomplete', {
dialect: 'mysql',
host: 'localhost'
});
module.exports = sequelize;
<% if (prods.length > 0) { %>
<div class="grid">
<% for (let product of prods) { %>
<article class="card product-item">
<header class="card__header">
<h1 class="product__title">
<%= product.title %>
</h1>
</header>
<div class="card__image">
app.use(errorController.get404);
app.use((error, req, res, next) => {
// res.status(error.httpStatusCode).render(...);
res.redirect('/500');
});
mongoose
.connect(MONGODB_URI)
@vbguard
vbguard / normalizeRequest.js
Created August 25, 2019 09:32
normalize request url get last pathname idx, qs, command
const url = require('url');
const path = require('path');
module.exports = function normalizeRequest(url) {
let idx;
const parsed = url.parse(uri, true);
const pathname = path.join(parsed.pathname, '/');
pathname = pathname.slice(1, pathname.length - 1);
idx = pathname.lastIndexOf('/');