Skip to content

Instantly share code, notes, and snippets.

View i386net's full-sized avatar
🏠
💻👻

i386net

🏠
💻👻
View GitHub Profile
@i386net
i386net / cards.js
Created July 8, 2020 08:23
delete user card with verification by id
const deleteCard = (req, res) => {
if (mongoose.Types.ObjectId.isValid(req.params.cardId)) {
return Card.findById(req.params.cardId)
.orFail(() => new Error(`Карточка с _id ${req.params.cardId} не найдена`))
.then((card) => {
if (card.owner.toString() === req.user._id) {
return Card.findByIdAndDelete(card._id)
.orFail(() => new Error('С удалением что-то пошло не так'))
.then((deletedCard) => res.send({ data: deletedCard, message: 'Карточка успешно удалена' }))
.catch((err) => res.status(404).send({ error: err.message }));
@i386net
i386net / app.js
Created July 6, 2020 12:23 — forked from stongo/app.js
Joi validation in a Mongoose model
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
db.on('error', function() {
return console.error.bind(console, 'connection error: ');
});
@i386net
i386net / gist:b40bb4df842e4c593540b1bbe44d81f0
Created July 3, 2020 14:16 — forked from rmondello/gist:b933231b1fcc83a7db0b
Exporting (iCloud) Keychain and Safari credentials to a CSV file

Exporting (iCloud) Keychain and Safari credentials to a CSV file

After my dad died, I wanted to be able to have access any of his online accounts going forward. My dad was a Safari user and used iCloud Keychain to sync his credentials across his devices. I don’t want to have to keep an OS X user account around just to access his accounts, so I wanted to export his credentials to a portable file.

This is the process I used to create a CSV file of his credentials in the format “example.com,user,pass”. This portable format would be pretty easy to import into 1Password or Safari in the future.

The way I went about this isn’t great; it opens up more opportunities for apps to control one’s Mac through Accessibility APIs, it writes plaintext passwords to disk, and it could use some cleaning up. A better approach might leverage the security command line tool that ships with OS X. That said, I found this method to be a fun illustration of what’s possible us

@i386net
i386net / scrapbox-new-card.js
Last active July 27, 2021 09:40
for Scrapbox.io | UA localization
const diffDate = (date, diff) => {
// date: '1993-09-11'
// diff: +1, -1
console.log('input', date);
console.log('diff', diff);
date.setDate(date.getDate() + diff);
console.log('output', date);
const a = [
date.getFullYear(),
('00' + (1 + date.getMonth())).slice(-2),
const dateHandling = () => {
const askDate = prompt('Enter date: ', 'YYYYMMDD or YYYY MM DD');
if (askDate === null) return new Date();
const dates = (str) => {
const year = str.slice(0, 4);
const month = str.slice(4, 6) - 1;
const day = str.slice(6, 8);
return [year, month, day];
};
if (askDate.match(/\d{8}/)) {
@i386net
i386net / eratosfen.js
Last active March 21, 2020 09:40
решето Эратосфена
// let ticks = null;
function primes(n) {
const a = new Array(n);
const ret = [];
a.fill(true);
// ticks = 0;
for (let i = 2; i <= n; i++) {
// ticks++;
if (a[i]) {
@i386net
i386net / Node_Types.md
Last active March 14, 2020 04:52
типы узлов JS

Типы узлов (NODE) документа

Код типа (nodeType) Тип узла Описание
1 ELEMENT_NODE Узел элемента
3 TEXT_NODE Текстовый узел (#text)
7 PROCESSING_INSTRUCTION_NODE Узел инструкции обработки
8 COMMENT_NODE Узел комментария (#comment)
9 DOCUMENT_NODE Узел документа (#document)
10 DOCUMENT_TYPE_NODE Узел типа документа