Skip to content

Instantly share code, notes, and snippets.

@AlekseyA
AlekseyA / Mac SSH Autocomplete
Created August 23, 2023 12:42 — forked from aliang/Mac SSH Autocomplete
Add auto complete to your ssh, put into your .bash_profile
_complete_ssh_hosts ()
{
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
comp_ssh_hosts=`cat ~/.ssh/known_hosts | \
cut -f 1 -d ' ' | \
sed -e s/,.*//g | \
grep -v ^# | \
uniq | \
grep -v "\[" ;
@AlekseyA
AlekseyA / authAPI.js
Created March 4, 2021 13:33
Axios wrapper and API samples
import axios, { setToken } from 'api/axios';
import token from 'utils/token';
const path = '/auth';
const tokenResponseHandler = ({ access, refresh, user }) => {
token.access.set(access);
token.refresh.set(refresh);
setToken(access);
@AlekseyA
AlekseyA / app.js
Created June 3, 2020 13:36
Working with Rchili API
const path = require('path')
const axios = require('axios');
const fs = require('fs'),
// file data from file
FILE_DATA=base64_encode(path.resolve('..', 'CV 6.pdf'));
/**
* HOW TO Make an HTTP Call - POST
*/
// do a POST request
@AlekseyA
AlekseyA / app.js
Created December 27, 2019 10:38
Async backoff
(async () => {
let a = 0;
const func = (...args) => {
a++;
return new Promise((res, rej) => {
setTimeout(() => res('ok'), 1000)
// setTimeout(() => rej('fuck'), 1000)
})
}
@AlekseyA
AlekseyA / logger.js
Created July 3, 2019 09:12
logger what writes to DB and logfile. Also it shows the line where error was executed
const path = require('path');
const Transport = require('winston-transport');
const winston = require('winston');
const moment = require('moment');
const db = require('../models');
const { format } = winston;
const {
combine,
@AlekseyA
AlekseyA / app.js
Created March 20, 2019 08:59
Creating sequelize migrations from existing models
const fs = require('fs');
const db = require('../models');
console.log('Start creating migration files...');
/* eslint-disable guard-for-in,no-restricted-syntax */
for (const model in db) {
const { attributes } = db[model];
for (const column in attributes) {
delete attributes[column].Model;
@AlekseyA
AlekseyA / index.js
Created December 21, 2018 15:59
Firebase function what sends email
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
// // Docs
// // https://firebase.google.com/docs/functions/write-firebase-functions
//
exports.sendSupportEmail = functions.https.onRequest(async (request, response) => {
const transporter = nodemailer.createTransport({
host: 'send.one.com',
@AlekseyA
AlekseyA / views.py
Created August 8, 2018 15:11
Django views
# some imports
@login_required
def provide_addinfo(request):
"""
Allows the user to provide a due date and any additional info for an order.
"""
if request.method == 'POST':
form = OrderForm(data=request.POST, request=request)
if form.is_valid(): # set session vars
@AlekseyA
AlekseyA / user.js
Created August 6, 2018 14:01
User model
/* eslint-disable no-param-reassign */
const { hashPassword } = require('../auth/helpers');
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('user', {
email: {
type: DataTypes.STRING,
validate: {
isEmail: {
msg: 'Email isn\'t correct'
@AlekseyA
AlekseyA / index.js
Created August 6, 2018 13:59
Models entry point
const Sequelize = require('sequelize');
const models = require('require-dir')();
const env = process.env.NODE_ENV || 'development';
const config = require('../../config/database')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {